mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
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 <micah.jerome.ellison@gmail.com>
This commit is contained in:
parent
c500730ae6
commit
7974f30261
2 changed files with 35 additions and 7 deletions
|
@ -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."
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,9 @@ def read_journal(journal_name="default"):
|
||||||
# ----- 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")
|
||||||
def set_config(config_file, temp_dir, working_dir):
|
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
|
# Copy the config file over
|
||||||
config_source = os.path.join(working_dir, "data", "configs", config_file)
|
config_source = os.path.join(working_dir, "data", "configs", config_file)
|
||||||
config_dest = os.path.join(temp_dir.name, 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
|
# @todo make this only copy some journals over
|
||||||
# Copy all of the journals over
|
# Copy all of the journals over
|
||||||
journal_source = os.path.join(working_dir, "data", "journals")
|
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)
|
shutil.copytree(journal_source, journal_dest)
|
||||||
|
|
||||||
# @todo get rid of this by using default config values
|
# @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"]
|
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")
|
@then("the output should contain pyproject.toml version")
|
||||||
def check_output_version_inline(cli_run, toml_version):
|
def check_output_version_inline(cli_run, toml_version):
|
||||||
out = cli_run["stdout"]
|
out = cli_run["stdout"]
|
||||||
|
@ -127,9 +139,3 @@ def check_message(text, cli_run):
|
||||||
out = cli_run["stderr"]
|
out = cli_run["stderr"]
|
||||||
assert text in out, [text, out]
|
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
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue