mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
* make behave slightly less verbose for use with behave --format progress2 * standardize behave tests * move tests around to be more behavior driven * clean up txt file after tests * add more tests, add more functionality to behave for calling mock editor * move around behave tests, get rid of regression files * clean up some code around keyrings * add more placeholder test scenarios (marked with @todo) You can run just these tests with `behave --no-skipped --tags=todo` * fix "missing_directory" test This test was missing the config file it was trying to use. So, it was really a very useless, broken test that we absolutely should not have approved the PR (#963) for. * add write tests for each journal type * update version tests, add new regex match behave step * add config test outlines * add journal types to some search tests * change "basic" config reference to "simple" * update configs * add more journal types in search * fix basic folder journal reference * add flush output steps to behave, update delete flag tests * fix failing test with a flush * update more delete flag tests to include other journal types * fix file cleanup after failed test with no debug on * fix password test * fix DayOne tag sample data, move search/format tag tests, and run them on multiple jrnl types * added ability to auto-prompt for password for encrypted journals Only uses password when prompted, and doesn't get in the way of other input prompts. This allows us to run the same scenarios on both encrypted journals and other journal types. * fold encrypted scenarios into the rest of the scenarios where possible * remove apostrophe that is breaking tests on CI * add more journal type tests to import feature * standardize whitespace in behave tests, take out duplicate test * update handling of cache directories in test suite (easier syntax) * skip failing YAML exporter emoji test on Windows * added @todo tags for things that need follow-up Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
86 lines
2.6 KiB
Python
86 lines
2.6 KiB
Python
import os
|
|
import shutil
|
|
|
|
from jrnl.os_compat import on_windows
|
|
|
|
CWD = os.getcwd()
|
|
|
|
# @see https://behave.readthedocs.io/en/latest/tutorial.html#debug-on-error-in-case-of-step-failures
|
|
BEHAVE_DEBUG_ON_ERROR = False
|
|
|
|
|
|
def setup_debug_on_error(userdata):
|
|
global BEHAVE_DEBUG_ON_ERROR
|
|
BEHAVE_DEBUG_ON_ERROR = userdata.getbool("BEHAVE_DEBUG_ON_ERROR")
|
|
|
|
|
|
def before_all(context):
|
|
setup_debug_on_error(context.config.userdata)
|
|
|
|
|
|
# def after_step(context, step):
|
|
# if BEHAVE_DEBUG_ON_ERROR and step.status == "failed":
|
|
# -- ENTER DEBUGGER: Zoom in on failure location.
|
|
# NOTE: Use IPython debugger, same for pdb (basic python debugger).
|
|
# import ipdb
|
|
# ipdb.post_mortem(step.exc_traceback)
|
|
|
|
|
|
def clean_all_working_dirs():
|
|
if os.path.exists("test.txt"):
|
|
os.remove("test.txt")
|
|
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()
|
|
return
|
|
|
|
if "skip_win" in feature.tags and on_windows:
|
|
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()
|
|
return
|
|
|
|
if "skip_win" in scenario.effective_tags and on_windows:
|
|
scenario.skip("Skipping on Windows")
|
|
return
|
|
|
|
|
|
def after_scenario(context, scenario):
|
|
"""After each scenario, restore all test data and remove working_dirs."""
|
|
if os.getcwd() != CWD:
|
|
os.chdir(CWD)
|
|
|
|
# only clean up if debugging is off and the scenario passed
|
|
if BEHAVE_DEBUG_ON_ERROR and scenario.status != "failed":
|
|
clean_all_working_dirs()
|
|
else:
|
|
clean_all_working_dirs()
|