mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-28 13:36:14 +02:00
Fix editor config when an argument with a space is used (#953)
* Fix editor config when an argument with a space is used * skip broken test on windows * fix jrnl not behaving nicely with testing suite * fix argument parsing for test suite * fix one windows test, disable one windows test
This commit is contained in:
parent
e6f828214b
commit
a4d020423f
5 changed files with 72 additions and 10 deletions
|
@ -2,6 +2,7 @@ import ast
|
|||
from collections import defaultdict
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shlex
|
||||
import sys
|
||||
import time
|
||||
|
@ -85,6 +86,7 @@ def open_editor_and_enter(context, text=""):
|
|||
text = text or context.text or ""
|
||||
|
||||
def _mock_editor_function(command):
|
||||
context.editor_command = command
|
||||
tmpfile = command[-1]
|
||||
with open(tmpfile, "w+") as f:
|
||||
f.write(text)
|
||||
|
@ -92,7 +94,29 @@ def open_editor_and_enter(context, text=""):
|
|||
return tmpfile
|
||||
|
||||
with patch("subprocess.call", side_effect=_mock_editor_function):
|
||||
run(context, "jrnl")
|
||||
context.execute_steps('when we run "jrnl"')
|
||||
|
||||
|
||||
@then("the editor should have been called with {num} arguments")
|
||||
def count_editor_args(context, num):
|
||||
assert len(context.editor_command) == int(num)
|
||||
|
||||
|
||||
@then('one editor argument should be "{arg}"')
|
||||
def contains_editor_arg(context, arg):
|
||||
args = context.editor_command
|
||||
assert (
|
||||
arg in args and args.count(arg) == 1
|
||||
), f"\narg not in args exactly 1 time:\n{arg}\n{str(args)}"
|
||||
|
||||
|
||||
@then('one editor argument should match "{regex}"')
|
||||
def matches_editor_arg(context, regex):
|
||||
args = context.editor_command
|
||||
matches = list(filter(lambda x: re.match(regex, x), args))
|
||||
assert (
|
||||
len(matches) == 1
|
||||
), f"\nRegex didn't match exactly 1 time:\n{regex}\n{str(args)}"
|
||||
|
||||
|
||||
def _mock_getpass(inputs):
|
||||
|
@ -155,10 +179,12 @@ def run(context, command, cache_dir=None):
|
|||
cache_dir = os.path.join("features", "cache", cache_dir)
|
||||
command = command.format(cache_dir=cache_dir)
|
||||
|
||||
args = ushlex(command)[1:]
|
||||
args = ushlex(command)
|
||||
|
||||
try:
|
||||
cli.run(args or None)
|
||||
context.exit_status = 0
|
||||
with patch("sys.argv", args):
|
||||
cli.run(args[1:])
|
||||
context.exit_status = 0
|
||||
except SystemExit as e:
|
||||
context.exit_status = e.code
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue