1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-15 01:24:29 +02:00

Add unit tests for xrandr --properties outputs

This commit is contained in:
Jake Ob
2023-02-17 16:25:41 +02:00
parent 98ced9616c
commit 6ea2d776ae
2 changed files with 202 additions and 0 deletions

View File

@ -0,0 +1,110 @@
Screen 0: minimum 320 x 200, current 2806 x 900, maximum 8192 x 8192
LVDS-1 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 344mm x 194mm
EDID:
00ffffffffffff004ca3523100000000
0014010380221378eac8959e57549226
0f505400000001010101010101010101
010101010101381d56d4500016303020
250058c2100000190000000f00000000
000000000025d9066a00000000fe0053
414d53554e470a204ca34154000000fe
004c544e313536415432343430310018
scaling mode: Full aspect
supported: Full, Center, Full aspect
link-status: Good
supported: Good, Bad
CONNECTOR_ID: 61
supported: 61
non-desktop: 0
range: (0, 1)
1366x768 60.00*+
1280x720 60.00 59.99 59.86 59.74
1024x768 60.04 60.00
960x720 60.00
928x696 60.05
896x672 60.01
1024x576 59.95 59.96 59.90 59.82
960x600 59.93 60.00
960x540 59.96 59.99 59.63 59.82
800x600 60.00 60.32 56.25
840x525 60.01 59.88
864x486 59.92 59.57
700x525 59.98
800x450 59.95 59.82
640x512 60.02
700x450 59.96 59.88
640x480 60.00 59.94
720x405 59.51 58.99
684x384 59.88 59.85
640x400 59.88 59.98
640x360 59.86 59.83 59.84 59.32
512x384 60.00
512x288 60.00 59.92
480x270 59.63 59.82
400x300 60.32 56.34
432x243 59.92 59.57
320x240 60.05
360x202 59.51 59.13
320x180 59.84 59.32
VGA-1 connected 1440x900+1366+0 (normal left inverted right x axis y axis) 408mm x 255mm
EDID:
00ffffffffffff000469d41901010101
2011010308291a78ea8585a6574a9c26
125054bfef80714f8100810f81408180
9500950f01019a29a0d0518422305098
360098ff1000001c000000fd00374b1e
530f000a202020202020000000fc0041
535553205657313933530a20000000ff
0037384c383032313130370a20200077
link-status: Good
supported: Good, Bad
CONNECTOR_ID: 64
supported: 64
non-desktop: 0
range: (0, 1)
1440x900 59.89*+ 74.98
1280x1024 75.02 60.02
1280x960 60.00
1280x800 74.93 59.81
1152x864 75.00
1024x768 75.03 70.07 60.00
832x624 74.55
800x600 72.19 75.00 60.32 56.25
640x480 75.00 72.81 66.67 59.94
720x400 70.08
HDMI-1 disconnected (normal left inverted right x axis y axis)
max bpc: 12
range: (8, 12)
content type: No Data
supported: No Data, Graphics, Photo, Cinema, Game
Colorspace: Default
supported: Default, SMPTE_170M_YCC, BT709_YCC, XVYCC_601, XVYCC_709, SYCC_601, opYCC_601, opRGB, BT2020_CYCC, BT2020_RGB, BT2020_YCC, DCI-P3_RGB_D65, DCI-P3_RGB_Theater
aspect ratio: Automatic
supported: Automatic, 4:3, 16:9
Broadcast RGB: Automatic
supported: Automatic, Full, Limited 16:235
audio: auto
supported: force-dvi, off, auto, on
link-status: Good
supported: Good, Bad
CONNECTOR_ID: 68
supported: 68
non-desktop: 0
range: (0, 1)
DP-1 disconnected (normal left inverted right x axis y axis)
Colorspace: Default
supported: Default, RGB_Wide_Gamut_Fixed_Point, RGB_Wide_Gamut_Floating_Point, opRGB, DCI-P3_RGB_D65, BT2020_RGB, BT601_YCC, BT709_YCC, XVYCC_601, XVYCC_709, SYCC_601, opYCC_601, BT2020_CYCC, BT2020_YCC
max bpc: 12
range: (6, 12)
Broadcast RGB: Automatic
supported: Automatic, Full, Limited 16:235
audio: auto
supported: force-dvi, off, auto, on
subconnector: Unknown
supported: Unknown, VGA, DVI-D, HDMI, DP, Wireless, Native
link-status: Good
supported: Good, Bad
CONNECTOR_ID: 76
supported: 76
non-desktop: 0
range: (0, 1)

View File

@ -7,12 +7,16 @@ from jc.parsers.xrandr import (
_parse_screen,
_parse_device,
_parse_mode,
_parse_model,
_device_pattern,
_screen_pattern,
_mode_pattern,
_frequencies_pattern,
_edid_head_pattern,
_edid_line_pattern,
parse,
Mode,
Model,
Device,
Screen,
)
@ -60,6 +64,27 @@ class XrandrTests(unittest.TestCase):
rest = match.groupdict()["rest"]
self.assertIsNotNone(re.match(_frequencies_pattern, rest))
edid_lines = [
" EDID: ",
" 00ffffffffffff000469d41901010101 ",
" 2011010308291a78ea8585a6574a9c26 ",
" 125054bfef80714f8100810f81408180 ",
" 9500950f01019a29a0d0518422305098 ",
" 360098ff1000001c000000fd00374b1e ",
" 530f000a202020202020000000fc0041 ",
" 535553205657313933530a20000000ff ",
" 0037384c383032313130370a20200077 "
]
for i in range(len(edid_lines)):
line = edid_lines[i]
if i == 0:
match = re.match(_edid_head_pattern, line)
else:
match = re.match(_edid_line_pattern, line)
self.assertIsNotNone(match)
def test_screens(self):
sample = "Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767"
@ -202,6 +227,16 @@ class XrandrTests(unittest.TestCase):
2, len(actual["screens"][0]["associated_device"]["associated_modes"])
)
with open("tests/fixtures/generic/xrandr_properties.out", "r") as f:
txt = f.read()
actual = parse(txt, quiet=True)
self.assertEqual(1, len(actual["screens"]))
self.assertEqual(3, len(actual["unassociated_devices"]))
self.assertEqual(
29, len(actual["screens"][0]["associated_device"]["associated_modes"])
)
def test_infinite_loop_fix(self):
with open("tests/fixtures/generic/xrandr_fix_spaces.out", "r") as f:
txt = f.read()
@ -222,5 +257,62 @@ class XrandrTests(unittest.TestCase):
self.assertEqual(actual, json_dict)
def test_model(self):
asus_edid = [
" EDID: ",
" 00ffffffffffff000469d41901010101",
" 2011010308291a78ea8585a6574a9c26",
" 125054bfef80714f8100810f81408180",
" 9500950f01019a29a0d0518422305098",
" 360098ff1000001c000000fd00374b1e",
" 530f000a202020202020000000fc0041",
" 535553205657313933530a20000000ff",
" 0037384c383032313130370a20200077"
]
asus_edid.reverse()
expected = {
"name": "ASUS VW193S",
"product_id": "6612",
"serial_number": "78L8021107",
}
actual: Optional[Model] = _parse_model(asus_edid)
self.assertIsNotNone(actual)
if actual:
for k, v in expected.items():
self.assertEqual(v, actual[k], f"mode regex failed on {k}")
generic_edid = [
" EDID: ",
" 00ffffffffffff004ca3523100000000",
" 0014010380221378eac8959e57549226",
" 0f505400000001010101010101010101",
" 010101010101381d56d4500016303020",
" 250058c2100000190000000f00000000",
" 000000000025d9066a00000000fe0053",
" 414d53554e470a204ca34154000000fe",
" 004c544e313536415432343430310018"
]
generic_edid.reverse()
expected = {
"name": "Generic",
"product_id": "12626",
"serial_number": "0",
}
actual: Optional[Model] = _parse_model(generic_edid)
self.assertIsNotNone(actual)
if actual:
for k, v in expected.items():
self.assertEqual(v, actual[k], f"mode regex failed on {k}")
empty_edid = [""]
actual: Optional[Model] = _parse_model(empty_edid)
self.assertIsNone(actual)
if __name__ == '__main__':
unittest.main()