mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-21 05:28:31 +02:00
This adds the ability to run commands in a cache directory without the test writer knowing where the cache directory is located. This will let us expand later if we want to start using system temp folders, without having to rewrite any of our tests.
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
import shutil
|
|
import os
|
|
import sys
|
|
|
|
|
|
def clean_all_working_dirs():
|
|
for folder in ("configs", "journals", "cache"):
|
|
working_dir = os.path.join("features", folder)
|
|
if os.path.exists(working_dir):
|
|
shutil.rmtree(working_dir)
|
|
|
|
|
|
def before_feature(context, feature):
|
|
# add "skip" tag
|
|
# https://stackoverflow.com/a/42721605/4276230
|
|
if "skip" in feature.tags:
|
|
feature.skip("Marked with @skip")
|
|
return
|
|
|
|
if "skip_win" in feature.tags and "win32" in sys.platform:
|
|
feature.skip("Skipping on Windows")
|
|
return
|
|
|
|
|
|
def before_scenario(context, scenario):
|
|
"""Before each scenario, backup all config and journal test data."""
|
|
# Clean up in case something went wrong
|
|
clean_all_working_dirs()
|
|
|
|
for folder in ("configs", "journals"):
|
|
original = os.path.join("features", "data", folder)
|
|
working_dir = os.path.join("features", folder)
|
|
if not os.path.exists(working_dir):
|
|
os.mkdir(working_dir)
|
|
for filename in os.listdir(original):
|
|
source = os.path.join(original, filename)
|
|
if os.path.isdir(source):
|
|
shutil.copytree(source, os.path.join(working_dir, filename))
|
|
else:
|
|
shutil.copy2(source, working_dir)
|
|
|
|
# add "skip" tag
|
|
# https://stackoverflow.com/a/42721605/4276230
|
|
if "skip" in scenario.effective_tags:
|
|
scenario.skip("Marked with @skip")
|
|
return
|
|
|
|
if "skip_win" in scenario.effective_tags and "win32" in sys.platform:
|
|
scenario.skip("Skipping on Windows")
|
|
return
|
|
|
|
|
|
def after_scenario(context, scenario):
|
|
"""After each scenario, restore all test data and remove working_dirs."""
|
|
clean_all_working_dirs()
|