mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 19:48:31 +02:00
fix handling of 'we should' statements
This commit is contained in:
parent
af8355b499
commit
1304cc8e36
2 changed files with 27 additions and 26 deletions
|
@ -92,3 +92,4 @@ Feature: Multiple journals
|
||||||
And we use the config "basic_encrypted.yaml"
|
And we use the config "basic_encrypted.yaml"
|
||||||
When we run "jrnl --cf editor_encrypted.yaml --decrypt"
|
When we run "jrnl --cf editor_encrypted.yaml --decrypt"
|
||||||
Then the config should contain "encrypt: true"
|
Then the config should contain "encrypt: true"
|
||||||
|
And the output should not contain "Wrong password"
|
||||||
|
|
|
@ -30,25 +30,37 @@ def output_should_match(regex, cli_run):
|
||||||
assert matches, f"\nRegex didn't match:\n{regex}\n{str(out)}\n{str(matches)}"
|
assert matches, f"\nRegex didn't match:\n{regex}\n{str(out)}\n{str(matches)}"
|
||||||
|
|
||||||
|
|
||||||
@then(parse("the output should contain\n{expected_output}"))
|
@then(parse("the output {should_or_should_not} contain\n{expected_output}"))
|
||||||
@then(parse('the output should contain "{expected_output}"'))
|
@then(parse('the output {should_or_should_not} contain "{expected_output}"'))
|
||||||
@then(parse("the {which_output_stream} output should contain\n{expected_output}"))
|
@then(
|
||||||
@then(parse('the {which_output_stream} output should contain "{expected_output}"'))
|
parse(
|
||||||
def output_should_contain(expected_output, which_output_stream, cli_run):
|
"the {which_output_stream} output {should_or_should_not} contain\n{expected_output}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
@then(
|
||||||
|
parse(
|
||||||
|
'the {which_output_stream} output {should_or_should_not} contain "{expected_output}"'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
def output_should_contain(
|
||||||
|
expected_output, which_output_stream, cli_run, should_or_should_not
|
||||||
|
):
|
||||||
|
we_should = parse_should_or_should_not(should_or_should_not)
|
||||||
|
|
||||||
assert expected_output
|
assert expected_output
|
||||||
if which_output_stream is None:
|
if which_output_stream is None:
|
||||||
assert (expected_output in cli_run["stdout"]) or (
|
assert ((expected_output in cli_run["stdout"]) == we_should) or (
|
||||||
expected_output in cli_run["stderr"]
|
(expected_output in cli_run["stderr"]) == we_should
|
||||||
)
|
)
|
||||||
|
|
||||||
elif which_output_stream == "standard":
|
elif which_output_stream == "standard":
|
||||||
assert expected_output in cli_run["stdout"]
|
assert (expected_output in cli_run["stdout"]) == we_should
|
||||||
|
|
||||||
elif which_output_stream == "error":
|
elif which_output_stream == "error":
|
||||||
assert expected_output in cli_run["stderr"]
|
assert (expected_output in cli_run["stderr"]) == we_should
|
||||||
|
|
||||||
else:
|
else:
|
||||||
assert expected_output in cli_run[which_output_stream]
|
assert (expected_output in cli_run[which_output_stream]) == we_should
|
||||||
|
|
||||||
|
|
||||||
@then(parse("the output should not contain\n{expected_output}"))
|
@then(parse("the output should not contain\n{expected_output}"))
|
||||||
|
@ -116,10 +128,7 @@ def config_var_on_disk(config_on_disk, journal_name, should_or_should_not, some_
|
||||||
# `expected` objects formatted in yaml only compare one level deep
|
# `expected` objects formatted in yaml only compare one level deep
|
||||||
actual_slice = {key: actual.get(key, None) for key in expected.keys()}
|
actual_slice = {key: actual.get(key, None) for key in expected.keys()}
|
||||||
|
|
||||||
if we_should:
|
assert (expected == actual_slice) == we_should
|
||||||
assert expected == actual_slice
|
|
||||||
else:
|
|
||||||
assert expected != actual_slice
|
|
||||||
|
|
||||||
|
|
||||||
@then(
|
@then(
|
||||||
|
@ -150,10 +159,7 @@ def config_var_in_memory(
|
||||||
# `expected` objects formatted in yaml only compare one level deep
|
# `expected` objects formatted in yaml only compare one level deep
|
||||||
actual_slice = {key: get_nested_val(actual, key) for key in expected.keys()}
|
actual_slice = {key: get_nested_val(actual, key) for key in expected.keys()}
|
||||||
|
|
||||||
if we_should:
|
assert (expected == actual_slice) == we_should
|
||||||
assert expected == actual_slice
|
|
||||||
else:
|
|
||||||
assert expected != actual_slice
|
|
||||||
|
|
||||||
|
|
||||||
@then("we should be prompted for a password")
|
@then("we should be prompted for a password")
|
||||||
|
@ -345,10 +351,7 @@ def count_elements(number, item, cli_run):
|
||||||
def count_editor_args(num_args, cli_run, editor_state, should_or_should_not):
|
def count_editor_args(num_args, cli_run, editor_state, should_or_should_not):
|
||||||
we_should = parse_should_or_should_not(should_or_should_not)
|
we_should = parse_should_or_should_not(should_or_should_not)
|
||||||
|
|
||||||
if we_should:
|
assert cli_run["mocks"]["editor"].called == we_should
|
||||||
assert cli_run["mocks"]["editor"].called
|
|
||||||
else:
|
|
||||||
assert not cli_run["mocks"]["editor"].called
|
|
||||||
|
|
||||||
if isinstance(num_args, int):
|
if isinstance(num_args, int):
|
||||||
assert len(editor_state["command"]) == int(num_args)
|
assert len(editor_state["command"]) == int(num_args)
|
||||||
|
@ -358,10 +361,7 @@ def count_editor_args(num_args, cli_run, editor_state, should_or_should_not):
|
||||||
def stdin_prompt_called(cli_run, should_or_should_not):
|
def stdin_prompt_called(cli_run, should_or_should_not):
|
||||||
we_should = parse_should_or_should_not(should_or_should_not)
|
we_should = parse_should_or_should_not(should_or_should_not)
|
||||||
|
|
||||||
if we_should:
|
assert cli_run["mocks"]["stdin"].called == we_should
|
||||||
assert cli_run["mocks"]["stdin"].called
|
|
||||||
else:
|
|
||||||
assert not cli_run["mocks"]["stdin"].called
|
|
||||||
|
|
||||||
|
|
||||||
@then(parse('the editor filename should end with "{suffix}"'))
|
@then(parse('the editor filename should end with "{suffix}"'))
|
||||||
|
|
Loading…
Add table
Reference in a new issue