26 lines
1.2 KiB
Python
26 lines
1.2 KiB
Python
import importlib.util
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
import unittest
|
|
|
|
spec = importlib.util.spec_from_file_location('display_preview', Path(__file__).resolve().parents[1] / 'backend/display_preview.py')
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
|
|
class PositionTests(unittest.TestCase):
|
|
def test_negative_coordinates(self):
|
|
self.assertIn(',-1920x0,', module.monitor_rule('DP-1', '1920x1080@60', '-1920x0', '1', 1))
|
|
|
|
def test_invalid_position(self):
|
|
with self.assertRaises(ValueError):
|
|
module.monitor_rule('DP-1', 'preferred', 'left', '1')
|
|
|
|
def test_preview_validates_coordinate_pair(self):
|
|
with patch.object(module, 'current', return_value={'name':'DP-1','x':0,'y':0,'width':1920,'height':1080,'refreshRate':60,'scale':1,'transform':0}):
|
|
with self.assertRaisesRegex(ValueError, 'вместе'):
|
|
module.preview('DP-1', 'preferred', '1', '0', '10')
|
|
with self.assertRaisesRegex(ValueError, 'координаты'):
|
|
module.preview('DP-1', 'preferred', '1', '0', '999999', '0')
|
|
|
|
if __name__ == '__main__': unittest.main()
|