File: test_rawinput.py

package info (click to toggle)
dogtail 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,108 kB
  • sloc: python: 8,020; makefile: 45; sh: 7
file content (129 lines) | stat: -rw-r--r-- 3,914 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/python3
"""
Unit tests for the dogtail.rawinput.
"""

# pylint: disable=import-outside-toplevel

import unittest
from dogtail.rawinput import (
    absolute_motion,
    absolute_motion_with_trajectory,
    check_coordinates,
    click,
    double_click,
    press,
    release,
)


class TestRawinput(unittest.TestCase):
    """
    Class to test dogtail's rawinput.
    """

    def test_absolute_motion(self):
        """
        Testing absolute_motion.
        """

        absolute_motion(50, 50)
        absolute_motion(100, 100)
        absolute_motion(150, 150)
        absolute_motion(200, 200)
        absolute_motion(200, 200, mouse_delay=1)
        absolute_motion(200, 200, mouse_delay=1, check=True)
        absolute_motion(-200, -200, mouse_delay=1, check=False)

    def test_motion_with_trajectory(self):
        """
        Testing absolute_motion_with_trajectory.
        """

        absolute_motion_with_trajectory(100, 100, 110, 110)
        absolute_motion_with_trajectory(110, 110, 120, 120)
        absolute_motion_with_trajectory(120, 120, 130, 130)
        absolute_motion_with_trajectory(130, 130, 150, 150, mouse_delay=0.1)

    def test_check_coordinates_directly(self):
        """
        Testing check_coordinates directly.
        """

        check_coordinates(0, 0)
        check_coordinates(-0, -0)
        check_coordinates(10, 0)
        check_coordinates(0, 10)

        # There are shadows which can be in negative, but that does not mean a bug.
        # We set the limits to (-50,-50), most issues are way over this value.
        with self.assertRaises(ValueError):
            check_coordinates(-100, 100)

        with self.assertRaises(ValueError):
            check_coordinates(100, -100)

        with self.assertRaises(ValueError):
            check_coordinates(-100, -100)

    def test_check_coordinates_in_methods(self):
        """
        Testing check_coordinates in methods.
        """

        # There are shadows which can be in negative, but that does not mean a bug.
        # We set the limits to (-50,-50), most issues are way over this value.

        # Absolute Motion.
        with self.assertRaises(ValueError):
            absolute_motion(-100, 100)
        with self.assertRaises(ValueError):
            absolute_motion(100, -100)
        with self.assertRaises(ValueError):
            absolute_motion(-100, -100)

        # Absolute Motion With Trajectory.
        with self.assertRaises(ValueError):
            absolute_motion_with_trajectory(-100, 100, 100, 100)
        with self.assertRaises(ValueError):
            absolute_motion_with_trajectory(100, -100, 100, 100)
        with self.assertRaises(ValueError):
            absolute_motion_with_trajectory(100, 100, -100, 100)
        with self.assertRaises(ValueError):
            absolute_motion_with_trajectory(100, 100, 100, -100)

        # Click.
        with self.assertRaises(ValueError):
            click(-100, 100)
        with self.assertRaises(ValueError):
            click(100, -100)
        with self.assertRaises(ValueError):
            click(-100, -100)

        # Double Click.
        with self.assertRaises(ValueError):
            double_click(-100, 100)
        with self.assertRaises(ValueError):
            double_click(100, -100)
        with self.assertRaises(ValueError):
            double_click(-100, -100)

        # Press.
        with self.assertRaises(ValueError):
            press(-100, 100)
        with self.assertRaises(ValueError):
            press(100, -100)
        with self.assertRaises(ValueError):
            press(-100, -100)

        # Release.
        with self.assertRaises(ValueError):
            release(-100, 100)
        with self.assertRaises(ValueError):
            release(100, -100)
        with self.assertRaises(ValueError):
            release(-100, -100)


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