mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 08:38:32 +02:00
* update pytest-bdd to 6.0 * update lock file * fix first test (inject command fixture to request) * fix some more tests * fix cli_run fixture * fix password fixture * Remove unused import * Fix greedy should_or_should_not parsing problems while also consolidating its parse/transformation-to-bool code * Prevent greedy matching in "we run" by using regular expression lookahead * Add missing "Outline" in scenario outlines with examples * Split "we use the config" and "we use no config" so pytest won't try to consume config_file as a fixture * Fix missing ShouldOrShouldNot * Formatting * fix get_fixture function * change output of failing test to be a little more useful * update lock file * update type builder to for should/should not to be in it's own file, rename some vars for readability * add parse-type new dev/testing dependency * update lock file --------- Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
76 lines
1.9 KiB
Python
76 lines
1.9 KiB
Python
# Copyright © 2012-2023 jrnl contributors
|
|
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
import functools
|
|
import os
|
|
|
|
|
|
def does_directory_contain_files(file_list, directory_path):
|
|
if not os.path.isdir(directory_path):
|
|
return False
|
|
|
|
for file in file_list.split("\n"):
|
|
fullpath = directory_path + "/" + file
|
|
if not os.path.isfile(fullpath):
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
def does_directory_contain_n_files(directory_path, number):
|
|
count = 0
|
|
if not os.path.isdir(directory_path):
|
|
return False
|
|
|
|
files = [
|
|
f
|
|
for f in os.listdir(directory_path)
|
|
if os.path.isfile(os.path.join(directory_path, f))
|
|
]
|
|
count = len(files)
|
|
|
|
return int(number) == count
|
|
|
|
|
|
def assert_equal_tags_ignoring_order(
|
|
actual_line, expected_line, actual_content, expected_content
|
|
):
|
|
actual_tags = set(tag.strip() for tag in actual_line[len("tags: ") :].split(","))
|
|
expected_tags = set(
|
|
tag.strip() for tag in expected_line[len("tags: ") :].split(",")
|
|
)
|
|
assert actual_tags == expected_tags, [
|
|
[actual_tags, expected_tags],
|
|
[expected_content, actual_content],
|
|
]
|
|
|
|
|
|
# @see: https://stackoverflow.com/a/65782539/569146
|
|
def get_nested_val(dictionary, path, *default):
|
|
try:
|
|
return functools.reduce(lambda x, y: x[y], path.split("."), dictionary)
|
|
except KeyError:
|
|
if default:
|
|
return default[0]
|
|
raise
|
|
|
|
|
|
# @see: https://stackoverflow.com/a/41599695/569146
|
|
def spy_wrapper(wrapped_function):
|
|
from unittest import mock
|
|
|
|
mock = mock.MagicMock()
|
|
|
|
def wrapper(self, *args, **kwargs):
|
|
mock(*args, **kwargs)
|
|
return wrapped_function(self, *args, **kwargs)
|
|
|
|
wrapper.mock = mock
|
|
return wrapper
|
|
|
|
|
|
def get_fixture(request, name, default=None):
|
|
try:
|
|
return request.getfixturevalue(name)
|
|
except LookupError:
|
|
return default
|