rework core run() so config_upgrade can be tested

This commit is contained in:
Suhas 2021-02-04 08:52:46 -05:00
parent ce930a27a1
commit c9404d013d

View file

@ -130,7 +130,7 @@ def set_config(context, config_file):
# Add jrnl version to file for 2.x journals # Add jrnl version to file for 2.x journals
with open(context.config_path, "a") as cf: with open(context.config_path, "a") as cf:
cf.write("version: {}".format(__version__)) cf.write("version: {}".format(__version__))
@given('we use the password "{password}" if prompted') @given('we use the password "{password}" if prompted')
def use_password_forever(context, password): def use_password_forever(context, password):
@ -388,14 +388,18 @@ def all_input_was_used(context):
for temp in context.iter_text: for temp in context.iter_text:
assert "" == temp, "Not all inputs were consumed" assert "" == temp, "Not all inputs were consumed"
@when('we run "{command}"') @when('we run "{command}"')
@when('we run "{command}" and pipe') @when('we run "{command}" and pipe')
@when('we run "{command}" and pipe "{text}"') @when('we run "{command}" and pipe "{text}"')
def run(context, command, text=""): def run(context, command, text=""):
text = text or context.text or "" 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: 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)
@ -425,7 +429,7 @@ def run(context, command, text=""):
patch("sys.stdin.read", side_effect=lambda: text), \ patch("sys.stdin.read", side_effect=lambda: text), \
patch("jrnl.time.parse", side_effect=_mock_time_parse(context)), \ patch("jrnl.time.parse", side_effect=_mock_time_parse(context)), \
patch("jrnl.config.get_config_path", side_effect=lambda: context.config_path), \ 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) \ patch("jrnl.install.get_config_path", side_effect=lambda: context.config_path) \
: :
context.editor = mock_editor context.editor = mock_editor