mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-07-02 06:56:12 +02:00
first attempt with strudel
This commit is contained in:
parent
2af05e4008
commit
2a0496f03c
42 changed files with 186 additions and 86 deletions
|
@ -23,4 +23,4 @@ scenarios("features/star.feature")
|
|||
scenarios("features/tag.feature")
|
||||
scenarios("features/template.feature")
|
||||
scenarios("features/upgrade.feature")
|
||||
scenarios("features/write.feature")
|
||||
scenarios("features/write.feature")
|
|
@ -18,14 +18,18 @@ pytest_plugins = [
|
|||
def pytest_bdd_apply_tag(tag, function):
|
||||
# skip markers
|
||||
if tag == "skip_win":
|
||||
logger.info(f'Condition in body log is: tag({tag}) = "skip_win"') # STRUDEL_LOG ured
|
||||
marker = mark.skipif(on_windows(), reason="Skip test on Windows")
|
||||
elif tag == "skip_posix":
|
||||
logger.info(f'Condition in body log is: tag({tag}) = "skip_posix"') # STRUDEL_LOG ddbs
|
||||
marker = mark.skipif(on_posix(), reason="Skip test on Mac/Linux")
|
||||
|
||||
# only on OS markers
|
||||
elif tag == "on_win":
|
||||
logger.info(f'Condition in body log is: tag({tag}) = "on_win"') # STRUDEL_LOG zjqp
|
||||
marker = mark.skipif(not on_windows(), reason="Skip test not on Windows")
|
||||
elif tag == "on_posix":
|
||||
logger.info(f'Condition in body log is: tag({tag}) = "on_posix"') # STRUDEL_LOG zgja
|
||||
marker = mark.skipif(not on_posix(), reason="Skip test not on Mac/Linux")
|
||||
else:
|
||||
# Fall back to pytest-bdd's default behavior
|
||||
|
@ -42,13 +46,17 @@ def pytest_runtest_setup(item):
|
|||
on_nix = on_posix()
|
||||
|
||||
if "skip_win" in markers and on_win:
|
||||
logger.info(f'Condition in body log is: "skip_win" in markers BoolOp on_win') # STRUDEL_LOG iabq
|
||||
skip("Skip test on Windows")
|
||||
|
||||
if "skip_posix" in markers and on_nix:
|
||||
logger.info(f'Condition in body log is: "skip_posix" in markers BoolOp on_nix') # STRUDEL_LOG asee
|
||||
skip("Skip test on Mac/Linux")
|
||||
|
||||
if "on_win" in markers and not on_win:
|
||||
logger.info(f'Condition in body log is: "on_win" in markers BoolOp (not on_win) is True') # STRUDEL_LOG gknf
|
||||
skip("Skip test not on Windows")
|
||||
|
||||
if "on_posix" in markers and not on_nix:
|
||||
skip("Skip test not on Mac/Linux")
|
||||
logger.info(f'Condition in body log is: "on_posix" in markers BoolOp (not on_nix) is True') # STRUDEL_LOG ojpo
|
||||
skip("Skip test not on Mac/Linux")
|
|
@ -7,11 +7,13 @@ import os
|
|||
|
||||
def does_directory_contain_files(file_list, directory_path):
|
||||
if not os.path.isdir(directory_path):
|
||||
logger.info(f'Condition in body log is: UnaryOp os.path.isdir( directory_path)') # STRUDEL_LOG iyeb
|
||||
return False
|
||||
|
||||
for file in file_list.split("\n"):
|
||||
fullpath = directory_path + "/" + file
|
||||
if not os.path.isfile(fullpath):
|
||||
logger.info(f'Condition in body log is: UnaryOp os.path.isfile( fullpath)') # STRUDEL_LOG iemx
|
||||
return False
|
||||
|
||||
return True
|
||||
|
@ -20,6 +22,7 @@ def does_directory_contain_files(file_list, directory_path):
|
|||
def does_directory_contain_n_files(directory_path, number):
|
||||
count = 0
|
||||
if not os.path.isdir(directory_path):
|
||||
logger.info(f'Condition in body log is: UnaryOp os.path.isdir( directory_path)') # STRUDEL_LOG ykwn
|
||||
return False
|
||||
|
||||
files = [
|
||||
|
@ -51,6 +54,7 @@ def get_nested_val(dictionary, path, *default):
|
|||
return functools.reduce(lambda x, y: x[y], path.split("."), dictionary)
|
||||
except KeyError:
|
||||
if default:
|
||||
logger.info(f'Condition in body log is: default') # STRUDEL_LOG ltbz
|
||||
return default[0]
|
||||
raise
|
||||
|
||||
|
@ -73,4 +77,4 @@ def get_fixture(request, name, default=None):
|
|||
try:
|
||||
return request.getfixturevalue(name)
|
||||
except LookupError:
|
||||
return default
|
||||
return default
|
|
@ -61,14 +61,17 @@ def output_should_contain(expected, which_output_stream, cli_run, it_should):
|
|||
|
||||
assert expected
|
||||
if which_output_stream is None:
|
||||
logger.info(f'Condition in body log is: which_output_stream({which_output_stream}) Is None') # STRUDEL_LOG ivav
|
||||
assert ((expected in cli_run["stdout"]) == it_should) or (
|
||||
(expected in cli_run["stderr"]) == it_should
|
||||
), output_str
|
||||
|
||||
elif which_output_stream == "standard":
|
||||
logger.info(f'Condition in body log is: which_output_stream({which_output_stream}) = "standard"') # STRUDEL_LOG zlhq
|
||||
assert (expected in cli_run["stdout"]) == it_should, output_str
|
||||
|
||||
elif which_output_stream == "error":
|
||||
logger.info(f'Condition in body log is: which_output_stream({which_output_stream}) = "error"') # STRUDEL_LOG qlkb
|
||||
assert (expected in cli_run["stderr"]) == it_should, output_str
|
||||
|
||||
else:
|
||||
|
@ -156,12 +159,14 @@ def default_journal_location(journal_file, journal_dir, config_on_disk, temp_dir
|
|||
def config_var_on_disk(config_on_disk, journal_name, it_should, some_yaml):
|
||||
actual = config_on_disk
|
||||
if journal_name:
|
||||
logger.info(f'Condition in body log is: journal_name') # STRUDEL_LOG etsi
|
||||
actual = actual["journals"][journal_name]
|
||||
|
||||
expected = YAML(typ="safe").load(some_yaml)
|
||||
|
||||
actual_slice = actual
|
||||
if isinstance(actual, dict):
|
||||
logger.info(f'Condition in body log is: actual is type: dict') # STRUDEL_LOG dqjv
|
||||
# `expected` objects formatted in yaml only compare one level deep
|
||||
actual_slice = {key: actual.get(key) for key in expected.keys()}
|
||||
|
||||
|
@ -191,12 +196,14 @@ def config_var_on_disk(config_on_disk, journal_name, it_should, some_yaml):
|
|||
def config_var_in_memory(config_in_memory, journal_name, it_should, some_yaml):
|
||||
actual = config_in_memory["overrides"]
|
||||
if journal_name:
|
||||
logger.info(f'Condition in body log is: journal_name') # STRUDEL_LOG ulkm
|
||||
actual = actual["journals"][journal_name]
|
||||
|
||||
expected = YAML(typ="safe").load(some_yaml)
|
||||
|
||||
actual_slice = actual
|
||||
if isinstance(actual, dict):
|
||||
logger.info(f'Condition in body log is: actual is type: dict') # STRUDEL_LOG rnbf
|
||||
# `expected` objects formatted in yaml only compare one level deep
|
||||
actual_slice = {key: get_nested_val(actual, key) for key in expected.keys()}
|
||||
|
||||
|
@ -272,6 +279,7 @@ def content_of_file_should_be(file_path, file_content, cache_dir):
|
|||
|
||||
for actual_line, expected_line in zip(actual_content, expected_content):
|
||||
if actual_line.startswith("tags: ") and expected_line.startswith("tags: "):
|
||||
logger.info(f'Condition in body log is: actual_line.startswith( "tags: ") BoolOp expected_line.startswith( "tags: ")') # STRUDEL_LOG mcja
|
||||
assert_equal_tags_ignoring_order(
|
||||
actual_line, expected_line, actual_content, expected_content
|
||||
)
|
||||
|
@ -300,9 +308,11 @@ def cache_dir_contains_files(file_list, cache_dir):
|
|||
def assert_output_is_valid_language(cli_run, language_name):
|
||||
language_name = language_name.upper()
|
||||
if language_name == "XML":
|
||||
logger.info(f'Condition in body log is: language_name({language_name}) = "XML"') # STRUDEL_LOG dxkz
|
||||
xml_tree = ElementTree.fromstring(cli_run["stdout"])
|
||||
assert xml_tree, "Invalid XML"
|
||||
elif language_name == "JSON":
|
||||
logger.info(f'Condition in body log is: language_name({language_name}) = "JSON"') # STRUDEL_LOG boxr
|
||||
assert json.loads(cli_run["stdout"]), "Invalid JSON"
|
||||
else:
|
||||
assert False, f"Language name {language_name} not recognized"
|
||||
|
@ -314,6 +324,7 @@ def assert_parsed_output_item_count(node_name, number, parsed_output):
|
|||
obj = parsed_output["obj"]
|
||||
|
||||
if lang == "XML":
|
||||
logger.info(f'Condition in body log is: lang({lang}) = "XML"') # STRUDEL_LOG erlc
|
||||
xml_node_names = (node.tag for node in obj)
|
||||
assert node_name in xml_node_names, str(list(xml_node_names))
|
||||
|
||||
|
@ -321,6 +332,7 @@ def assert_parsed_output_item_count(node_name, number, parsed_output):
|
|||
assert actual_entry_count == number, actual_entry_count
|
||||
|
||||
elif lang == "JSON":
|
||||
logger.info(f'Condition in body log is: lang({lang}) = "JSON"') # STRUDEL_LOG vtrh
|
||||
my_obj = obj
|
||||
|
||||
for node in node_name.split("."):
|
||||
|
@ -342,13 +354,16 @@ def assert_output_field_content(field_name, comparison, expected_keys, parsed_ou
|
|||
obj = parsed_output["obj"]
|
||||
expected_keys = expected_keys.split("\n")
|
||||
if len(expected_keys) == 1:
|
||||
logger.info(f'Condition in body log is: len( expected_keys) = 1') # STRUDEL_LOG jtiw
|
||||
expected_keys = expected_keys[0]
|
||||
|
||||
if lang == "XML":
|
||||
logger.info(f'Condition in body log is: lang({lang}) = "XML"') # STRUDEL_LOG sjoz
|
||||
xml_node_names = (node.tag for node in obj)
|
||||
assert field_name in xml_node_names, str(list(xml_node_names))
|
||||
|
||||
if field_name == "tags":
|
||||
logger.info(f'Condition in body log is: field_name({field_name}) = "tags"') # STRUDEL_LOG ocyv
|
||||
actual_tags = set(t.attrib["name"] for t in obj.find("tags"))
|
||||
assert set(actual_tags) == set(expected_keys), [
|
||||
actual_tags,
|
||||
|
@ -358,6 +373,7 @@ def assert_output_field_content(field_name, comparison, expected_keys, parsed_ou
|
|||
assert False, "This test only works for tags in XML"
|
||||
|
||||
elif lang == "JSON":
|
||||
logger.info(f'Condition in body log is: lang({lang}) = "JSON"') # STRUDEL_LOG encw
|
||||
my_obj = obj
|
||||
|
||||
for node in field_name.split("."):
|
||||
|
@ -368,7 +384,9 @@ def assert_output_field_content(field_name, comparison, expected_keys, parsed_ou
|
|||
my_obj = my_obj[node]
|
||||
|
||||
if comparison == "be":
|
||||
logger.info(f'Condition in body log is: comparison({comparison}) = "be"') # STRUDEL_LOG nciy
|
||||
if isinstance(my_obj, str):
|
||||
logger.info(f'Condition in body log is: my_obj is type: str') # STRUDEL_LOG axdm
|
||||
assert expected_keys == my_obj, [my_obj, expected_keys]
|
||||
else:
|
||||
assert set(expected_keys) == set(my_obj), [
|
||||
|
@ -376,7 +394,9 @@ def assert_output_field_content(field_name, comparison, expected_keys, parsed_ou
|
|||
set(expected_keys),
|
||||
]
|
||||
elif comparison == "contain":
|
||||
logger.info(f'Condition in body log is: comparison({comparison}) = "contain"') # STRUDEL_LOG fmfm
|
||||
if isinstance(my_obj, str):
|
||||
logger.info(f'Condition in body log is: my_obj is type: str') # STRUDEL_LOG qtfe
|
||||
assert expected_keys in my_obj, [my_obj, expected_keys]
|
||||
else:
|
||||
assert all(elem in my_obj for elem in expected_keys), [
|
||||
|
@ -405,6 +425,7 @@ def count_editor_args(num_args, cli_run, editor_state, it_should):
|
|||
assert cli_run["mocks"]["editor"].called == it_should
|
||||
|
||||
if isinstance(num_args, int):
|
||||
logger.info(f'Condition in body log is: num_args is type: int') # STRUDEL_LOG mthy
|
||||
assert len(editor_state["command"]) == int(num_args)
|
||||
|
||||
|
||||
|
@ -427,8 +448,10 @@ def contains_editor_file(comparison, str_value, editor_state):
|
|||
content = editor_state["tmpfile"]["content"]
|
||||
# content = f'\n"""\n{content}\n"""\n'
|
||||
if comparison == "be":
|
||||
logger.info(f'Condition in body log is: comparison({comparison}) = "be"') # STRUDEL_LOG hrup
|
||||
assert content == str_value
|
||||
elif comparison == "contain":
|
||||
logger.info(f'Condition in body log is: comparison({comparison}) = "contain"') # STRUDEL_LOG ytoz
|
||||
assert str_value in content
|
||||
else:
|
||||
assert False, f"Comparison '{comparison}' not supported"
|
||||
assert False, f"Comparison '{comparison}' not supported"
|
|
@ -8,4 +8,4 @@ should_choice = TypeBuilder.make_enum(
|
|||
"should": True,
|
||||
"should not": False,
|
||||
}
|
||||
)
|
||||
)
|
|
@ -15,6 +15,7 @@ from jrnl.main import run
|
|||
@when(parse('we change directory to "{directory_name}"'))
|
||||
def when_we_change_directory(directory_name):
|
||||
if not os.path.isdir(directory_name):
|
||||
logger.info(f'Condition in body log is: UnaryOp os.path.isdir( directory_name)') # STRUDEL_LOG ahcx
|
||||
os.mkdir(directory_name)
|
||||
|
||||
os.chdir(directory_name)
|
||||
|
@ -62,4 +63,4 @@ def we_run_jrnl(capsys, keyring, request, command, input_method, all_input):
|
|||
captured = capsys.readouterr()
|
||||
|
||||
cli_run["stdout"] = captured.out
|
||||
cli_run["stderr"] = captured.err
|
||||
cli_run["stderr"] = captured.err
|
|
@ -18,4 +18,4 @@ def test_colorize(data_fixture):
|
|||
string = data_fixture
|
||||
colorized_string = colorize(string, "BLUE", True)
|
||||
|
||||
assert colorized_string == Style.BRIGHT + Fore.BLUE + string + Style.RESET_ALL
|
||||
assert colorized_string == Style.BRIGHT + Fore.BLUE + string + Style.RESET_ALL
|
|
@ -24,4 +24,4 @@ def test_find_alt_config_not_exist(request):
|
|||
with pytest.raises(JrnlException) as ex:
|
||||
found_alt_config = find_alt_config(bad_config_path)
|
||||
assert found_alt_config is not None
|
||||
assert isinstance(ex.value, JrnlException)
|
||||
assert isinstance(ex.value, JrnlException)
|
|
@ -52,4 +52,4 @@ def test_display_search_results_builtin_plugins(
|
|||
|
||||
mock_exporter.assert_called_once_with(export_format)
|
||||
mock_export.assert_called_once_with(test_journal, test_filename)
|
||||
mock_print.assert_called_once_with(mock_export.return_value)
|
||||
mock_print.assert_called_once_with(mock_export.return_value)
|
|
@ -1,45 +1,45 @@
|
|||
# Copyright © 2012-2023 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
import os
|
||||
from unittest.mock import mock_open
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from jrnl.editor import get_template_path
|
||||
from jrnl.editor import read_template_file
|
||||
from jrnl.exception import JrnlException
|
||||
|
||||
|
||||
@patch(
|
||||
"os.getcwd", side_effect="/"
|
||||
) # prevent failures in CI if current directory has been deleted
|
||||
@patch("builtins.open", side_effect=FileNotFoundError())
|
||||
def test_read_template_file_with_no_file_raises_exception(mock_open, mock_getcwd):
|
||||
with pytest.raises(JrnlException) as ex:
|
||||
read_template_file("invalid_file.txt")
|
||||
assert isinstance(ex.value, JrnlException)
|
||||
|
||||
|
||||
@patch(
|
||||
"os.getcwd", side_effect="/"
|
||||
) # prevent failures in CI if current directory has been deleted
|
||||
@patch("builtins.open", new_callable=mock_open, read_data="template text")
|
||||
def test_read_template_file_with_valid_file_returns_text(mock_file, mock_getcwd):
|
||||
assert read_template_file("valid_file.txt") == "template text"
|
||||
|
||||
|
||||
def test_get_template_path_when_exists_returns_correct_path():
|
||||
with patch("os.path.exists", return_value=True):
|
||||
output = get_template_path("template", "templatepath")
|
||||
|
||||
assert output == os.path.join("templatepath", "template")
|
||||
|
||||
|
||||
@patch("jrnl.editor.absolute_path")
|
||||
def test_get_template_path_when_doesnt_exist_returns_correct_path(mock_absolute_paths):
|
||||
with patch("os.path.exists", return_value=False):
|
||||
output = get_template_path("template", "templatepath")
|
||||
|
||||
assert output == mock_absolute_paths.return_value
|
||||
# Copyright © 2012-2023 jrnl contributors
|
||||
# License: https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
import os
|
||||
from unittest.mock import mock_open
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from jrnl.editor import get_template_path
|
||||
from jrnl.editor import read_template_file
|
||||
from jrnl.exception import JrnlException
|
||||
|
||||
|
||||
@patch(
|
||||
"os.getcwd", side_effect="/"
|
||||
) # prevent failures in CI if current directory has been deleted
|
||||
@patch("builtins.open", side_effect=FileNotFoundError())
|
||||
def test_read_template_file_with_no_file_raises_exception(mock_open, mock_getcwd):
|
||||
with pytest.raises(JrnlException) as ex:
|
||||
read_template_file("invalid_file.txt")
|
||||
assert isinstance(ex.value, JrnlException)
|
||||
|
||||
|
||||
@patch(
|
||||
"os.getcwd", side_effect="/"
|
||||
) # prevent failures in CI if current directory has been deleted
|
||||
@patch("builtins.open", new_callable=mock_open, read_data="template text")
|
||||
def test_read_template_file_with_valid_file_returns_text(mock_file, mock_getcwd):
|
||||
assert read_template_file("valid_file.txt") == "template text"
|
||||
|
||||
|
||||
def test_get_template_path_when_exists_returns_correct_path():
|
||||
with patch("os.path.exists", return_value=True):
|
||||
output = get_template_path("template", "templatepath")
|
||||
|
||||
assert output == os.path.join("templatepath", "template")
|
||||
|
||||
|
||||
@patch("jrnl.editor.absolute_path")
|
||||
def test_get_template_path_when_doesnt_exist_returns_correct_path(mock_absolute_paths):
|
||||
with patch("os.path.exists", return_value=False):
|
||||
output = get_template_path("template", "templatepath")
|
||||
|
||||
assert output == mock_absolute_paths.return_value
|
|
@ -44,4 +44,4 @@ class TestYaml:
|
|||
)
|
||||
with pytest.raises(JrnlException):
|
||||
YAMLExporter.write_file("journal", "non-existing-path")
|
||||
mock_open.assert_not_called()
|
||||
mock_open.assert_not_called()
|
|
@ -14,4 +14,4 @@ def test_initialize_autocomplete_runs_without_readline():
|
|||
from jrnl import install
|
||||
|
||||
with mock.patch.dict(sys.modules, {"readline": None}):
|
||||
install._initialize_autocomplete() # should not throw exception
|
||||
install._initialize_autocomplete() # should not throw exception
|
|
@ -88,4 +88,4 @@ def test_split_args_on_windows(args):
|
|||
def test_split_args_on_not_windows(args):
|
||||
input_arguments, expected_split_args = args[0], args[1]
|
||||
with mock.patch("jrnl.os_compat.on_windows", lambda: True):
|
||||
assert split_args(input_arguments) == expected_split_args
|
||||
assert split_args(input_arguments) == expected_split_args
|
|
@ -25,4 +25,4 @@ def test_print_msg_calls_print_msgs_with_kwargs(print_msgs):
|
|||
"some_rando_arg": "💩",
|
||||
}
|
||||
print_msg(test_msg, **kwargs)
|
||||
print_msgs.assert_called_once_with([test_msg], style=test_msg.style, **kwargs)
|
||||
print_msgs.assert_called_once_with([test_msg], style=test_msg.style, **kwargs)
|
|
@ -108,4 +108,4 @@ class TestDotNotationToList:
|
|||
def test_sequential_delimiters(self):
|
||||
k = "g.r..h.v"
|
||||
k_l = _convert_dots_to_list(k)
|
||||
assert len(k_l) == 4
|
||||
assert len(k_l) == 4
|
|
@ -311,4 +311,4 @@ class TestDeserialization:
|
|||
assert cfg["editor"] == "vi -c startinsert"
|
||||
|
||||
cfg = make_yaml_valid_dict(["highlight", "true"])
|
||||
assert cfg["highlight"] is True
|
||||
assert cfg["highlight"] is True
|
|
@ -103,4 +103,4 @@ def test_absolute_path(mock_abspath, mock_expand_path):
|
|||
|
||||
assert absolute_path(test_val) == mock_abspath.return_value
|
||||
mock_expand_path.assert_called_with(test_val)
|
||||
mock_abspath.assert_called_with(mock_expand_path.return_value)
|
||||
mock_abspath.assert_called_with(mock_expand_path.return_value)
|
|
@ -41,4 +41,4 @@ def test_default_minute_is_added():
|
|||
)
|
||||
def test_is_valid_date(inputs):
|
||||
year, month, day, expected_result = inputs
|
||||
assert time.is_valid_date(year, month, day) == expected_result
|
||||
assert time.is_valid_date(year, month, day) == expected_result
|
Loading…
Add table
Add a link
Reference in a new issue