From 4e09c75ff7338db34b1f43a4b38673918526cfcf Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Wed, 6 May 2020 14:15:22 -0700 Subject: [PATCH] clean up extra directories after running behave --- features/environment.py | 4 ++-- features/exporting.feature | 2 +- features/regression.feature | 2 +- features/steps/export_steps.py | 13 ++++++++----- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/features/environment.py b/features/environment.py index 02f2747e..e2fab73c 100644 --- a/features/environment.py +++ b/features/environment.py @@ -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) diff --git a/features/exporting.feature b/features/exporting.feature index 89abfd0e..230acd94 100644 --- a/features/exporting.feature +++ b/features/exporting.feature @@ -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 """ diff --git a/features/regression.feature b/features/regression.feature index 033ec95c..e687e364 100644 --- a/features/regression.feature +++ b/features/regression.feature @@ -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 """ diff --git a/features/steps/export_steps.py b/features/steps/export_steps.py index 40127ecc..0acdce8f 100644 --- a/features/steps/export_steps.py +++ b/features/steps/export_steps.py @@ -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):