clean up extra directories after running behave

This commit is contained in:
Jonathan Wren 2020-05-06 14:15:22 -07:00
parent 065f38cfe4
commit 4e09c75ff7
4 changed files with 12 additions and 9 deletions

View file

@ -18,7 +18,7 @@ def before_feature(context, feature):
def before_scenario(context, scenario):
"""Before each scenario, backup all config and journal test data."""
# Clean up in case something went wrong
for folder in ("configs", "journals"):
for folder in ("configs", "journals", "cache"):
working_dir = os.path.join("features", folder)
if os.path.exists(working_dir):
shutil.rmtree(working_dir)
@ -48,7 +48,7 @@ def before_scenario(context, scenario):
def after_scenario(context, scenario):
"""After each scenario, restore all test data and remove working_dirs."""
for folder in ("configs", "journals"):
for folder in ("configs", "journals", "cache"):
working_dir = os.path.join("features", folder)
if os.path.exists(working_dir):
shutil.rmtree(working_dir)

View file

@ -123,7 +123,7 @@ Feature: Exporting a Journal
Scenario: Export to yaml
Given we use the config "tags.yaml"
And we created a directory named "exported_journal"
When we run "jrnl --export yaml -o exported_journal"
When we run "jrnl --export yaml -o features/cache/exported_journal"
Then "exported_journal" should contain the files ["2013-04-09_i-have-an-idea.md", "2013-06-10_i-met-with-dan.md"]
And the content of exported yaml "exported_journal/2013-04-09_i-have-an-idea.md" should be
"""

View file

@ -149,7 +149,7 @@ Feature: Zapped bugs should stay dead.
Scenario: Add a blank line to YAML export is there isn't one already
Given we use the config "deletion.yaml"
And we created a directory named "bug768"
When we run "jrnl --export yaml -o bug768"
When we run "jrnl --export yaml -o features/cache/bug768"
Then "bug768" should contain the files ["2019-10-29_first-entry.md", "2019-10-29_second-entry.md", "2019-10-29_third-entry.md"]
And the content of exported yaml "bug768/2019-10-29_third-entry.md" should be
"""

View file

@ -87,14 +87,16 @@ def assert_xml_output_tags(context, expected_tags_json_list):
@given('we created a directory named "{dir_name}"')
def create_directory(context, dir_name):
if os.path.exists(dir_name):
shutil.rmtree(dir_name)
os.mkdir(dir_name)
working_dir = os.path.join("features", "cache", dir_name)
if os.path.exists(working_dir):
shutil.rmtree(working_dir)
os.makedirs(working_dir)
@then('"{dir_name}" should contain the files {expected_files_json_list}')
def assert_dir_contains_files(context, dir_name, expected_files_json_list):
actual_files = os.listdir(dir_name)
working_dir = os.path.join("features", "cache", dir_name)
actual_files = os.listdir(working_dir)
expected_files = json.loads(expected_files_json_list)
# sort to deal with inconsistent default file ordering on different OS's
@ -107,8 +109,9 @@ def assert_dir_contains_files(context, dir_name, expected_files_json_list):
@then('the content of exported yaml "{file_path}" should be')
def assert_exported_yaml_file_content(context, file_path):
expected_content = context.text.strip().splitlines()
full_file_path = os.path.join("features", "cache", file_path)
with open(file_path, "r") as f:
with open(full_file_path, "r") as f:
actual_content = f.read().strip().splitlines()
for actual_line, expected_line in zip(actual_content, expected_content):