From 43b8407ad53dfc398d9f08853c33d9fa74985681 Mon Sep 17 00:00:00 2001 From: Suhas Date: Sat, 23 Jan 2021 11:08:01 -0500 Subject: [PATCH] implement editor override step --- features/steps/core.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/features/steps/core.py b/features/steps/core.py index d39b43f4..e6c88609 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -215,6 +215,29 @@ def open_editor_and_enter(context, method, text=""): @then("the editor {editor} should have been called") def editor_override(context, editor): + def _mock_editor(command_and_journal_file): + editor = command_and_journal_file[0] + context.tmpfile = command_and_journal_file[-1] + print("%s has been launched"%editor) + return tmpfile + + try : + # fmt: off + # see: https://github.com/psf/black/issues/664 + with \ + patch("subprocess.call", side_effect=_mock_editor) as mock_editor, \ + patch("sys.stdin.isatty", return_value=True), \ + 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.get_config_path", side_effect=lambda: context.config_path) \ + : + cli(['--override','{"editor": "%s"}'%editor]) + context.exit_status = 0 + context.editor = mock_editor + assert mock_editor.assert_called_once_with(editor, context.tmpfile) + except SystemExit as e: + context.exit_status = e.code + @then("the editor should have been called") @then("the editor should have been called with {num} arguments") def count_editor_args(context, num=None):