Add tests.

This commit is contained in:
Joaquin 2020-10-07 23:03:08 -05:00 committed by Jonathan Wren
parent 7d0b4b6b19
commit 5f47a60338
No known key found for this signature in database
GPG key ID: 43D5FF8722E7F68A
6 changed files with 64 additions and 5 deletions

View file

@ -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

View file

@ -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

View file

@ -512,3 +512,23 @@ Feature: Custom formats
| basic_encrypted | | basic_encrypted |
| basic_folder | | basic_folder |
| basic_dayone | | 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.
"""

View file

@ -35,7 +35,6 @@ class Journal:
"highlight": True, "highlight": True,
"linewrap": 80, "linewrap": 80,
"indent_character": "|", "indent_character": "|",
"display_format": "text",
} }
self.config.update(kwargs) self.config.update(kwargs)
# Set up date parser # Set up date parser

View file

@ -49,7 +49,6 @@ default_config = {
"linewrap": 79, "linewrap": 79,
"indent_character": "|", "indent_character": "|",
"colors": {"date": "none", "title": "none", "body": "none", "tags": "none",}, "colors": {"date": "none", "title": "none", "body": "none", "tags": "none",},
"display_format": "text",
} }

View file

@ -290,7 +290,7 @@ def _delete_search_results(journal, old_entries, **kwargs):
journal.write() journal.write()
def _display_search_results(args, journal, config, **kwargs): def _display_search_results(args, journal, **kwargs):
if args.short: if args.short:
print(journal.pprint(short=True)) print(journal.pprint(short=True))
@ -302,6 +302,9 @@ def _display_search_results(args, journal, config, **kwargs):
print(exporter.export(journal, args.filename)) print(exporter.export(journal, args.filename))
else: else:
# Display according display_format config option # 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) 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())