From c8e09b023fd86483ca7f458393e60873dc06fdcc Mon Sep 17 00:00:00 2001 From: sriniv27 Date: Mon, 8 Feb 2021 20:14:48 -0500 Subject: [PATCH] reuse existing mock; delete unneeded code --- features/steps/override.py | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) diff --git a/features/steps/override.py b/features/steps/override.py index d1857b0b..766bea77 100644 --- a/features/steps/override.py +++ b/features/steps/override.py @@ -11,17 +11,7 @@ from yaml.loader import FullLoader import jrnl - -def _mock_time_parse(context): - original_parse = jrnl.time.parse - if "now" not in context: - return original_parse - - def wrapper(input, *args, **kwargs): - input = context.now if input == "now" else input - return original_parse(input, *args, **kwargs) - - return wrapper +from features.steps.core import _mock_time_parse @given("we use the config {config_file}") @@ -30,33 +20,22 @@ def load_config(context, config_file): context.config_path = os.path.abspath(filepath) -@when("we run jrnl with {args}") -def run_command(context, args): - context.args = split_args("%s" % args) - context.parser = parse_args(context.args) - with open(context.config_path, "r") as f: - cfg = yaml.load(f, Loader=FullLoader) - context.cfg = cfg - - @then("the runtime config should have {key_as_dots} set to {override_value}") def config_override(context, key_as_dots: str, override_value: str): key_as_vec = key_as_dots.split(".") - def _mock_callback(**args): - print("callback executed") - # fmt: off try: with \ mock.patch("jrnl.jrnl.search_mode"), \ mock.patch.object(jrnl.override,"_recursively_apply",wraps=jrnl.override._recursively_apply) as mock_recurse, \ - mock.patch('jrnl.install.load_or_install_jrnl', return_value=context.cfg), \ + mock.patch('jrnl.install.load_or_install_jrnl', return_value=context.jrnl_config), \ mock.patch('jrnl.time.parse', side_effect=_mock_time_parse(context)), \ mock.patch("jrnl.config.get_config_path", side_effect=lambda: context.config_path), \ mock.patch("jrnl.install.get_config_path", side_effect=lambda: context.config_path) \ : - run(context.parser) + parsed_args = parse_args(context.args) + run(parsed_args) runtime_cfg = mock_recurse.call_args_list[0][0][0] for k in key_as_vec: @@ -80,7 +59,7 @@ def editor_override(context, editor): # fmt: off # see: https://github.com/psf/black/issues/664 with \ - mock.patch("jrnl.jrnl._write_in_editor", side_effect=_mock_write_in_editor(context.cfg)) as mock_write_in_editor, \ + mock.patch("jrnl.jrnl._write_in_editor", side_effect=_mock_write_in_editor(context.jrnl_config)) as mock_write_in_editor, \ mock.patch("sys.stdin.isatty", return_value=True), \ mock.patch("jrnl.time.parse", side_effect = _mock_time_parse(context)), \ mock.patch("jrnl.config.get_config_path", side_effect=lambda: context.config_path), \ @@ -90,7 +69,7 @@ def editor_override(context, editor): run(context.parser) context.exit_status = 0 context.editor = mock_write_in_editor - expected_config = context.cfg + expected_config = context.jrnl_config expected_config['editor'] = '%s'%editor expected_config['journal'] ='features/journals/journal.jrnl' @@ -101,7 +80,7 @@ def editor_override(context, editor): # fmt: on -@then("the stdin prompt must be launched") +@then("the stdin prompt should have been called") def override_editor_to_use_stdin(context): try: @@ -109,7 +88,7 @@ def override_editor_to_use_stdin(context): "sys.stdin.read", return_value="Zwei peanuts walk into a bar und one of zem was a-salted", ) as mock_stdin_read, mock.patch( - "jrnl.install.load_or_install_jrnl", return_value=context.cfg + "jrnl.install.load_or_install_jrnl", return_value=context.jrnl_config ), mock.patch( "jrnl.Journal.open_journal", spec=False,