From 5f47a603382144ae356f79469aecb5839c2132b2 Mon Sep 17 00:00:00 2001 From: Joaquin Date: Wed, 7 Oct 2020 23:03:08 -0500 Subject: [PATCH] Add tests. --- features/data/configs/format_md.yaml | 19 +++++++++++++++++++ features/data/configs/format_text.yaml | 19 +++++++++++++++++++ features/format.feature | 20 ++++++++++++++++++++ jrnl/Journal.py | 1 - jrnl/install.py | 1 - jrnl/jrnl.py | 9 ++++++--- 6 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 features/data/configs/format_md.yaml create mode 100644 features/data/configs/format_text.yaml diff --git a/features/data/configs/format_md.yaml b/features/data/configs/format_md.yaml new file mode 100644 index 00000000..0b9f1c3b --- /dev/null +++ b/features/data/configs/format_md.yaml @@ -0,0 +1,19 @@ +colors: + body: none + date: none + tags: none + title: none +default_hour: 9 +default_minute: 0 +display_format: markdown +editor: '' +encrypt: false +highlight: true +indent_character: '|' +journals: + default: features/journals/simple.journal +linewrap: 80 +tagsymbols: '@' +template: false +timeformat: '%Y-%m-%d %H:%M' +version: v2.4.5 diff --git a/features/data/configs/format_text.yaml b/features/data/configs/format_text.yaml new file mode 100644 index 00000000..c82ff7a7 --- /dev/null +++ b/features/data/configs/format_text.yaml @@ -0,0 +1,19 @@ +colors: + body: none + date: none + tags: none + title: none +default_hour: 9 +default_minute: 0 +display_format: text +editor: '' +encrypt: false +highlight: true +indent_character: '|' +journals: + default: features/journals/simple.journal +linewrap: 80 +tagsymbols: '@' +template: false +timeformat: '%Y-%m-%d %H:%M' +version: v2.4.5 diff --git a/features/format.feature b/features/format.feature index e689a9f3..4bddd079 100644 --- a/features/format.feature +++ b/features/format.feature @@ -512,3 +512,23 @@ Feature: Custom formats | basic_encrypted | | basic_folder | | basic_dayone | + + Scenario: Markdown Support from config file + Given we use the config "format_md.yaml" + When we run "jrnl -n 1" + Then the output should be + """ + # 2013 + ## June + ### 2013-06-10 15:40 Life is good. + But I'm better. + """ + + Scenario: Text Formatter from config file + Given we use the config "format_text.yaml" + When we run "jrnl -n 1" + Then the output should be + """ + [2013-06-10 15:40] Life is good. + But I'm better. + """ diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 2028666b..a6bf35d0 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -35,7 +35,6 @@ class Journal: "highlight": True, "linewrap": 80, "indent_character": "|", - "display_format": "text", } self.config.update(kwargs) # Set up date parser diff --git a/jrnl/install.py b/jrnl/install.py index 8347d27c..5f5f0032 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -49,7 +49,6 @@ default_config = { "linewrap": 79, "indent_character": "|", "colors": {"date": "none", "title": "none", "body": "none", "tags": "none",}, - "display_format": "text", } diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 97886928..c351fe74 100644 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -290,7 +290,7 @@ def _delete_search_results(journal, old_entries, **kwargs): journal.write() -def _display_search_results(args, journal, config, **kwargs): +def _display_search_results(args, journal, **kwargs): if args.short: print(journal.pprint(short=True)) @@ -302,6 +302,9 @@ def _display_search_results(args, journal, config, **kwargs): print(exporter.export(journal, args.filename)) else: # Display according display_format config option - config_selected = config.get("display_format", journal.config["display_format"]) + config_selected = kwargs['config'].get("display_format") exporter = plugins.get_exporter(config_selected) - print(exporter.export(journal, args.filename)) + if config_selected: + print(exporter.export(journal, args.filename)) + else: + print(journal.pprint())