From c9404d013dd02cae9865afef2da2ef6b3d2e51bb Mon Sep 17 00:00:00 2001 From: Suhas Date: Thu, 4 Feb 2021 08:52:46 -0500 Subject: [PATCH] rework core run() so config_upgrade can be tested --- features/steps/core.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/features/steps/core.py b/features/steps/core.py index eaeb04da..724d41cc 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -130,7 +130,7 @@ def set_config(context, config_file): # Add jrnl version to file for 2.x journals with open(context.config_path, "a") as cf: cf.write("version: {}".format(__version__)) - + @given('we use the password "{password}" if prompted') def use_password_forever(context, password): @@ -388,14 +388,18 @@ def all_input_was_used(context): for temp in context.iter_text: assert "" == temp, "Not all inputs were consumed" - @when('we run "{command}"') @when('we run "{command}" and pipe') @when('we run "{command}" and pipe "{text}"') def run(context, command, text=""): text = text or context.text or "" - with open(context.config_path) as f: - context.jrnl_config = yaml.load(f,Loader=yaml.FullLoader) + + 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: cache_dir = os.path.join("features", "cache", context.cache_dir) command = command.format(cache_dir=cache_dir) @@ -425,7 +429,7 @@ def run(context, command, text=""): patch("sys.stdin.read", side_effect=lambda: text), \ patch("jrnl.time.parse", side_effect=_mock_time_parse(context)), \ patch("jrnl.config.get_config_path", side_effect=lambda: context.config_path), \ - patch("jrnl.install.load_or_install_jrnl",return_value = context.jrnl_config), \ + patch("jrnl.install.load_or_install_jrnl",wraps=jrnl.install.load_or_install_jrnl), \ patch("jrnl.install.get_config_path", side_effect=lambda: context.config_path) \ : context.editor = mock_editor