first attempt with strudel

This commit is contained in:
shai 2024-03-07 17:30:47 +02:00
parent 2af05e4008
commit 2a0496f03c
42 changed files with 186 additions and 86 deletions

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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