mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 11:38:32 +02:00
rework mocks in test suite for new messaging functionality
This commit is contained in:
parent
d2f2967bc1
commit
34df64c989
4 changed files with 41 additions and 45 deletions
|
@ -69,7 +69,7 @@ Feature: Reading and writing to journal with custom date formats
|
|||
|
||||
Scenario: Writing an entry at the prompt with custom date
|
||||
Given we use the config "little_endian_dates.yaml"
|
||||
When we run "jrnl" and enter "2013-05-10: I saw Elvis. He's alive."
|
||||
When we run "jrnl" and pipe "2013-05-10: I saw Elvis. He's alive."
|
||||
Then we should get no error
|
||||
When we run "jrnl -999"
|
||||
Then the output should contain "10.05.2013 09:00 I saw Elvis."
|
||||
|
|
|
@ -86,7 +86,7 @@ def cli_run(
|
|||
mock_editor,
|
||||
mock_user_input,
|
||||
mock_overrides,
|
||||
mock_password,
|
||||
mock_piped_input,
|
||||
):
|
||||
# Check if we need more mocks
|
||||
mock_factories.update(mock_args)
|
||||
|
@ -95,7 +95,7 @@ def cli_run(
|
|||
mock_factories.update(mock_editor)
|
||||
mock_factories.update(mock_config_path)
|
||||
mock_factories.update(mock_user_input)
|
||||
mock_factories.update(mock_password)
|
||||
mock_factories.update(mock_piped_input)
|
||||
|
||||
return {
|
||||
"status": 0,
|
||||
|
@ -181,32 +181,6 @@ def toml_version(working_dir):
|
|||
return pyproject_contents["tool"]["poetry"]["version"]
|
||||
|
||||
|
||||
@fixture
|
||||
def mock_password(request):
|
||||
def _mock_password():
|
||||
from rich.console import Console
|
||||
|
||||
password = get_fixture(request, "password")
|
||||
user_input = get_fixture(request, "user_input")
|
||||
|
||||
if password:
|
||||
password = password.splitlines()
|
||||
|
||||
elif user_input:
|
||||
password = user_input.splitlines()
|
||||
|
||||
if not password:
|
||||
password = Exception("Unexpected call for password")
|
||||
|
||||
mock_console = Mock(wraps=Console(stderr=True))
|
||||
mock_console.input = Mock()
|
||||
mock_console.input.side_effect = password
|
||||
|
||||
return patch("jrnl.output._get_console", return_value=mock_console)
|
||||
|
||||
return {"rich_console_input": _mock_password}
|
||||
|
||||
|
||||
@fixture
|
||||
def input_method():
|
||||
return ""
|
||||
|
@ -228,23 +202,43 @@ def should_not():
|
|||
|
||||
|
||||
@fixture
|
||||
def mock_user_input(request, is_tty):
|
||||
def _generator(target):
|
||||
def _mock_user_input():
|
||||
user_input = get_fixture(request, "user_input", None)
|
||||
def mock_piped_input(request, is_tty):
|
||||
def _mock_piped_input():
|
||||
piped_input = get_fixture(request, "all_input", None)
|
||||
|
||||
if user_input is None:
|
||||
user_input = Exception("Unexpected call for user input")
|
||||
else:
|
||||
user_input = user_input.splitlines() if is_tty else [user_input]
|
||||
if piped_input is None:
|
||||
piped_input = Exception("Unexpected call for piped input")
|
||||
else:
|
||||
piped_input = piped_input.splitlines()
|
||||
|
||||
return patch(target, side_effect=user_input)
|
||||
if is_tty:
|
||||
piped_input = []
|
||||
|
||||
return _mock_user_input
|
||||
return patch("sys.stdin.read", side_effect=piped_input)
|
||||
|
||||
return {"piped_input": _mock_piped_input}
|
||||
|
||||
|
||||
@fixture
|
||||
def mock_user_input(request):
|
||||
def _mock_user_input():
|
||||
from rich.console import Console
|
||||
|
||||
user_input = get_fixture(request, "all_input", None)
|
||||
|
||||
if user_input is None:
|
||||
user_input = Exception("Unexpected call for user input")
|
||||
else:
|
||||
user_input = user_input.splitlines()
|
||||
|
||||
mock_console = Mock(wraps=Console(stderr=True))
|
||||
mock_console.input = Mock()
|
||||
mock_console.input.side_effect = user_input
|
||||
|
||||
return patch("jrnl.output._get_console", return_value=mock_console)
|
||||
|
||||
return {
|
||||
"stdin": _generator("sys.stdin.read"),
|
||||
"input": _generator("builtins.input"),
|
||||
"user_input": _mock_user_input
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -61,7 +61,9 @@ def output_should_contain(
|
|||
assert (expected_output in cli_run["stderr"]) == we_should, output_str
|
||||
|
||||
else:
|
||||
assert (expected_output in cli_run[which_output_stream]) == we_should, output_str
|
||||
assert (
|
||||
expected_output in cli_run[which_output_stream]
|
||||
) == we_should, output_str
|
||||
|
||||
|
||||
@then(parse("the output should not contain\n{expected_output}"))
|
||||
|
|
|
@ -22,11 +22,11 @@ def when_we_change_directory(directory_name):
|
|||
# These variables are used in the `@when(re(...))` section below
|
||||
command = '(?P<command>[^"]*)'
|
||||
input_method = "(?P<input_method>enter|pipe)"
|
||||
user_input = '("(?P<user_input>[^"]*)")'
|
||||
all_input = '("(?P<all_input>[^"]*)")'
|
||||
|
||||
|
||||
@when(parse('we run "jrnl {command}" and {input_method}\n{user_input}'))
|
||||
@when(re(f'we run "jrnl ?{command}" and {input_method} {user_input}'))
|
||||
@when(parse('we run "jrnl {command}" and {input_method}\n{all_input}'))
|
||||
@when(re(f'we run "jrnl ?{command}" and {input_method} {all_input}'))
|
||||
@when(parse('we run "jrnl {command}"'))
|
||||
@when('we run "jrnl"')
|
||||
def we_run_jrnl(cli_run, capsys, keyring):
|
||||
|
|
Loading…
Add table
Reference in a new issue