mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
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 <micah.jerome.ellison@gmail.com>
This commit is contained in:
parent
7974f30261
commit
e257194d17
2 changed files with 30 additions and 18 deletions
|
@ -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 "<config_file>"
|
||||
When we run "jrnl <command>"
|
||||
Then we should see the message "Entry added"
|
||||
When we run "jrnl -n 1"
|
||||
Then the output should contain "<output>"
|
||||
|
||||
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. |
|
||||
|
|
|
@ -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 "<config_file>"', 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 <command>"')
|
||||
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 "<output>"')
|
||||
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]
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue