mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-11 17:46:12 +02:00
Address code review
make the test perform actual qualification
make format
update other test as well
remove unnecessary mock
reset .gitignore to e6c0a16342
delete pretty.yaml
remove launch.json
reorder mocks
convert scenario to scenario outline for behavioral coverage
fix scenario syntax
comment out problematic step; add password handling
reorder import
meld conditional code
rework melded export logic
update code to be exercised in test
This commit is contained in:
parent
edc8cd93e3
commit
0a6e5f94c0
8 changed files with 44 additions and 127 deletions
|
@ -2,41 +2,41 @@ import argparse
|
|||
import jrnl
|
||||
import pytest
|
||||
from unittest import mock
|
||||
from jrnl.jrnl import _export_journal
|
||||
from jrnl.jrnl import _display_search_results, _export_journal
|
||||
|
||||
|
||||
# fmt: off
|
||||
# see: https://github.com/psf/black/issues/664
|
||||
@pytest.mark.parametrize("export_format", [ "pretty", "short",])
|
||||
#fmt: on
|
||||
@mock.patch.object(argparse, "Namespace", return_value={"export": None, "filename": None})
|
||||
@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
|
||||
#fmt: off
|
||||
# see: https://github.com/psf/black/issues/664
|
||||
with mock.patch("builtins.print") as print_spy, mock.patch("jrnl.Journal.Journal.pprint") as mock_pprint:
|
||||
_export_journal(mock_args, test_journal)
|
||||
print_spy.call_args_list = mock_pprint
|
||||
# fmt: on
|
||||
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
|
||||
|
||||
|
||||
@mock.patch.object(argparse, "Namespace", return_value={"export": None, "filename": None})
|
||||
@mock.patch.object(argparse, "Namespace", return_value={"export": "markdown", "filename": "foo.jrnl"})
|
||||
def test_export_plugin(mock_args):
|
||||
export_format = "markdown"
|
||||
export_format = mock_args.return_value["export"]
|
||||
|
||||
test_journal = jrnl.Journal.Journal
|
||||
mock_args.export = export_format
|
||||
mock_args.filename = "foo.jrnl"
|
||||
mock_args.filename = mock_args.return_value['filename']
|
||||
|
||||
# fmt: off
|
||||
# see: https://github.com/psf/black/issues/664
|
||||
with mock.patch("builtins.print") as print_spy, \
|
||||
mock.patch("jrnl.plugins.get_exporter") as mock_get_exporter, \
|
||||
mock.patch("jrnl.Journal.Journal.pprint") as mock_pprint:
|
||||
mock.patch("jrnl.Journal.Journal.pprint") :
|
||||
_export_journal(mock_args, test_journal)
|
||||
# fmt: on
|
||||
|
||||
print_spy.call_args_list = mock_pprint
|
||||
mock_get_exporter.assert_called_once_with(export_format)
|
||||
print_spy.assert_called_once_with(mock_get_exporter().export(test_journal,mock_args.filename))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue