mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
Fix bug that prevented --format pretty and --format short from working (#1177)
This commit is contained in:
parent
b9a6d029e2
commit
a3f4f6b944
7 changed files with 79 additions and 2 deletions
|
@ -1,5 +1,31 @@
|
||||||
Feature: Custom formats
|
Feature: Custom formats
|
||||||
|
|
||||||
|
Scenario Outline: Short printing via --format flag
|
||||||
|
Given We use the config "<config>.yaml"
|
||||||
|
And we use the password "test" if prompted
|
||||||
|
When we run "jrnl --format short -3"
|
||||||
|
Then we should get no error
|
||||||
|
|
||||||
|
Examples: configs
|
||||||
|
| config |
|
||||||
|
| basic_onefile |
|
||||||
|
| basic_encrypted |
|
||||||
|
| basic_folder |
|
||||||
|
| basic_dayone |
|
||||||
|
|
||||||
|
Scenario Outline: Pretty Printing aka the Default
|
||||||
|
Given We use the config "<config>.yaml"
|
||||||
|
And we use the password "test" if prompted
|
||||||
|
When we run "jrnl --format pretty -3"
|
||||||
|
Then we should get no error
|
||||||
|
|
||||||
|
Examples: configs
|
||||||
|
| config |
|
||||||
|
| basic_onefile |
|
||||||
|
| basic_encrypted |
|
||||||
|
| basic_folder |
|
||||||
|
| basic_dayone |
|
||||||
|
|
||||||
Scenario Outline: JSON format
|
Scenario Outline: JSON format
|
||||||
Given we use the config "<config>.yaml"
|
Given we use the config "<config>.yaml"
|
||||||
And we use the password "test" if prompted
|
And we use the password "test" if prompted
|
||||||
|
|
|
@ -407,6 +407,12 @@ def all_input_was_used(context):
|
||||||
def run(context, command, text=""):
|
def run(context, command, text=""):
|
||||||
text = text or context.text or ""
|
text = text or context.text or ""
|
||||||
|
|
||||||
|
if "config_path" in context and context.config_path is not None:
|
||||||
|
with open(context.config_path) as f:
|
||||||
|
context.jrnl_config = yaml.load(f, Loader=yaml.FullLoader)
|
||||||
|
else:
|
||||||
|
context.jrnl_config = None
|
||||||
|
|
||||||
if "cache_dir" in context and context.cache_dir is not None:
|
if "cache_dir" in context and context.cache_dir is not None:
|
||||||
cache_dir = os.path.join("features", "cache", context.cache_dir)
|
cache_dir = os.path.join("features", "cache", context.cache_dir)
|
||||||
command = command.format(cache_dir=cache_dir)
|
command = command.format(cache_dir=cache_dir)
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
# Copyright (C) 2012-2021 jrnl contributors
|
# Copyright (C) 2012-2021 jrnl contributors
|
||||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
from behave import given
|
from behave import given
|
||||||
from behave import then
|
from behave import then
|
||||||
|
|
||||||
|
|
|
@ -323,9 +323,12 @@ def _delete_search_results(journal, old_entries, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
def _display_search_results(args, journal, **kwargs):
|
def _display_search_results(args, journal, **kwargs):
|
||||||
if args.short:
|
if args.short or args.export == "short":
|
||||||
print(journal.pprint(short=True))
|
print(journal.pprint(short=True))
|
||||||
|
|
||||||
|
elif args.export == "pretty":
|
||||||
|
print(journal.pprint())
|
||||||
|
|
||||||
elif args.tags:
|
elif args.tags:
|
||||||
print(plugins.get_exporter("tags").export(journal))
|
print(plugins.get_exporter("tags").export(journal))
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ __exporters = [
|
||||||
__importers = [JRNLImporter]
|
__importers = [JRNLImporter]
|
||||||
|
|
||||||
__exporter_types = {name: plugin for plugin in __exporters for name in plugin.names}
|
__exporter_types = {name: plugin for plugin in __exporters for name in plugin.names}
|
||||||
|
__exporter_types["pretty"] = None
|
||||||
|
__exporter_types["short"] = None
|
||||||
__importer_types = {name: plugin for plugin in __importers for name in plugin.names}
|
__importer_types = {name: plugin for plugin in __importers for name in plugin.names}
|
||||||
|
|
||||||
EXPORT_FORMATS = sorted(__exporter_types.keys())
|
EXPORT_FORMATS = sorted(__exporter_types.keys())
|
||||||
|
|
17
tests/test_color.py
Normal file
17
tests/test_color.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from jrnl.color import colorize
|
||||||
|
from colorama import Fore, Style
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def data_fixture():
|
||||||
|
string = "Zwei peanuts walked into a bar"
|
||||||
|
yield string
|
||||||
|
|
||||||
|
|
||||||
|
def test_colorize(data_fixture):
|
||||||
|
string = data_fixture
|
||||||
|
colorized_string = colorize(string, "BLUE", True)
|
||||||
|
|
||||||
|
assert colorized_string == Style.BRIGHT + Fore.BLUE + string + Style.RESET_ALL
|
23
tests/test_display.py
Normal file
23
tests/test_display.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import argparse
|
||||||
|
import jrnl
|
||||||
|
import pytest
|
||||||
|
from unittest import mock
|
||||||
|
from jrnl.jrnl import _display_search_results
|
||||||
|
|
||||||
|
|
||||||
|
# fmt: off
|
||||||
|
# see: https://github.com/psf/black/issues/664
|
||||||
|
@pytest.mark.parametrize("export_format", [ "pretty", "short","markdown"])
|
||||||
|
#fmt: on
|
||||||
|
@mock.patch.object(argparse, "Namespace", return_value={"export": "markdown", "filename": "irrele.vant"})
|
||||||
|
def test_export_format(mock_args, export_format):
|
||||||
|
|
||||||
|
test_journal = jrnl.Journal.Journal
|
||||||
|
mock_args.export = export_format
|
||||||
|
#fmt: off
|
||||||
|
# see: https://github.com/psf/black/issues/664
|
||||||
|
with mock.patch("builtins.print") as mock_spy_print, \
|
||||||
|
mock.patch('jrnl.Journal.Journal.pprint') as mock_pprint:
|
||||||
|
_display_search_results(mock_args, test_journal)
|
||||||
|
mock_spy_print.assert_called_once_with(mock_pprint())
|
||||||
|
#fmt: on
|
Loading…
Add table
Reference in a new issue