Use path strings instead of Path objects in return values to prevent side effects that caused unit tests to fail on some platforms

This commit is contained in:
Micah Jerome Ellison 2023-03-28 09:02:23 -07:00
parent 1a67c8c0ed
commit 0da0b7428f
4 changed files with 18 additions and 16 deletions

View file

@ -183,7 +183,7 @@ def mock_default_journal_path(temp_dir):
@fixture
def mock_default_templates_path(temp_dir):
templates_path = Path(temp_dir.name, "templates")
templates_path = os.path.join(temp_dir.name, "templates")
return {
"get_templates_path": lambda: patch(
"jrnl.editor.get_templates_path", return_value=templates_path

View file

@ -1,7 +1,7 @@
# Copyright © 2012-2023 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html
import pathlib
import os
from unittest.mock import mock_open
from unittest.mock import patch
@ -25,17 +25,15 @@ def test_read_template_file_with_valid_file_returns_text(mock_file):
def test_get_template_path_when_exists_returns_correct_path():
template_path = pathlib.Path("templatepath")
with patch("os.path.exists", return_value = True):
output = get_template_path("template", "templatepath")
with patch.object(pathlib.Path, "exists", lambda _: True):
output = get_template_path("template", template_path)
assert output == str(template_path / "template")
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.object(pathlib.Path, "exists", lambda _: False):
output = get_template_path("template", pathlib.Path("templatepath"))
with patch("os.path.exists", return_value = False):
output = get_template_path("template", "templatepath")
assert output == str(mock_absolute_paths.return_value)
assert output == mock_absolute_paths.return_value