File: test_xlib_display.py

package info (click to toggle)
python-xlib 0.33-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,040 kB
  • sloc: python: 23,022; awk: 89; makefile: 60; sh: 10
file content (173 lines) | stat: -rw-r--r-- 6,595 bytes parent folder | download | duplicates (3)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python

import sys
import os
import unittest

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

import Xlib.display
import Xlib.error
import Xlib.protocol.display
import Xlib.protocol.event
import Xlib.protocol.rq
import Xlib.xobject.fontable
import Xlib.X


class TestXlibDisplay(unittest.TestCase):
    def setUp(self):
        # Create authority file.
        self.display_num = os.getenv("DISPLAY")
        self.display = Xlib.display.Display(self.display_num)
        self.dummy_str = "qqq"
        self.keysym = 65535

    def test_display_instance(self):
        self.assertTrue(isinstance(self.display, Xlib.display.Display))

    def test_default_display_name(self):
        self.assertEqual(self.display.get_display_name(), self.display_num)

    def test_default_screen_number(self):
        self.assertEqual(self.display.get_default_screen(), 0)

    def test_returns_no_events(self):
        self.assertEqual(self.display.pending_events(), 0)

    def test_pointer_mapping_is_list(self):
        self.assertTrue(isinstance(self.display.get_pointer_mapping(), list))

    def test_set_get_pointer_mapping(self):
        orig_mapping = self.display.get_pointer_mapping()
        length = len(orig_mapping)
        try:
            self.display.set_pointer_mapping([0] * length)
            self.assertEqual(self.display.get_pointer_mapping(), [0] * length)
        finally:
            self.display.set_pointer_mapping(orig_mapping)

    def test_can_close_display(self):
        self.display.close()
        self.assertEqual(str(self.display.display.socket_error), "Display connection closed by client")

    def test_can_close_display_and_check_for_error(self):
        with self.assertRaises(Xlib.error.ConnectionClosedError):
            self.display.close()
            self.display.flush()

    def test_return_fileno(self):
        self.assertTrue(isinstance(self.display.fileno(), int))

    def test_has_no_invalid_extension(self):
        self.assertTrue(~self.display.has_extension(self.dummy_str))

    def test_has_valid_extension(self):
        extensions = self.display.list_extensions()
        if extensions:
            self.assertTrue(~self.display.has_extension(extensions[0]))

    def test_can_create_resource_object(self):
        self.assertTrue(
            isinstance(self.display.create_resource_object("font", 0), Xlib.xobject.fontable.Font))

    def test_get_default_screen_instance(self):
        self.assertTrue(isinstance(self.display.screen(), Xlib.protocol.rq.DictWrapper))

    def test_get_zero_screen_instance(self):
        self.assertTrue(isinstance(self.display.screen(0), Xlib.protocol.rq.DictWrapper))

    def test_default_screen_count(self):
        self.assertEqual(self.display.screen_count(), 1)

    def test_cannot_add_existing_display_method(self):
        self.assertRaises(AssertionError, self.display.extension_add_method,
                          "display", "extension_add_method", lambda x: x)

    def test_cannot_add_existing_font_method(self):
        self.assertRaises(AssertionError, self.display.extension_add_method, "font", "__init__", lambda x: x)

    def test_can_add_extension_error(self):
        self.display.extension_add_error(1, Xlib.error.XError)
        self.assertEqual(self.display.display.error_classes[1], Xlib.error.XError)

    def test_keycode_to_keysym_for_invalid_index(self):
        self.assertEqual(self.display.keycode_to_keysym(0, 0), Xlib.X.NoSymbol)

    def test_keysym_to_keycode_for_nosymbol(self):
        self.assertEqual(self.display.keysym_to_keycode(Xlib.X.NoSymbol), 0)

    def test_keysym_to_keycode_for_valid_symbol(self):
        self.assertEqual(self.display.keysym_to_keycode(self.keysym), 119)

    def test_keysym_to_keycodes_for_nosymbol(self):
        self.assertEqual(self.display.keysym_to_keycodes(Xlib.X.NoSymbol), [])

    def test_refresh_keyboard_mapping_invalid_event(self):
        self.assertRaises(TypeError, self.display.refresh_keyboard_mapping, Xlib.protocol.event.AnyEvent)

    def test_get_modifier_mapping(self):
        self.assertEqual(len(self.display.get_modifier_mapping()), 8)

    def test_set_modifier_mapping(self):
        mapping = self.display.get_modifier_mapping()
        self.assertEqual(self.display.set_modifier_mapping(mapping), Xlib.X.MappingSuccess)

    def test_get_screensaver(self):
        self.assertTrue(isinstance(self.display.get_screen_saver(), Xlib.protocol.request.GetScreenSaver))

    def test_list_hosts(self):
        self.assertTrue(isinstance(self.display.list_hosts(), Xlib.protocol.request.ListHosts))

    def test_get_keyboard_control(self):
        self.assertTrue(
            isinstance(self.display.get_keyboard_control(), Xlib.protocol.request.GetKeyboardControl))

    def test_change_keyboard_mapping(self):
        kpt_mapping = self.display.get_keyboard_mapping(254, 1)
        self.display.change_keyboard_mapping(254, kpt_mapping)
        self.assertEqual(self.display.get_keyboard_mapping(254, 1), kpt_mapping)

    def test_get_font_path(self):
        self.assertNotEqual(self.display.get_font_path(), [])

    def test_get_atom_name(self):
        atom = self.display.get_atom(self.display_num)
        val = self.display.get_atom_name(atom)
        self.assertEqual(val, self.display_num)

    def test_intern_atom(self):
        atom = self.display.intern_atom(self.display_num)
        val = self.display.get_atom_name(atom)
        self.assertEqual(val, self.display_num)

    def test_get_input_focus(self):
        self.assertTrue(isinstance(self.display.get_input_focus(), Xlib.protocol.request.GetInputFocus))

    def test_query_keymap(self):
        self.assertTrue(isinstance(self.display.query_keymap(), list))

    def test_open_invalid_font(self):
        self.assertEqual(self.display.open_font(self.dummy_str), None)

    def test_list_fonts(self):
        fonts = self.display.list_fonts("*", 1)
        self.assertNotEqual(fonts, [])

    def test_lookup_valid_keysym(self):
        self.assertNotEqual(self.display.lookup_string(self.keysym), None)

    def test_lookup_invalid_keysym(self):
        self.assertEqual(self.display.lookup_string(-1), None)

    def test_rebind_string(self):
        self.display.rebind_string(self.keysym, self.dummy_str)
        self.assertEqual(self.display.lookup_string(self.keysym), self.dummy_str)

    def test_get_selection_owner(self):
        atom = self.display.get_atom(self.display_num)
        self.assertEqual(self.display.get_selection_owner(atom), 0)


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