Files
dotfiles/quickshell/tests/test_displays.py
T
2026-11-17 18:15:16 +07:00

40 lines
1.5 KiB
Python

import importlib.util
import pathlib
import unittest
from unittest.mock import patch
PATH = pathlib.Path(__file__).resolve().parents[1] / 'backend' / 'displays.py'
spec = importlib.util.spec_from_file_location('displays', PATH)
displays = importlib.util.module_from_spec(spec)
spec.loader.exec_module(displays)
class DisplayTests(unittest.TestCase):
def test_normalize(self):
monitor = {'name': 'eDP-1', 'width': 1920, 'height': 1080, 'refreshRate': 59.999, 'scale': 1.25, 'focused': True, 'availableModes': ['1920x1080@60.00Hz']}
result = displays.normalize([monitor])[0]
self.assertEqual((result['width'], result['height']), (1920, 1080))
self.assertEqual(result['refreshRate'], 60.0)
self.assertEqual(result['availableModes'], ['1920x1080@60.00Hz'])
def test_invalid_list(self):
with self.assertRaises(ValueError):
displays.normalize({})
def test_missing_name_skipped(self):
self.assertEqual(displays.normalize([{}, None]), [])
def test_read_only_command(self):
with patch.object(displays.subprocess, 'run') as run:
run.return_value.stdout = '[]'
self.assertEqual(displays.main(['list'])['monitors'], [])
self.assertEqual(run.call_args.args[0], ['hyprctl', '-j', 'monitors', 'all'])
def test_mutating_command_rejected(self):
with self.assertRaises(ValueError):
displays.main(['set', 'eDP-1', '1920x1080'])
if __name__ == '__main__':
unittest.main()