diff --git a/jc/parsers/xrandr.py b/jc/parsers/xrandr.py index 363741f9..05963458 100644 --- a/jc/parsers/xrandr.py +++ b/jc/parsers/xrandr.py @@ -26,8 +26,8 @@ Schema: "current_height": integer, "maximum_width": integer, "maximum_height": integer, - "associated_device": { - "associated_modes": [ + "devices": { + "modes": [ { "resolution_width": integer, "resolution_height": integer, @@ -58,24 +58,6 @@ Schema: "reflection": string } ], - "unassociated_devices": [ - { - "associated_modes": [ - { - "resolution_width": integer, - "resolution_height": integer, - "is_high_resolution": boolean, - "frequencies": [ - { - "frequency": float, - "is_current": boolean, - "is_preferred": boolean - } - ] - } - ] - } - ] } Examples: @@ -91,8 +73,8 @@ Examples: "current_height": 1080, "maximum_width": 32767, "maximum_height": 32767, - "associated_device": { - "associated_modes": [ + "devices": { + "modes": [ { "resolution_width": 1920, "resolution_height": 1080, @@ -136,8 +118,7 @@ Examples: "reflection": "normal" } } - ], - "unassociated_devices": [] + ] } $ xrandr --properties | jc --xrandr -p @@ -151,8 +132,8 @@ Examples: "current_height": 1080, "maximum_width": 32767, "maximum_height": 32767, - "associated_device": { - "associated_modes": [ + "devices": { + "modes": [ { "resolution_width": 1920, "resolution_height": 1080, @@ -199,8 +180,7 @@ Examples: "reflection": "normal" } } - ], - "unassociated_devices": [] + ] } """ import re @@ -212,14 +192,15 @@ from jc.parsers.pyedid.helpers.edid_helper import EdidHelper class info: """Provides parser metadata (version, author, etc.)""" + version = "1.2" description = "`xrandr` command parser" author = "Kevin Lyter" - author_email = "lyter_git at sent.com" - details = 'Using parts of the pyedid library at https://github.com/jojonas/pyedid.' + author_email = "code (at) lyterk.com" + details = "Using parts of the pyedid library at https://github.com/jojonas/pyedid." compatible = ["linux", "darwin", "cygwin", "aix", "freebsd"] magic_commands = ["xrandr"] - tags = ['command'] + tags = ["command"] __version__ = info.version @@ -267,7 +248,7 @@ try: "offset_height": int, "dimension_width": int, "dimension_height": int, - "associated_modes": List[Mode], + "modes": List[Mode], "rotation": str, "reflection": str, }, @@ -282,14 +263,13 @@ try: "current_height": int, "maximum_width": int, "maximum_height": int, - "associated_device": Device, + "devices": List[Device], }, ) Response = TypedDict( "Response", { "screens": List[Screen], - "unassociated_devices": List[Device], }, ) except ImportError: @@ -317,14 +297,17 @@ def _parse_screen(next_lines: List[str]) -> Optional[Screen]: return None raw_matches = result.groupdict() - screen: Screen = {} + + screen: Screen = {"devices": []} for k, v in raw_matches.items(): screen[k] = int(v) - if next_lines: + while next_lines: device: Optional[Device] = _parse_device(next_lines) - if device: - screen["associated_device"] = device + if not device: + break + else: + screen["devices"].append(device) return screen @@ -358,7 +341,7 @@ def _parse_device(next_lines: List[str], quiet: bool = False) -> Optional[Device matches = result.groupdict() device: Device = { - "associated_modes": [], + "modes": [], "is_connected": matches["is_connected"] == "connected", "is_primary": matches["is_primary"] is not None and len(matches["is_primary"]) > 0, @@ -367,14 +350,21 @@ def _parse_device(next_lines: List[str], quiet: bool = False) -> Optional[Device "reflection": matches["reflection"] or "normal", } for k, v in matches.items(): - if k not in {"is_connected", "is_primary", "device_name", "rotation", "reflection"}: + if k not in { + "is_connected", + "is_primary", + "device_name", + "rotation", + "reflection", + }: try: if v: device[k] = int(v) - except ValueError and not quiet: - jc.utils.warning_message( - [f"{next_line} : {k} - {v} is not int-able"] - ) + except ValueError: + if not quiet: + jc.utils.warning_message( + [f"{next_line} : {k} - {v} is not int-able"] + ) model: Optional[Model] = _parse_model(next_lines, quiet) if model: @@ -386,7 +376,7 @@ def _parse_device(next_lines: List[str], quiet: bool = False) -> Optional[Device next_line = next_lines.pop() next_mode: Optional[Mode] = _parse_mode(next_line) if next_mode: - device["associated_modes"].append(next_mode) + device["modes"].append(next_mode) else: if re.match(_device_pattern, next_line): next_lines.append(next_line) @@ -481,7 +471,7 @@ def _parse_mode(line: str) -> Optional[Mode]: return mode -def parse(data: str, raw: bool =False, quiet: bool =False) -> Dict: +def parse(data: str, raw: bool = False, quiet: bool = False) -> Dict: """ Main text parsing function @@ -500,19 +490,12 @@ def parse(data: str, raw: bool =False, quiet: bool =False) -> Dict: linedata = data.splitlines() linedata.reverse() # For popping - result: Response = {"screens": [], "unassociated_devices": []} + result: Response = {"screens": []} if jc.utils.has_data(data): while linedata: screen = _parse_screen(linedata) if screen: result["screens"].append(screen) - else: - device = _parse_device(linedata, quiet) - if device: - result["unassociated_devices"].append(device) - - if not result["unassociated_devices"] and not result["screens"]: - return {} return result diff --git a/tests/fixtures/generic/xrandr_3.out b/tests/fixtures/generic/xrandr_3.out new file mode 100644 index 00000000..8eaf62f0 --- /dev/null +++ b/tests/fixtures/generic/xrandr_3.out @@ -0,0 +1,8 @@ +Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384 +test-3-1 disconnected primary (normal left inverted right x axis y axis) +test-3-2 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 521mm x 293mm + 1920x1080 60.00*+ 59.94 60.00 + 1680x1050 60.00 59.88 + 1400x1050 60.00 + 1600x900 60.00 + 1280x1024 75.02 60.02 60.00 diff --git a/tests/fixtures/generic/xrandr_fix_spaces.json b/tests/fixtures/generic/xrandr_fix_spaces.json deleted file mode 100644 index aac9c63a..00000000 --- a/tests/fixtures/generic/xrandr_fix_spaces.json +++ /dev/null @@ -1 +0,0 @@ -{"screens":[{"screen_number":0,"minimum_width":320,"minimum_height":200,"current_width":2806,"current_height":900,"maximum_width":8192,"maximum_height":8192,"associated_device":{"associated_modes":[{"resolution_width":1366,"resolution_height":768,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":true,"is_preferred":true}]},{"resolution_width":1280,"resolution_height":720,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false},{"frequency":59.99,"is_current":false,"is_preferred":false},{"frequency":59.86,"is_current":false,"is_preferred":false},{"frequency":59.74,"is_current":false,"is_preferred":false}]},{"resolution_width":1024,"resolution_height":768,"is_high_resolution":false,"frequencies":[{"frequency":60.04,"is_current":false,"is_preferred":false},{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":960,"resolution_height":720,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":928,"resolution_height":696,"is_high_resolution":false,"frequencies":[{"frequency":60.05,"is_current":false,"is_preferred":false}]},{"resolution_width":896,"resolution_height":672,"is_high_resolution":false,"frequencies":[{"frequency":60.01,"is_current":false,"is_preferred":false}]},{"resolution_width":1024,"resolution_height":576,"is_high_resolution":false,"frequencies":[{"frequency":59.95,"is_current":false,"is_preferred":false},{"frequency":59.96,"is_current":false,"is_preferred":false},{"frequency":59.9,"is_current":false,"is_preferred":false},{"frequency":59.82,"is_current":false,"is_preferred":false}]},{"resolution_width":960,"resolution_height":600,"is_high_resolution":false,"frequencies":[{"frequency":59.93,"is_current":false,"is_preferred":false},{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":960,"resolution_height":540,"is_high_resolution":false,"frequencies":[{"frequency":59.96,"is_current":false,"is_preferred":false},{"frequency":59.99,"is_current":false,"is_preferred":false},{"frequency":59.63,"is_current":false,"is_preferred":false},{"frequency":59.82,"is_current":false,"is_preferred":false}]},{"resolution_width":800,"resolution_height":600,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false},{"frequency":60.32,"is_current":false,"is_preferred":false},{"frequency":56.25,"is_current":false,"is_preferred":false}]},{"resolution_width":840,"resolution_height":525,"is_high_resolution":false,"frequencies":[{"frequency":60.01,"is_current":false,"is_preferred":false},{"frequency":59.88,"is_current":false,"is_preferred":false}]},{"resolution_width":864,"resolution_height":486,"is_high_resolution":false,"frequencies":[{"frequency":59.92,"is_current":false,"is_preferred":false},{"frequency":59.57,"is_current":false,"is_preferred":false}]},{"resolution_width":700,"resolution_height":525,"is_high_resolution":false,"frequencies":[{"frequency":59.98,"is_current":false,"is_preferred":false}]},{"resolution_width":800,"resolution_height":450,"is_high_resolution":false,"frequencies":[{"frequency":59.95,"is_current":false,"is_preferred":false},{"frequency":59.82,"is_current":false,"is_preferred":false}]},{"resolution_width":640,"resolution_height":512,"is_high_resolution":false,"frequencies":[{"frequency":60.02,"is_current":false,"is_preferred":false}]},{"resolution_width":700,"resolution_height":450,"is_high_resolution":false,"frequencies":[{"frequency":59.96,"is_current":false,"is_preferred":false},{"frequency":59.88,"is_current":false,"is_preferred":false}]},{"resolution_width":640,"resolution_height":480,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false},{"frequency":59.94,"is_current":false,"is_preferred":false}]},{"resolution_width":720,"resolution_height":405,"is_high_resolution":false,"frequencies":[{"frequency":59.51,"is_current":false,"is_preferred":false},{"frequency":58.99,"is_current":false,"is_preferred":false}]},{"resolution_width":684,"resolution_height":384,"is_high_resolution":false,"frequencies":[{"frequency":59.88,"is_current":false,"is_preferred":false},{"frequency":59.85,"is_current":false,"is_preferred":false}]},{"resolution_width":640,"resolution_height":400,"is_high_resolution":false,"frequencies":[{"frequency":59.88,"is_current":false,"is_preferred":false},{"frequency":59.98,"is_current":false,"is_preferred":false}]},{"resolution_width":640,"resolution_height":360,"is_high_resolution":false,"frequencies":[{"frequency":59.86,"is_current":false,"is_preferred":false},{"frequency":59.83,"is_current":false,"is_preferred":false},{"frequency":59.84,"is_current":false,"is_preferred":false},{"frequency":59.32,"is_current":false,"is_preferred":false}]},{"resolution_width":512,"resolution_height":384,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":512,"resolution_height":288,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false},{"frequency":59.92,"is_current":false,"is_preferred":false}]},{"resolution_width":480,"resolution_height":270,"is_high_resolution":false,"frequencies":[{"frequency":59.63,"is_current":false,"is_preferred":false},{"frequency":59.82,"is_current":false,"is_preferred":false}]},{"resolution_width":400,"resolution_height":300,"is_high_resolution":false,"frequencies":[{"frequency":60.32,"is_current":false,"is_preferred":false},{"frequency":56.34,"is_current":false,"is_preferred":false}]},{"resolution_width":432,"resolution_height":243,"is_high_resolution":false,"frequencies":[{"frequency":59.92,"is_current":false,"is_preferred":false},{"frequency":59.57,"is_current":false,"is_preferred":false}]},{"resolution_width":320,"resolution_height":240,"is_high_resolution":false,"frequencies":[{"frequency":60.05,"is_current":false,"is_preferred":false}]},{"resolution_width":360,"resolution_height":202,"is_high_resolution":false,"frequencies":[{"frequency":59.51,"is_current":false,"is_preferred":false},{"frequency":59.13,"is_current":false,"is_preferred":false}]},{"resolution_width":320,"resolution_height":180,"is_high_resolution":false,"frequencies":[{"frequency":59.84,"is_current":false,"is_preferred":false},{"frequency":59.32,"is_current":false,"is_preferred":false}]}],"is_connected":true,"is_primary":true,"device_name":"LVDS-1","rotation":"normal","reflection":"normal","resolution_width":1366,"resolution_height":768,"offset_width":0,"offset_height":0,"dimension_width":344,"dimension_height":194}}],"unassociated_devices":[{"associated_modes":[{"resolution_width":1440,"resolution_height":900,"is_high_resolution":false,"frequencies":[{"frequency":59.89,"is_current":true,"is_preferred":true},{"frequency":74.98,"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}]},{"resolution_width":1280,"resolution_height":960,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":1280,"resolution_height":800,"is_high_resolution":false,"frequencies":[{"frequency":74.93,"is_current":false,"is_preferred":false},{"frequency":59.81,"is_current":false,"is_preferred":false}]},{"resolution_width":1152,"resolution_height":864,"is_high_resolution":false,"frequencies":[{"frequency":75.0,"is_current":false,"is_preferred":false}]},{"resolution_width":1024,"resolution_height":768,"is_high_resolution":false,"frequencies":[{"frequency":75.03,"is_current":false,"is_preferred":false},{"frequency":70.07,"is_current":false,"is_preferred":false},{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":832,"resolution_height":624,"is_high_resolution":false,"frequencies":[{"frequency":74.55,"is_current":false,"is_preferred":false}]},{"resolution_width":800,"resolution_height":600,"is_high_resolution":false,"frequencies":[{"frequency":72.19,"is_current":false,"is_preferred":false},{"frequency":75.0,"is_current":false,"is_preferred":false},{"frequency":60.32,"is_current":false,"is_preferred":false},{"frequency":56.25,"is_current":false,"is_preferred":false}]},{"resolution_width":640,"resolution_height":480,"is_high_resolution":false,"frequencies":[{"frequency":75.0,"is_current":false,"is_preferred":false},{"frequency":72.81,"is_current":false,"is_preferred":false},{"frequency":66.67,"is_current":false,"is_preferred":false},{"frequency":59.94,"is_current":false,"is_preferred":false}]},{"resolution_width":720,"resolution_height":400,"is_high_resolution":false,"frequencies":[{"frequency":70.08,"is_current":false,"is_preferred":false}]}],"is_connected":true,"is_primary":false,"device_name":"VGA-1","rotation":"normal","reflection":"Y axis","resolution_width":1440,"resolution_height":900,"offset_width":1366,"offset_height":0,"dimension_width":408,"dimension_height":255},{"associated_modes":[],"is_connected":false,"is_primary":false,"device_name":"HDMI-1","rotation":"normal","reflection":"normal"},{"associated_modes":[],"is_connected":false,"is_primary":false,"device_name":"DP-1","rotation":"normal","reflection":"normal"}]} diff --git a/tests/fixtures/generic/xrandr_fix_spaces.out b/tests/fixtures/generic/xrandr_fix_spaces.out deleted file mode 100644 index f45bb098..00000000 --- a/tests/fixtures/generic/xrandr_fix_spaces.out +++ /dev/null @@ -1,44 +0,0 @@ -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 - 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 Y axis (normal left inverted right x axis y axis) 408mm x 255mm - 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) -DP-1 disconnected (normal left inverted right x axis y axis) diff --git a/tests/fixtures/generic/xrandr_is_current_fix.json b/tests/fixtures/generic/xrandr_is_current_fix.json deleted file mode 100644 index 98ee6634..00000000 --- a/tests/fixtures/generic/xrandr_is_current_fix.json +++ /dev/null @@ -1 +0,0 @@ -{"screens":[{"screen_number":0,"minimum_width":320,"minimum_height":200,"current_width":1846,"current_height":768,"maximum_width":8192,"maximum_height":8192,"associated_device":{"associated_modes":[{"resolution_width":1366,"resolution_height":768,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":true,"is_preferred":true}]},{"resolution_width":1280,"resolution_height":720,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false},{"frequency":59.99,"is_current":false,"is_preferred":false},{"frequency":59.86,"is_current":false,"is_preferred":false},{"frequency":59.74,"is_current":false,"is_preferred":false}]},{"resolution_width":1024,"resolution_height":768,"is_high_resolution":false,"frequencies":[{"frequency":60.04,"is_current":false,"is_preferred":false},{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":960,"resolution_height":720,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":928,"resolution_height":696,"is_high_resolution":false,"frequencies":[{"frequency":60.05,"is_current":false,"is_preferred":false}]},{"resolution_width":896,"resolution_height":672,"is_high_resolution":false,"frequencies":[{"frequency":60.01,"is_current":false,"is_preferred":false}]},{"resolution_width":1024,"resolution_height":576,"is_high_resolution":false,"frequencies":[{"frequency":59.95,"is_current":false,"is_preferred":false},{"frequency":59.96,"is_current":false,"is_preferred":false},{"frequency":59.9,"is_current":false,"is_preferred":false},{"frequency":59.82,"is_current":false,"is_preferred":false}]},{"resolution_width":960,"resolution_height":600,"is_high_resolution":false,"frequencies":[{"frequency":59.93,"is_current":false,"is_preferred":false},{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":960,"resolution_height":540,"is_high_resolution":false,"frequencies":[{"frequency":59.96,"is_current":false,"is_preferred":false},{"frequency":59.99,"is_current":false,"is_preferred":false},{"frequency":59.63,"is_current":false,"is_preferred":false},{"frequency":59.82,"is_current":false,"is_preferred":false}]},{"resolution_width":800,"resolution_height":600,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false},{"frequency":60.32,"is_current":false,"is_preferred":false},{"frequency":56.25,"is_current":false,"is_preferred":false}]},{"resolution_width":840,"resolution_height":525,"is_high_resolution":false,"frequencies":[{"frequency":60.01,"is_current":false,"is_preferred":false},{"frequency":59.88,"is_current":false,"is_preferred":false}]},{"resolution_width":864,"resolution_height":486,"is_high_resolution":false,"frequencies":[{"frequency":59.92,"is_current":false,"is_preferred":false},{"frequency":59.57,"is_current":false,"is_preferred":false}]},{"resolution_width":700,"resolution_height":525,"is_high_resolution":false,"frequencies":[{"frequency":59.98,"is_current":false,"is_preferred":false}]},{"resolution_width":800,"resolution_height":450,"is_high_resolution":false,"frequencies":[{"frequency":59.95,"is_current":false,"is_preferred":false},{"frequency":59.82,"is_current":false,"is_preferred":false}]},{"resolution_width":640,"resolution_height":512,"is_high_resolution":false,"frequencies":[{"frequency":60.02,"is_current":false,"is_preferred":false}]},{"resolution_width":700,"resolution_height":450,"is_high_resolution":false,"frequencies":[{"frequency":59.96,"is_current":false,"is_preferred":false},{"frequency":59.88,"is_current":false,"is_preferred":false}]},{"resolution_width":640,"resolution_height":480,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false},{"frequency":59.94,"is_current":false,"is_preferred":false}]},{"resolution_width":720,"resolution_height":405,"is_high_resolution":false,"frequencies":[{"frequency":59.51,"is_current":false,"is_preferred":false},{"frequency":58.99,"is_current":false,"is_preferred":false}]},{"resolution_width":684,"resolution_height":384,"is_high_resolution":false,"frequencies":[{"frequency":59.88,"is_current":false,"is_preferred":false},{"frequency":59.85,"is_current":false,"is_preferred":false}]},{"resolution_width":640,"resolution_height":400,"is_high_resolution":false,"frequencies":[{"frequency":59.88,"is_current":false,"is_preferred":false},{"frequency":59.98,"is_current":false,"is_preferred":false}]},{"resolution_width":640,"resolution_height":360,"is_high_resolution":false,"frequencies":[{"frequency":59.86,"is_current":false,"is_preferred":false},{"frequency":59.83,"is_current":false,"is_preferred":false},{"frequency":59.84,"is_current":false,"is_preferred":false},{"frequency":59.32,"is_current":false,"is_preferred":false}]},{"resolution_width":512,"resolution_height":384,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":512,"resolution_height":288,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false},{"frequency":59.92,"is_current":false,"is_preferred":false}]},{"resolution_width":480,"resolution_height":270,"is_high_resolution":false,"frequencies":[{"frequency":59.63,"is_current":false,"is_preferred":false},{"frequency":59.82,"is_current":false,"is_preferred":false}]},{"resolution_width":400,"resolution_height":300,"is_high_resolution":false,"frequencies":[{"frequency":60.32,"is_current":false,"is_preferred":false},{"frequency":56.34,"is_current":false,"is_preferred":false}]},{"resolution_width":432,"resolution_height":243,"is_high_resolution":false,"frequencies":[{"frequency":59.92,"is_current":false,"is_preferred":false},{"frequency":59.57,"is_current":false,"is_preferred":false}]},{"resolution_width":320,"resolution_height":240,"is_high_resolution":false,"frequencies":[{"frequency":60.05,"is_current":false,"is_preferred":false}]},{"resolution_width":360,"resolution_height":202,"is_high_resolution":false,"frequencies":[{"frequency":59.51,"is_current":false,"is_preferred":false},{"frequency":59.13,"is_current":false,"is_preferred":false}]},{"resolution_width":320,"resolution_height":180,"is_high_resolution":false,"frequencies":[{"frequency":59.84,"is_current":false,"is_preferred":false},{"frequency":59.32,"is_current":false,"is_preferred":false}]}],"is_connected":true,"is_primary":true,"device_name":"LVDS-1","rotation":"normal","reflection":"normal","resolution_width":1366,"resolution_height":768,"offset_width":0,"offset_height":0,"dimension_width":344,"dimension_height":194}}],"unassociated_devices":[{"associated_modes":[{"resolution_width":1440,"resolution_height":900,"is_high_resolution":false,"frequencies":[{"frequency":59.89,"is_current":false,"is_preferred":true},{"frequency":74.98,"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}]},{"resolution_width":1280,"resolution_height":960,"is_high_resolution":false,"frequencies":[{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":1280,"resolution_height":800,"is_high_resolution":false,"frequencies":[{"frequency":74.93,"is_current":false,"is_preferred":false},{"frequency":59.81,"is_current":false,"is_preferred":false}]},{"resolution_width":1152,"resolution_height":864,"is_high_resolution":false,"frequencies":[{"frequency":75.0,"is_current":false,"is_preferred":false}]},{"resolution_width":1024,"resolution_height":768,"is_high_resolution":false,"frequencies":[{"frequency":75.03,"is_current":false,"is_preferred":false},{"frequency":70.07,"is_current":false,"is_preferred":false},{"frequency":60.0,"is_current":false,"is_preferred":false}]},{"resolution_width":832,"resolution_height":624,"is_high_resolution":false,"frequencies":[{"frequency":74.55,"is_current":false,"is_preferred":false}]},{"resolution_width":800,"resolution_height":600,"is_high_resolution":false,"frequencies":[{"frequency":72.19,"is_current":false,"is_preferred":false},{"frequency":75.0,"is_current":false,"is_preferred":false},{"frequency":60.32,"is_current":false,"is_preferred":false},{"frequency":56.25,"is_current":false,"is_preferred":false}]},{"resolution_width":640,"resolution_height":480,"is_high_resolution":false,"frequencies":[{"frequency":75.0,"is_current":true,"is_preferred":false},{"frequency":72.81,"is_current":false,"is_preferred":false},{"frequency":66.67,"is_current":false,"is_preferred":false},{"frequency":59.94,"is_current":false,"is_preferred":false}]},{"resolution_width":720,"resolution_height":400,"is_high_resolution":false,"frequencies":[{"frequency":70.08,"is_current":false,"is_preferred":false}]}],"is_connected":true,"is_primary":false,"device_name":"VGA-1","rotation":"left","reflection":"normal","resolution_width":480,"resolution_height":640,"offset_width":1366,"offset_height":0,"dimension_width":408,"dimension_height":255},{"associated_modes":[],"is_connected":false,"is_primary":false,"device_name":"HDMI-1","rotation":"normal","reflection":"normal"},{"associated_modes":[],"is_connected":false,"is_primary":false,"device_name":"DP-1","rotation":"normal","reflection":"normal"}]} diff --git a/tests/fixtures/generic/xrandr_is_current_fix.out b/tests/fixtures/generic/xrandr_is_current_fix.out deleted file mode 100644 index 452a6462..00000000 --- a/tests/fixtures/generic/xrandr_is_current_fix.out +++ /dev/null @@ -1,44 +0,0 @@ -Screen 0: minimum 320 x 200, current 1846 x 768, maximum 8192 x 8192 -LVDS-1 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 344mm x 194mm - 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 480x640+1366+0 left (normal left inverted right x axis y axis) 408mm x 255mm - 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) -DP-1 disconnected (normal left inverted right x axis y axis) diff --git a/tests/test_xrandr.py b/tests/test_xrandr.py index 2866dc32..0c704e88 100644 --- a/tests/test_xrandr.py +++ b/tests/test_xrandr.py @@ -21,13 +21,15 @@ from jc.parsers.xrandr import ( Screen, ) +import pprint + class XrandrTests(unittest.TestCase): def test_xrandr_nodata(self): """ Test 'xrandr' with no data """ - self.assertEqual(parse('', quiet=True), {}) + self.assertEqual(parse("", quiet=True), {"screens": []}) def test_regexes(self): devices = [ @@ -44,7 +46,7 @@ class XrandrTests(unittest.TestCase): screens = [ "Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767", - "Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384" + "Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384", ] for screen in screens: self.assertIsNotNone(re.match(_screen_pattern, screen)) @@ -63,7 +65,7 @@ class XrandrTests(unittest.TestCase): if match: rest = match.groupdict()["rest"] self.assertIsNotNone(re.match(_frequencies_pattern, rest)) - + edid_lines = [ " EDID: ", " 00ffffffffffff000469d41901010101 ", @@ -73,7 +75,7 @@ class XrandrTests(unittest.TestCase): " 360098ff1000001c000000fd00374b1e ", " 530f000a202020202020000000fc0041 ", " 535553205657313933530a20000000ff ", - " 0037384c383032313130370a20200077 " + " 0037384c383032313130370a20200077 ", ] for i in range(len(edid_lines)): @@ -104,7 +106,9 @@ class XrandrTests(unittest.TestCase): for k, v in expected.items(): self.assertEqual(v, actual[k], f"screens regex failed on {k}") - sample = "Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384" + sample = ( + "Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 16384 x 16384" + ) actual = _parse_screen([sample]) if actual: self.assertEqual(320, actual["minimum_width"]) @@ -141,9 +145,7 @@ class XrandrTests(unittest.TestCase): device = _parse_device(extended_sample) if device: - self.assertEqual( - 59.94, device["associated_modes"][12]["frequencies"][4]["frequency"] - ) + self.assertEqual(59.94, device["modes"][12]["frequencies"][4]["frequency"]) def test_device_with_reflect(self): sample = "VGA-1 connected primary 1920x1080+0+0 left X and Y axis (normal left inverted right x axis y axis) 310mm x 170mm" @@ -195,67 +197,49 @@ class XrandrTests(unittest.TestCase): self.assertEqual(True, actual["is_high_resolution"]) self.assertEqual(50.0, actual["frequencies"][1]["frequency"]) - def test_complete(self): + 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) self.assertEqual(1, len(actual["screens"])) - self.assertEqual(4, len(actual["unassociated_devices"])) - self.assertEqual( - 18, len(actual["screens"][0]["associated_device"]["associated_modes"]) - ) + self.assertEqual(18, len(actual["screens"][0]["devices"][0]["modes"])) + def test_complete_2(self): with open("tests/fixtures/generic/xrandr_2.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(38, len(actual["screens"][0]["devices"][0]["modes"])) + + def test_complete_3(self): + with open("tests/fixtures/generic/xrandr_3.out", "r") as f: + txt = f.read() + actual = parse(txt, quiet=True) + + self.assertEqual(1, len(actual["screens"])) self.assertEqual( - 38, len(actual["screens"][0]["associated_device"]["associated_modes"]) + 2, + len(actual["screens"][0]["devices"]), ) + def test_complete_4(self): with open("tests/fixtures/generic/xrandr_simple.out", "r") as f: txt = f.read() actual = parse(txt, quiet=True) self.assertEqual(1, len(actual["screens"])) - self.assertEqual(0, len(actual["unassociated_devices"])) - self.assertEqual( - 2, len(actual["screens"][0]["associated_device"]["associated_modes"]) - ) + self.assertEqual(2, len(actual["screens"][0]["devices"][0]["modes"])) + def test_complete_5(self): 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() - actual = parse(txt, quiet=True) - - with open("tests/fixtures/generic/xrandr_fix_spaces.json", "r") as f: - json_dict = json.loads(f.read()) - - self.assertEqual(actual, json_dict) - - def test_is_current_fix(self): - with open("tests/fixtures/generic/xrandr_is_current_fix.out", "r") as f: - txt = f.read() - actual = parse(txt, quiet=True) - - with open("tests/fixtures/generic/xrandr_is_current_fix.json", "r") as f: - json_dict = json.loads(f.read()) - - self.assertEqual(actual, json_dict) + self.assertEqual(29, len(actual["screens"][0]["devices"][0]["modes"])) def test_model(self): asus_edid = [ @@ -267,7 +251,7 @@ class XrandrTests(unittest.TestCase): " 360098ff1000001c000000fd00374b1e", " 530f000a202020202020000000fc0041", " 535553205657313933530a20000000ff", - " 0037384c383032313130370a20200077" + " 0037384c383032313130370a20200077", ] asus_edid.reverse() @@ -293,8 +277,8 @@ class XrandrTests(unittest.TestCase): " 250058c2100000190000000f00000000", " 000000000025d9066a00000000fe0053", " 414d53554e470a204ca34154000000fe", - " 004c544e313536415432343430310018" - ] + " 004c544e313536415432343430310018", + ] generic_edid.reverse() expected = { @@ -314,5 +298,6 @@ class XrandrTests(unittest.TestCase): actual: Optional[Model] = _parse_model(empty_edid) self.assertIsNone(actual) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main()