AkurAI Build
Menu

cosmic-mobile

public

Latest change 638621fcb5ab2fdbcab08fefcde87ee712b2489c - Assert move validates bounds before connecting by AkurAI Build

import importlib.util
import unittest
from pathlib import Path
spec = importlib.util.spec_from_file_location('qmp', Path(__file__).resolve().parents[1] / 'qmp.py')
assert spec is not None and spec.loader is not None
qmp = importlib.util.module_from_spec(spec)
spec.loader.exec_module(qmp)

class InputTests(unittest.TestCase):
    def test_tap_bounds_and_scaling(self):
        events = qmp.tap_events(449, 989, 450, 990)
        self.assertEqual(events[0]['data']['value'], 32767)
        self.assertEqual(events[1]['data']['value'], 32767)
        with self.assertRaises(ValueError): qmp.tap_events(450, 0, 450, 990)
    def test_text_validation_before_input(self):
        self.assertEqual(qmp.text_keys('A!\n'), ['shift-a', 'shift-1', 'ret'])
        with self.assertRaises(ValueError): qmp.text_keys('hello þ')

    def test_move_is_pointer_only(self):
        import sys
        sys.argv = ['qmp.py', 'move', '10', '20', '--socket', '/nonexistent']
        with self.assertRaises(OSError): qmp.main()
        sys.argv = ['qmp.py', 'move', '5000', '20', '--socket', '/nonexistent']
        with self.assertRaises(ValueError): qmp.main()

if __name__ == '__main__': unittest.main()