Skip to content

Commit

Permalink
mah gawd, all da coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bandophahita committed Apr 5, 2024
1 parent 9a174d9 commit 45ba578
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_resolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
from itertools import chain
from typing import TYPE_CHECKING
from unittest import mock

import pytest
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 45ba578

Please sign in to comment.