mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 04:58:32 +02:00
implement editor override step
This commit is contained in:
parent
12d2f48f97
commit
43b8407ad5
1 changed files with 23 additions and 0 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Reference in a new issue