From 45ba578d2c676b08f5448f56e99240ac4f50189b Mon Sep 17 00:00:00 2001 From: Marcel Wilson Date: Fri, 5 Apr 2024 14:20:09 -0400 Subject: [PATCH] mah gawd, all da coverage --- tests/test_resolutions.py | 31 +++++++++++++++++++++++++++++++ tests/test_settings.py | 19 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/tests/test_resolutions.py b/tests/test_resolutions.py index c0123a7..1e022da 100644 --- a/tests/test_resolutions.py +++ b/tests/test_resolutions.py @@ -2,6 +2,7 @@ import logging from itertools import chain +from typing import TYPE_CHECKING from unittest import mock import pytest @@ -36,6 +37,9 @@ from screenpy.resolutions.base_resolution import BaseMatcher from screenpy.speech_tools import get_additive_description +if TYPE_CHECKING: + from pytest_mock import MockerFixture + class TestBaseResolution: def test_subclasses_deprecated(self) -> None: @@ -121,6 +125,33 @@ class MockResolution(BaseResolution): resolution.get_line.assert_called_once() + @pytest.mark.filterwarnings("ignore:BaseResolution") + def test_describe(self, mocker: MockerFixture) -> None: + class MockResolution(BaseResolution): + """Must be defined here for new mock matchers.""" + + matcher_function = mock.create_autospec(BaseMatcher) + + resolution = MockResolution() + mock_get_line = mocker.patch.object(resolution, "get_line") + mock_str = mocker.create_autospec(str) + mock_get_line.return_value = mock_str + resolution.describe() + + mock_get_line.assert_called_once() + mock_str.capitalize.assert_called_once() + + @pytest.mark.filterwarnings("ignore:BaseResolution") + def test_resolve(self) -> None: + class MockResolution(BaseResolution): + """Must be defined here for new mock matchers.""" + + matcher_function = mock.create_autospec(BaseMatcher) + + resolution = MockResolution() + rt = resolution.resolve() + assert rt is resolution + class TestContainsItemMatching: def test_can_be_instantiated(self) -> None: diff --git a/tests/test_settings.py b/tests/test_settings.py index 4b224d6..d7504e0 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -42,6 +42,25 @@ def test__parse_pyproject_toml_file_exists(self, MockedPath: mock.Mock) -> None: "stdoutadapter": {"INDENT_SIZE": 500}, } + @mock.patch("screenpy.configuration.Path", autospec=True) + def test__parse_pyproject_toml_no_tool_path(self, MockedPath: mock.Mock) -> None: + MockedPath.cwd.return_value.__truediv__.return_value = MockedPath + MockedPath.is_file.return_value = True + test_data = ( + b"[tool.screenpy]\nTIMEOUT = 500" + b"\n\n[tool.screenpy.stdoutadapter]\nINDENT_SIZE = 500" + ) + mock_open = mock.mock_open(read_data=test_data) + MockedPath.open.side_effect = mock_open.side_effect + MockedPath.open.return_value = mock_open.return_value + + with mock.patch("screenpy.configuration.hasattr") as mockhasattr: + mockhasattr.return_value = False + pyproject_config = PyprojectTomlConfig(ScreenPySettings) + pyproject_config._parse_pyproject_toml() + + assert pyproject_config.toml_config == {} + class TestSettings: def test_pyproject_overwrites_initial(self) -> None: