Debian Codegraph @

tests/interactive/window/test_window_modes.py

raw symbols SCIP
1 import pytest
2 import time
3
4 from tests.annotations import Platform, require_platform
5 from tests.base.interactive import InteractiveTestCase
6 from tests.interactive.window import window_util
7
8 from pyglet import window
9 from pyglet.gl import *
10 from pyglet.window.event import WindowEventLogger
11
12 @pytest.mark.requires_user_validation
13 class WINDOW_MINIMIZE_MAXIMIZE(InteractiveTestCase):
14 """Test that window can be minimized and maximized.
15
16 Expected behaviour:
17 One window will be opened. It will be maximized and minimized.
18 """
19 def test_minimize_maximize(self):
20 self.width, self.height = 200, 200
21 self.w = w = window.Window(self.width, self.height, resizable=True)
22 try:
23 w.dispatch_events()
24 self.user_verify('Is the window visible and not maximized?',
25 take_screenshot=False)
26
27 w.maximize()
28 w.dispatch_events()
29 self.user_verify('Is the window maximized?',
30 take_screenshot=False)
31
32 w.minimize()
33 w.dispatch_events()
34 self.user_verify('Is the window minimized?',
35 take_screenshot=False)
36
37 finally:
38 w.close()
39
40
41 @pytest.mark.requires_user_action
42 class WINDOW_ACTIVATE(InteractiveTestCase):
43 """Test that the window can be activated (focus set).
44
45 Expected behaviour:
46 One window will be opened. Every 5 seconds it will be activated;
47 it should be come to the front and accept keyboard input (this will
48 be shown on the terminal).
49
50 On some OSes, the taskbar icon may flash (indicating the application
51 requires attention) rather than moving the window to the foreground. This
52 is the correct behaviour.
53
54 Press escape or close the window to finished the test.
55 """
56 def test_activate(self):
57 w = window.Window(200, 200)
58 try:
59 w.push_handlers(WindowEventLogger())
60 last_time = time.time()
61 while not w.has_exit:
62 if time.time() - last_time > 5:
63 w.activate()
64 last_time = time.time()
65 print('Activated window.')
66 w.dispatch_events()
67 finally:
68 w.close()
69 self.user_verify('Pass test?', take_screenshot=False)
70
71
72 @pytest.mark.requires_user_action
73 class WINDOW_RESIZABLE(InteractiveTestCase):
74 """Test that window can be resized.
75
76 Expected behaviour:
77 One window will be opened. It should be resizable by the user.
78
79 Close the window or press ESC to end the test.
80 """
81 def test_resizable(self):
82 self.width, self.height = 200, 200
83 self.w = w = window.Window(self.width, self.height, resizable=True)
84 try:
85 glClearColor(1, 1, 1, 1)
86 while not w.has_exit:
87 window_util.draw_client_border(w)
88 w.flip()
89 w.dispatch_events()
90 finally:
91 w.close()
92 self.user_verify('Pass test?', take_screenshot=False)
93
94
95 @pytest.mark.requires_user_action
96 @require_platform(Platform.WINDOWS + Platform.OSX)
97 class WINDOW_MODE_SWITCH(InteractiveTestCase):
98 """Test switching to available screen modes."""
99 def on_text(self, text):
100 text = text[:1]
101 i = ord(text) - ord('a')
102 if 0 <= i < len(self.modes):
103 print('Switching to %s' % self.modes[i])
104 self.w.screen.set_mode(self.modes[i])
105
106 def on_expose(self):
107 glClearColor(1, 0, 0, 1)
108 glClear(GL_COLOR_BUFFER_BIT)
109 window_util.draw_client_border(self.w)
110 self.w.flip()
111
112 def test_set_fullscreen(self):
113 self.w = w = window.Window(200, 200)
114 try:
115 self.modes = w.screen.get_modes()
116 self.assertTrue(len(self.modes) > 0, msg='No modes available')
117 print('Press a letter to switch to the corresponding mode:')
118 for i, mode in enumerate(self.modes):
119 print('%s: %s' % (chr(i + ord('a')), mode))
120
121 w.push_handlers(self)
122 self.on_expose()
123 while not w.has_exit:
124 w.dispatch_events()
125 finally:
126 w.close()
127 self.user_verify('Pass test?', take_screenshot=False)