Skip to content

Commit e1d9355

Browse files
committed
Repair test suite by mocking get_border_and_shadow_thickness to avoid calls to GetWindowRect
1 parent bf94800 commit e1d9355

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

test/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
__pyvda_utils = Path(importlib.util.find_spec('pyvda').origin).parent / 'utils.py'
2525

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

2931

test/test_common.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pathlib import Path
1010
from unittest.mock import Mock, patch
1111

12+
from pytest_mock import MockerFixture
1213
import win32gui
1314
from test.conftest import DISPLAYS1, DISPLAYS2, RULES1, RULES2, WINDOWS1, WINDOWS2
1415

@@ -210,16 +211,18 @@ def sample_json(self, window_json):
210211
def sample_cls(self, window_cls):
211212
return window_cls
212213

213-
def test_fits_display(self, klass: WindowType, sample_json, display_json, expected=None):
214+
def test_fits_display(self, klass: WindowType, mocker: MockerFixture, sample_json, display_json, expected=None):
214215
if expected is None:
215216
expected = (sample_json in WINDOWS1 and display_json in DISPLAYS1) or (
216217
sample_json in WINDOWS2 and display_json in DISPLAYS2
217218
)
218219
instance = klass.from_json(sample_json)
220+
mocker.patch.object(instance, 'get_border_and_shadow_thickness', Mock(spec=True, return_value=8))
219221
display_json = Display.from_json(display_json)
220222
assert instance.fits_display(display_json) is expected
221223

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

225228

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

246-
def test_fits_display(self, klass: Rule, sample_json, display_json):
249+
def test_fits_display(self, klass: Rule, mocker: MockerFixture, sample_json, display_json):
247250
expected = (sample_json in RULES1 and display_json in DISPLAYS1) or (
248251
sample_json in RULES2 and display_json in DISPLAYS2
249252
)
250-
return super().test_fits_display(klass, sample_json, display_json, expected)
253+
return super().test_fits_display(klass, mocker, sample_json, display_json, expected)
251254

252255

253256
class TestSnapshot(TestJSONType):

0 commit comments

Comments
 (0)