Add _mock_editor_function

This commit is contained in:
Aaron Lichtman 2019-11-16 13:42:30 +01:00
parent ccb55392dd
commit 9b0ebb7d84
No known key found for this signature in database
GPG key ID: 22368077DE9F9903

View file

@ -71,7 +71,15 @@ def set_config(context, config_file):
@when('we open the editor and enter {text}') @when('we open the editor and enter {text}')
def open_editor_and_enter(context, text=""): def open_editor_and_enter(context, text=""):
text = (text or context.text) text = (text or context.text)
with patch('subprocess.call', return_value=text): print("open_editor_and_enter called")
def _mock_editor_function(command):
print("_mock_editor_function called")
tmpfile = command.split()[-1]
print("TMPFILE:", tmpfile)
with open(tmpfile, "w+") as f:
f.write(text)
with patch('subprocess.call', side_effect=_mock_editor_function):
run(context, "jrnl") run(context, "jrnl")