From e257194d177c8590accaef0c5f5f508c848028b7 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 20 Feb 2021 14:00:40 -0800 Subject: [PATCH] Add scenario outline test to datetime - Allow config step to support scenario outlines - Add another datetime test - Get rid of read journal step since it doesn't work with other journal types (we should rely on jrnl knowing how to parse each jrnl type for better tests) Co-authored-by: Micah Jerome Ellison --- tests/features/datetime.feature | 17 +++++++++++++++++ tests/step_defs/conftest.py | 31 +++++++++++++------------------ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/tests/features/datetime.feature b/tests/features/datetime.feature index ca82e8c0..d28092ce 100644 --- a/tests/features/datetime.feature +++ b/tests/features/datetime.feature @@ -31,3 +31,20 @@ Feature: Reading and writing to journal with custom date formats | But I'm better. + Scenario Outline: Writing an entry from command line with custom date + Given we use the config "" + When we run "jrnl " + Then we should see the message "Entry added" + When we run "jrnl -n 1" + Then the output should contain "" + + Examples: Day-first Dates + | config_file | command | output | + | little_endian_dates.yaml | 2020-09-19: My first entry. | 19.09.2020 09:00 My first entry. | + | little_endian_dates.yaml | 2020-08-09: My second entry. | 09.08.2020 09:00 My second entry. | + | little_endian_dates.yaml | 2020-02-29: Test. | 29.02.2020 09:00 Test. | + | little_endian_dates.yaml | 2019-02-29: Test. | 2019-02-29: Test. | + | little_endian_dates.yaml | 2020-08-32: Test. | 2020-08-32: Test. | + | little_endian_dates.yaml | 2032-02-01: Test. | 01.02.2032 09:00 Test. | + | little_endian_dates.yaml | 2020-01-01: Test. | 01.01.2020 09:00 Test. | + | little_endian_dates.yaml | 2020-12-31: Test. | 31.12.2020 09:00 Test. | diff --git a/tests/step_defs/conftest.py b/tests/step_defs/conftest.py index 0eec48ed..99825ff8 100644 --- a/tests/step_defs/conftest.py +++ b/tests/step_defs/conftest.py @@ -42,16 +42,9 @@ def toml_version(working_dir): return pyproject_contents["tool"]["poetry"]["version"] -@fixture -def read_journal(journal_name="default"): - configuration = load_config(context.config_path) - with open(configuration["journals"][journal_name]) as journal_file: - journal = journal_file.read() - return journal - - # ----- STEPS ----- # @given(parse('we use the config "{config_file}"'), target_fixture="config_path") +@given('we use the config ""', target_fixture="config_path") def set_config(config_file, temp_dir, working_dir): # Move into temp dir as cwd os.chdir(temp_dir.name) @@ -77,7 +70,8 @@ def set_config(config_file, temp_dir, working_dir): return config_dest -@when(parse('we run "{command}"')) +@when(parse('we run "jrnl {command}"')) +@when('we run "jrnl "') def run(command, config_path, cli_run, capsys): args = split_args(command) status = 0 @@ -85,12 +79,12 @@ def run(command, config_path, cli_run, capsys): # fmt: off # see: https://github.com/psf/black/issues/664 with \ - patch("sys.argv", args), \ + patch("sys.argv", ['jrnl'] + args), \ patch("jrnl.config.get_config_path", side_effect=lambda: config_path), \ patch("jrnl.install.get_config_path", side_effect=lambda: config_path) \ : try: - cli(args[1:]) + cli(args) except SystemExit as e: status = e.code # fmt: on @@ -113,10 +107,11 @@ def matches_std_output(regex, cli_run): assert matches, f"\nRegex didn't match:\n{regex}\n{str(out)}\n{str(matches)}" -@then(parse("the output should contain\n{text}")) -@then(parse('the output should contain "{text}"')) -def check_output_inline(text, cli_run): - assert text and text in cli_run["stdout"] +@then(parse("the output should contain\n{output}")) +@then(parse('the output should contain "{output}"')) +@then('the output should contain ""') +def check_output_inline(output, cli_run): + assert output and output in cli_run["stdout"] @then(parse('the output should be "{expected_out}"')) @@ -124,8 +119,9 @@ def check_output_inline(text, cli_run): def check_output(cli_run, expected_out): expected_out = expected_out.strip() actual_out = cli_run["stdout"].strip() - assert expected_out == actual_out, \ - f"Output does not match.\nExpected:\n{expected_out}\n---end---\nActual:\n{actual_out}\n---end---\n" + assert ( + expected_out == actual_out + ), f"Output does not match.\nExpected:\n{expected_out}\n---end---\nActual:\n{actual_out}\n---end---\n" @then("the output should contain pyproject.toml version") @@ -138,4 +134,3 @@ def check_output_version_inline(cli_run, toml_version): def check_message(text, cli_run): out = cli_run["stderr"] assert text in out, [text, out] -