Expand "we run" step in pytest-bdd

- Add some necessary fixtures
- Add datetime test
- Implement "the output should not contain" step
- Implement "the output should contain the date" step

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
This commit is contained in:
Jonathan Wren 2021-02-20 18:41:07 -08:00
parent 74ae5f039b
commit 72170304ef
2 changed files with 63 additions and 3 deletions

View file

@ -67,3 +67,39 @@ Feature: Reading and writing to journal with custom date formats
# | little_endian_dates.yaml | -on 'july' --short | 10.07.2013 15:40 Life is good. | # | little_endian_dates.yaml | -on 'july' --short | 10.07.2013 15:40 Life is good. |
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."
Then we should get no error
When we run "jrnl -999"
Then the output should contain "10.05.2013 09:00 I saw Elvis."
And the output should contain "He's alive."
Scenario: Viewing today's entries does not print the entire journal
# see: https://github.com/jrnl-org/jrnl/issues/741
Given we use the config "simple.yaml"
When we run "jrnl -on today"
Then the output should not contain "Life is good"
And the output should not contain "But I'm better."
Scenario Outline: Create entry using day of the week as entry date.
Given we use the config "simple.yaml"
When we run "jrnl <command>"
Then we should see the message "Entry added"
When we run "jrnl -1"
Then the output should contain "<output>"
Then the output should contain the date "<date>"
Examples: Days of the week
| command | output | date |
| Monday: entry on a monday | entry on a monday | monday at 9am |
| Tuesday: entry on a tuesday | entry on a tuesday | tuesday at 9am |
| Wednesday: entry on a wednesday | entry on a wednesday | wednesday at 9am |
| Thursday: entry on a thursday | entry on a thursday | thursday at 9am |
| Friday: entry on a friday | entry on a friday | friday at 9am |
| Saturday: entry on a saturday | entry on a saturday | saturday at 9am |
| Sunday: entry on a sunday | entry on a sunday | sunday at 9am |
| sunday: entry on a sunday | entry on a sunday | sunday at 9am |
| sUndAy: entry on a sunday | entry on a sunday | sunday at 9am |

View file

@ -47,6 +47,16 @@ def toml_version(working_dir):
return pyproject_contents["tool"]["poetry"]["version"] return pyproject_contents["tool"]["poetry"]["version"]
@fixture
def command():
return ''
@fixture
def user_input():
return ''
# ----- STEPS ----- # # ----- STEPS ----- #
@given(parse('we use the config "{config_file}"'), target_fixture="config_path") @given(parse('we use the config "{config_file}"'), target_fixture="config_path")
@given('we use the config "<config_file>"', target_fixture="config_path") @given('we use the config "<config_file>"', target_fixture="config_path")
@ -77,7 +87,9 @@ def we_use_the_config(config_file, temp_dir, working_dir):
@when(parse('we run "jrnl {command}"')) @when(parse('we run "jrnl {command}"'))
@when('we run "jrnl <command>"') @when('we run "jrnl <command>"')
def we_run(command, config_path, cli_run, capsys): @when('we run "jrnl"')
@when(parse('we run "jrnl" and enter "{user_input}"'))
def we_run(command, config_path, user_input, cli_run, capsys):
args = split_args(command) args = split_args(command)
status = 0 status = 0
@ -85,8 +97,8 @@ def we_run(command, config_path, cli_run, capsys):
# see: https://github.com/psf/black/issues/664 # see: https://github.com/psf/black/issues/664
with \ with \
patch("sys.argv", ['jrnl'] + args), \ patch("sys.argv", ['jrnl'] + args), \
patch("jrnl.config.get_config_path", side_effect=lambda: config_path), \ patch("sys.stdin.read", return_value=user_input) as mock_read, \
patch("jrnl.install.get_config_path", side_effect=lambda: config_path) \ patch("jrnl.install.get_config_path", return_value=config_path) \
: :
try: try:
cli(args) cli(args)
@ -119,6 +131,13 @@ def output_should_contain(output, cli_run):
assert output and output in cli_run["stdout"] assert output and output in cli_run["stdout"]
@then(parse("the output should not contain\n{output}"))
@then(parse('the output should not contain "{output}"'))
@then('the output should not contain "<output>"')
def output_should_contain(output, cli_run):
assert output not in cli_run["stdout"]
@then(parse("the output should be\n{output}")) @then(parse("the output should be\n{output}"))
@then(parse('the output should be "{output}"')) @then(parse('the output should be "{output}"'))
@then('the output should be "<output>"') @then('the output should be "<output>"')
@ -130,6 +149,11 @@ def output_should_be(output, cli_run):
), failed_msg('Output does not match.', output, actual_out) ), failed_msg('Output does not match.', output, actual_out)
@then('the output should contain the date "<date>"')
def output_should_contain(output, cli_run):
assert output and output in cli_run["stdout"]
@then("the output should contain pyproject.toml version") @then("the output should contain pyproject.toml version")
def output_should_contain_version(cli_run, toml_version): def output_should_contain_version(cli_run, toml_version):
out = cli_run["stdout"] out = cli_run["stdout"]