add tests for parsing certain xrandr output; fix crash when screen doesn't have an...
[lilass.git] / tests.py
1 #!/usr/bin/env python3
2 import unittest
3 import screen
4 import os
5
6 class TestResolutions(unittest.TestCase):
7
8     def test_ratio(self):
9         # check whether a few aspect ratios are printed as expected
10         self.assertEqual(str(screen.Resolution(1024, 768)), '1024x768 (4:3)')
11         self.assertTrue(str(screen.Resolution(1280, 1024)) in ('1280x1024 (5:4)', '1280x1024 (4:3)'))
12         self.assertEqual(str(screen.Resolution(1366, 768)), '1366x768 (16:9)')
13         self.assertEqual(str(screen.Resolution(1920, 1080)), '1920x1080 (16:9)')
14         self.assertEqual(str(screen.Resolution(1920, 1200)), '1920x1200 (16:10)')
15         self.assertEqual(str(screen.Resolution(720, 480)), '720x480 (3:2)')
16
17     def test_xrandr(self):
18         internalConnectors = list(screen.commonInternalConnectorNames())
19         for file in os.listdir('xrandr-tests'):
20             print("##",file)
21             with open(os.path.join('xrandr-tests', file)) as file:
22                 s = screen.ScreenSituation(internalConnectors, xrandrSource = file)
23                 del(s)
24
25 if __name__ == '__main__':
26     unittest.main()