From 7974f3026160caa9e6d0fe7e5fdb9c7d04e42f95 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 20 Feb 2021 13:18:35 -0800 Subject: [PATCH] Make tests move into temp dir as they run This will prevent any unexpected files from showing up anywhere outside the temp dir Co-authored-by: Micah Jerome Ellison --- tests/features/datetime.feature | 22 ++++++++++++++++++++++ tests/step_defs/conftest.py | 20 +++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/tests/features/datetime.feature b/tests/features/datetime.feature index cbb31ff4..ca82e8c0 100644 --- a/tests/features/datetime.feature +++ b/tests/features/datetime.feature @@ -9,3 +9,25 @@ Feature: Reading and writing to journal with custom date formats Then the output should contain "2013-11-30 15:42 Project Started." + Scenario: Dates can be in the future + # https://github.com/jrnl-org/jrnl/issues/185 + Given we use the config "simple.yaml" + When we run "jrnl 26/06/2099: Planet? Earth. Year? 2099." + Then we should see the message "Entry added" + When we run "jrnl -999" + Then the output should contain "2099-06-26 09:00 Planet?" + + + Scenario: Loading a sample journal with custom date + Given we use the config "little_endian_dates.yaml" + When we run "jrnl -n 2" + Then we should get no error + When we run "jrnl -n 999" + Then the output should be + 09.06.2013 15:39 My first entry. + | Everything is alright + + 10.07.2013 15:40 Life is good. + | But I'm better. + + diff --git a/tests/step_defs/conftest.py b/tests/step_defs/conftest.py index a764d090..0eec48ed 100644 --- a/tests/step_defs/conftest.py +++ b/tests/step_defs/conftest.py @@ -53,6 +53,9 @@ def read_journal(journal_name="default"): # ----- STEPS ----- # @given(parse('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) + # Copy the config file over config_source = os.path.join(working_dir, "data", "configs", config_file) config_dest = os.path.join(temp_dir.name, config_file) @@ -61,7 +64,7 @@ def set_config(config_file, temp_dir, working_dir): # @todo make this only copy some journals over # Copy all of the journals over journal_source = os.path.join(working_dir, "data", "journals") - journal_dest = os.path.join(temp_dir.name, "journals") + journal_dest = os.path.join(temp_dir.name, "features", "journals") shutil.copytree(journal_source, journal_dest) # @todo get rid of this by using default config values @@ -116,6 +119,15 @@ def check_output_inline(text, cli_run): assert text and text in cli_run["stdout"] +@then(parse('the output should be "{expected_out}"')) +@then(parse("the output should be\n{expected_out}")) +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" + + @then("the output should contain pyproject.toml version") def check_output_version_inline(cli_run, toml_version): out = cli_run["stdout"] @@ -127,9 +139,3 @@ def check_message(text, cli_run): out = cli_run["stderr"] assert text in out, [text, out] - -@then(parse('the journal should contain "{text}"')) -@then(parse('journal "{journal_name}" should contain "{text}"')) -def check_journal_content(context, text, journal_name="default"): - journal = read_journal(context, journal_name) - assert text in journal, journal