Debian Codegraph @

tests/test_wx_measure_frame.py

raw
1 import pytest
2 import wx
3 from _pytest.fixtures import SubRequest
4
5 from DisplayCAL import real_display_size_mm
6 from DisplayCAL.dev.mocks import check_call, check_call_str
7 from DisplayCAL.wx_measure_frame import get_default_size
8 from tests.data.display_data import DisplayData
9
10
11 @pytest.fixture(
12 scope="session", name="size_in_mm", params=["size_available", "size_unavailable"]
13 )
14 def fixture_size_in_mm(request: SubRequest) -> tuple[int, int]:
15 """Return display size in mm (width, height)."""
16 return (
17 DisplayData.DISPLAY_DATA_1["size"]
18 if request.param == "size_available"
19 else (0, 0)
20 )
21
22
23 @pytest.mark.parametrize(
24 "real_display",
25 (True, False),
26 ids=("with_real_display_size_mm", "without_real_display_size_mm"),
27 )
28 def test_get_default_size_1(real_display: bool, size_in_mm: tuple[int, int]) -> None:
29 """Testing wx_measure_frame.get_default_size() function."""
30 with check_call_str("DisplayCAL.wx_measure_frame.getcfg", DisplayData.CFG_DATA):
31 with check_call_str(
32 "DisplayCAL.wx_measure_frame.get_display_number",
33 DisplayData.DISPLAY_DATA_1["screen"],
34 ):
35 with check_call(wx, "Display", DisplayData()):
36 if real_display:
37 with check_call(
38 real_display_size_mm,
39 "real_display_size_mm",
40 DisplayData.DISPLAY_DATA_1["size"],
41 ):
42 result = get_default_size()
43 else:
44 with check_call(
45 wx, "DisplaySize", DisplayData.DISPLAY_DATA_1["size"]
46 ):
47 with check_call(wx, "DisplaySizeMM", size_in_mm):
48 result = get_default_size()
49 assert isinstance(result, int)
50 assert result > 1
51
52
53 @pytest.mark.skip(
54 reason="TODO: This test is moved from the module, properly implement it."
55 )
56 def test_from_module():
57 import time
58
59 for rgb in [
60 (0.079291, 1 / 51.0, 1 / 51.0),
61 (0.079291, 0.089572, 0.094845),
62 (0.032927, 0.028376, 0.027248),
63 (0.037647, 0.037095, 0.036181),
64 (51.2 / 255, 153.7 / 255, 127.4 / 255),
65 ]:
66 wx.CallAfter(wx.GetApp().TopWindow.show_rgb, rgb)
67 time.sleep(0.05)
68 input("Press RETURN to continue\n")
69 if not wx.GetApp().TopWindow:
70 break
71
72 # This is the caller of the test function... implement it properly later on.
73 import threading
74
75 t = threading.Thread(target=test)
76 app.TopWindow.show_controls(False)
77 t.start()
78