mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-13 01:20:24 +02:00
fix for unhandled lines in xrandr output
This commit is contained in:
@ -540,9 +540,19 @@ def parse(data: str, raw: bool = False, quiet: bool = False) -> Response:
|
||||
lines = data.splitlines()
|
||||
screen, device = None, None
|
||||
|
||||
# temporary fix to ignore specific unhandled lines
|
||||
ignore_pattern = re.compile(r'^\s+(h|v):\s+(height|width)\s+\d+\s+start\s+\d+\s+end')
|
||||
|
||||
result: Response = {"screens": []}
|
||||
if jc.utils.has_data(data):
|
||||
while index < len(lines):
|
||||
|
||||
# temporary fix to ignore specific unhandled lines
|
||||
ignore_re = ignore_pattern.match(lines[index])
|
||||
if ignore_re:
|
||||
index += 1
|
||||
continue
|
||||
|
||||
line = _Line.categorize(lines[index])
|
||||
if line.t == LineType.Screen:
|
||||
screen = _parse_screen(line)
|
||||
|
1
tests/fixtures/generic/xrandr.json
vendored
Normal file
1
tests/fixtures/generic/xrandr.json
vendored
Normal file
File diff suppressed because one or more lines are too long
1
tests/fixtures/generic/xrandr_2.json
vendored
Normal file
1
tests/fixtures/generic/xrandr_2.json
vendored
Normal file
File diff suppressed because one or more lines are too long
1
tests/fixtures/generic/xrandr_3.json
vendored
Normal file
1
tests/fixtures/generic/xrandr_3.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"screens":[{"devices":[{"props":{},"resolution_modes":[],"is_connected":false,"is_primary":true,"device_name":"test-3-1","rotation":"normal","reflection":"normal"},{"props":{},"resolution_modes":[{"resolution_width":1920,"resolution_height":1080,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":true,"is_preferred":true},{"frequency":59.94,"is_current":false,"is_preferred":false},{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":1680,"resolution_height":1050,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false},{"frequency":59.88,"is_current":false,"is_preferred":false}]},{"resolution_width":1400,"resolution_height":1050,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":1600,"resolution_height":900,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":1280,"resolution_height":1024,"is_high_resolution":false,"frequencies":[{"frequency":75.02,"is_current":false,"is_preferred":false},{"frequency":60.02,"is_current":false,"is_preferred":false},{"frequency":60.0,"is_current":false,"is_preferred":false}]}],"is_connected":true,"is_primary":false,"device_name":"test-3-2","rotation":"normal","reflection":"normal","resolution_width":1920,"resolution_height":1080,"offset_width":0,"offset_height":0,"dimension_width":521,"dimension_height":293}],"screen_number":0,"minimum_width":320,"minimum_height":200,"current_width":1920,"current_height":1080,"maximum_width":16384,"maximum_height":16384}]}
|
1
tests/fixtures/generic/xrandr_extra_hv_lines.json
vendored
Normal file
1
tests/fixtures/generic/xrandr_extra_hv_lines.json
vendored
Normal file
File diff suppressed because one or more lines are too long
47
tests/fixtures/generic/xrandr_extra_hv_lines.out
vendored
Normal file
47
tests/fixtures/generic/xrandr_extra_hv_lines.out
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
Screen 0: minimum 320 x 200, current 3840 x 3240, maximum 16384 x 16384
|
||||
eDP-1 connected 1920x1080+0+2160 (normal left inverted right x axis y axis) 309mm x 173mm
|
||||
1920x1080 60.00*+ 59.97 59.96 59.93
|
||||
1680x1050 59.95 60.00 59.88
|
||||
1400x1050 59.98
|
||||
1600x900 59.99 59.94 59.95 59.82
|
||||
1280x1024 60.00 60.02
|
||||
1440x900 60.00
|
||||
1400x900 59.96 59.88
|
||||
1280x960 60.00
|
||||
1440x810 60.00 59.97
|
||||
1368x768 59.88 59.85
|
||||
1280x800 59.99 60.00 59.97 59.81 59.91
|
||||
1280x720 60.00 60.00 59.99 59.86 59.74
|
||||
1024x768 60.00 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.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 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
|
||||
HDMI-1 disconnected (normal left inverted right x axis y axis)
|
||||
DP-1 disconnected primary 3840x2160+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
|
||||
DP-2 disconnected (normal left inverted right x axis y axis)
|
||||
3840x2160 (0xa0) 533.250MHz +HSync -VSync
|
||||
h: width 3840 start 3888 end 3952 total 4000 skew 0 clock 133.31KHz
|
||||
v: height 2160 start 2163 end 2168 total 2222 clock 60.00Hz
|
1
tests/fixtures/generic/xrandr_properties_1.json
vendored
Normal file
1
tests/fixtures/generic/xrandr_properties_1.json
vendored
Normal file
File diff suppressed because one or more lines are too long
59
tests/fixtures/generic/xrandr_simple.json
vendored
59
tests/fixtures/generic/xrandr_simple.json
vendored
@ -1,58 +1 @@
|
||||
{
|
||||
"screens": [
|
||||
{
|
||||
"screen_number": 0,
|
||||
"minimum_width": 8,
|
||||
"minimum_height": 8,
|
||||
"current_width": 1920,
|
||||
"current_height": 1080,
|
||||
"maximum_width": 32767,
|
||||
"maximum_height": 32767,
|
||||
"associated_device": {
|
||||
"associated_modes": [
|
||||
{
|
||||
"resolution_width": 1920,
|
||||
"resolution_height": 1080,
|
||||
"is_high_resolution": false,
|
||||
"frequencies": [
|
||||
{
|
||||
"frequency": 60.03,
|
||||
"is_current": true,
|
||||
"is_preferred": true
|
||||
},
|
||||
{
|
||||
"frequency": 59.93,
|
||||
"is_current": false,
|
||||
"is_preferred": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"resolution_width": 1680,
|
||||
"resolution_height": 1050,
|
||||
"is_high_resolution": false,
|
||||
"frequencies": [
|
||||
{
|
||||
"frequency": 59.88,
|
||||
"is_current": false,
|
||||
"is_preferred": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"is_connected": true,
|
||||
"is_primary": true,
|
||||
"device_name": "eDP1",
|
||||
"rotation": "normal",
|
||||
"reflection": "normal",
|
||||
"resolution_width": 1920,
|
||||
"resolution_height": 1080,
|
||||
"offset_width": 0,
|
||||
"offset_height": 0,
|
||||
"dimension_width": 310,
|
||||
"dimension_height": 170
|
||||
}
|
||||
}
|
||||
],
|
||||
"unassociated_devices": []
|
||||
}
|
||||
{"screens":[{"devices":[{"props":{},"resolution_modes":[{"resolution_width":1920,"resolution_height":1080,"is_high_resolution":false,"frequencies":[{"frequency":60.03,"is_current":true,"is_preferred":true},{"frequency":59.93,"is_current":false,"is_preferred":false}]},{"resolution_width":1680,"resolution_height":1050,"is_high_resolution":false,"frequencies":[{"frequency":59.88,"is_current":false,"is_preferred":false}]}],"is_connected":true,"is_primary":true,"device_name":"eDP1","rotation":"normal","reflection":"normal","resolution_width":1920,"resolution_height":1080,"offset_width":0,"offset_height":0,"dimension_width":310,"dimension_height":170}],"screen_number":0,"minimum_width":8,"minimum_height":8,"current_width":1920,"current_height":1080,"maximum_width":32767,"maximum_height":32767}]}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import pprint
|
||||
import json
|
||||
import re
|
||||
import unittest
|
||||
from typing import Optional
|
||||
@ -197,52 +198,67 @@ class XrandrTests(unittest.TestCase):
|
||||
def test_complete_1(self):
|
||||
self.maxDiff = None
|
||||
with open("tests/fixtures/generic/xrandr.out", "r") as f:
|
||||
txt = f.read()
|
||||
actual = parse(txt, quiet=True)
|
||||
actual = parse(f.read(), quiet=True)
|
||||
|
||||
with open('tests/fixtures/generic/xrandr.json', 'r') as f:
|
||||
reference = json.loads(f.read())
|
||||
|
||||
self.assertEqual(1, len(actual["screens"]))
|
||||
self.assertEqual(
|
||||
18, len(actual["screens"][0]["devices"][0]["resolution_modes"])
|
||||
)
|
||||
self.assertEqual(actual, reference)
|
||||
|
||||
def test_complete_2(self):
|
||||
with open("tests/fixtures/generic/xrandr_2.out", "r") as f:
|
||||
txt = f.read()
|
||||
actual = parse(txt, quiet=True)
|
||||
actual = parse(f.read(), quiet=True)
|
||||
|
||||
with open('tests/fixtures/generic/xrandr_2.json', 'r') as f:
|
||||
reference = json.loads(f.read())
|
||||
|
||||
self.assertEqual(1, len(actual["screens"]))
|
||||
self.assertEqual(
|
||||
38, len(actual["screens"][0]["devices"][0]["resolution_modes"])
|
||||
)
|
||||
self.assertEqual(actual, reference)
|
||||
|
||||
def test_complete_3(self):
|
||||
with open("tests/fixtures/generic/xrandr_3.out", "r") as f:
|
||||
txt = f.read()
|
||||
actual = parse(txt, quiet=True)
|
||||
actual = parse(f.read(), quiet=True)
|
||||
|
||||
with open('tests/fixtures/generic/xrandr_3.json', 'r') as f:
|
||||
reference = json.loads(f.read())
|
||||
|
||||
self.assertEqual(1, len(actual["screens"]))
|
||||
self.assertEqual(
|
||||
2,
|
||||
len(actual["screens"][0]["devices"]),
|
||||
)
|
||||
self.assertEqual(actual, reference)
|
||||
|
||||
def test_complete_4(self):
|
||||
with open("tests/fixtures/generic/xrandr_simple.out", "r") as f:
|
||||
txt = f.read()
|
||||
actual = parse(txt, quiet=True)
|
||||
actual = parse(f.read(), quiet=True)
|
||||
|
||||
with open('tests/fixtures/generic/xrandr_simple.json', 'r') as f:
|
||||
reference = json.loads(f.read())
|
||||
|
||||
self.assertEqual(1, len(actual["screens"]))
|
||||
self.assertEqual(2, len(actual["screens"][0]["devices"][0]["resolution_modes"]))
|
||||
self.assertEqual(actual, reference)
|
||||
|
||||
def test_complete_5(self):
|
||||
with open("tests/fixtures/generic/xrandr_properties_1.out", "r") as f:
|
||||
txt = f.read()
|
||||
actual = parse(txt, quiet=True)
|
||||
actual = parse(f.read(), quiet=True)
|
||||
|
||||
with open('tests/fixtures/generic/xrandr_properties_1.json', 'r') as f:
|
||||
reference = json.loads(f.read())
|
||||
|
||||
self.assertEqual(1, len(actual["screens"]))
|
||||
self.assertEqual(
|
||||
38, len(actual["screens"][0]["devices"][0]["resolution_modes"])
|
||||
)
|
||||
self.assertEqual(actual, reference)
|
||||
|
||||
# def test_model(self):
|
||||
# asus_edid = [
|
||||
@ -346,6 +362,16 @@ default connected 1024x600+0+0 0mm x 0mm
|
||||
actual["screens"][0]["devices"][0]["props"]["EdidModel"], # type: ignore
|
||||
)
|
||||
|
||||
def test_issue_549(self):
|
||||
"""https://github.com/kellyjonbrazil/jc/issues/549"""
|
||||
with open("tests/fixtures/generic/xrandr_extra_hv_lines.out", "r") as f:
|
||||
actual = parse(f.read(), quiet=True)
|
||||
|
||||
with open('tests/fixtures/generic/xrandr_extra_hv_lines.json', 'r') as f:
|
||||
reference = json.loads(f.read())
|
||||
|
||||
self.assertEqual(actual, reference)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user