mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-28 13:36:14 +02:00
[WIP] Lots of test refactoring (#1042)
* 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>
This commit is contained in:
parent
b76a1c43da
commit
d916f66dbf
48 changed files with 2382 additions and 1182 deletions
|
@ -1,6 +1,8 @@
|
|||
import json
|
||||
import os
|
||||
import shutil
|
||||
import random
|
||||
import string
|
||||
from xml.etree import ElementTree
|
||||
|
||||
from behave import given
|
||||
|
@ -116,23 +118,32 @@ def assert_xml_output_tags(context, expected_tags_json_list):
|
|||
|
||||
|
||||
@given('we create cache directory "{dir_name}"')
|
||||
def create_directory(context, dir_name):
|
||||
@given("we create a cache directory")
|
||||
def create_directory(context, dir_name=None):
|
||||
if not dir_name:
|
||||
dir_name = "cache_" + "".join(
|
||||
random.choices(string.ascii_uppercase + string.digits, k=20)
|
||||
)
|
||||
|
||||
working_dir = os.path.join("features", "cache", dir_name)
|
||||
if os.path.exists(working_dir):
|
||||
shutil.rmtree(working_dir)
|
||||
os.makedirs(working_dir)
|
||||
context.cache_dir = dir_name
|
||||
|
||||
|
||||
@then('cache directory "{dir_name}" should contain the files')
|
||||
@then(
|
||||
'cache directory "{dir_name}" should contain the files {expected_files_json_list}'
|
||||
)
|
||||
def assert_dir_contains_files(context, dir_name, expected_files_json_list="[]"):
|
||||
@then('cache "{dir_name}" should contain the files')
|
||||
@then('cache "{dir_name}" should contain the files {expected_files_json_list}')
|
||||
@then("the cache should contain the files")
|
||||
def assert_dir_contains_files(context, dir_name=None, expected_files_json_list=""):
|
||||
if not dir_name:
|
||||
dir_name = context.cache_dir
|
||||
|
||||
working_dir = os.path.join("features", "cache", dir_name)
|
||||
actual_files = os.listdir(working_dir)
|
||||
|
||||
expected_files = context.text or expected_files_json_list
|
||||
expected_files = json.loads(expected_files)
|
||||
expected_files = expected_files.split("\n")
|
||||
|
||||
# sort to deal with inconsistent default file ordering on different OS's
|
||||
actual_files.sort()
|
||||
|
@ -142,7 +153,11 @@ def assert_dir_contains_files(context, dir_name, expected_files_json_list="[]"):
|
|||
|
||||
|
||||
@then('the content of file "{file_path}" in cache directory "{cache_dir}" should be')
|
||||
def assert_exported_yaml_file_content(context, file_path, cache_dir):
|
||||
@then('the content of file "{file_path}" in the cache should be')
|
||||
def assert_exported_yaml_file_content(context, file_path, cache_dir=None):
|
||||
if not cache_dir:
|
||||
cache_dir = context.cache_dir
|
||||
|
||||
expected_content = context.text.strip().splitlines()
|
||||
full_file_path = os.path.join("features", "cache", cache_dir, file_path)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue