Skip to content

Commit

Permalink
Repair test suite by mocking get_border_and_shadow_thickness to avo…
Browse files Browse the repository at this point in the history
…id calls to `GetWindowRect`
  • Loading branch information
Crozzers committed Jun 25, 2024
1 parent bf94800 commit e1d9355
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
__pyvda_utils = Path(importlib.util.find_spec('pyvda').origin).parent / 'utils.py'

sys.path.insert(0, str((Path(__file__).parent / '../').resolve()))
# allow internal imports like win32_extras
sys.path.insert(0, str((Path(__file__).parent / '../src').resolve()))
from src import common # noqa:E402


Expand Down
11 changes: 7 additions & 4 deletions test/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pathlib import Path
from unittest.mock import Mock, patch

from pytest_mock import MockerFixture
import win32gui
from test.conftest import DISPLAYS1, DISPLAYS2, RULES1, RULES2, WINDOWS1, WINDOWS2

Expand Down Expand Up @@ -210,16 +211,18 @@ def sample_json(self, window_json):
def sample_cls(self, window_cls):
return window_cls

def test_fits_display(self, klass: WindowType, sample_json, display_json, expected=None):
def test_fits_display(self, klass: WindowType, mocker: MockerFixture, sample_json, display_json, expected=None):
if expected is None:
expected = (sample_json in WINDOWS1 and display_json in DISPLAYS1) or (
sample_json in WINDOWS2 and display_json in DISPLAYS2
)
instance = klass.from_json(sample_json)
mocker.patch.object(instance, 'get_border_and_shadow_thickness', Mock(spec=True, return_value=8))
display_json = Display.from_json(display_json)
assert instance.fits_display(display_json) is expected

def test_fits_display_config(self, sample_cls: WindowType, displays: list[Display]):
def test_fits_display_config(self, sample_cls: WindowType, mocker: MockerFixture, displays: list[Display]):
mocker.patch.object(sample_cls, 'get_border_and_shadow_thickness', Mock(spec=True, return_value=8))
assert sample_cls.fits_display_config(displays) is True


Expand All @@ -243,11 +246,11 @@ def test_post_init(self, klass: Rule):
assert instance.name is not None
assert isinstance(instance.name, str)

def test_fits_display(self, klass: Rule, sample_json, display_json):
def test_fits_display(self, klass: Rule, mocker: MockerFixture, sample_json, display_json):
expected = (sample_json in RULES1 and display_json in DISPLAYS1) or (
sample_json in RULES2 and display_json in DISPLAYS2
)
return super().test_fits_display(klass, sample_json, display_json, expected)
return super().test_fits_display(klass, mocker, sample_json, display_json, expected)


class TestSnapshot(TestJSONType):
Expand Down

0 comments on commit e1d9355

Please sign in to comment.