Merge lp:~unity-team/unity/unity.test-special-keys into lp:unity

Proposed by Brandon Schaefer on 2012-03-13
Status: Merged
Approved by: Brandon Schaefer on 2012-03-13
Approved revision: 2108
Merged at revision: 2107
Proposed branch: lp:~unity-team/unity/unity.test-special-keys
Merge into: lp:unity
Diff against target: 284 lines (+69/-25)
2 files modified
tests/autopilot/autopilot/tests/__init__.py (+2/-0)
tests/autopilot/autopilot/tests/test_dash.py (+67/-25)
To merge this branch: bzr merge lp:~unity-team/unity/unity.test-special-keys
Reviewer Review Type Date Requested Status
Thomi Richards (community) 2012-03-13 Approve on 2012-03-13
Review via email: mp+97311@code.launchpad.net
To post a comment you must log in.
Thomi Richards (thomir) wrote :

Hi,

These look great - two small things:

1) Please add "self.dash = Dash()" to AutopilotTest case - you'll see we already have self.launcher and self.switcher etc.

2) please put 'self.dash.ensure_hidden()' into your setup, and remove it from the tests.

3) I'm now being *really* picky, but your docstrings should ideally:
 a) Start with a captial letter and end with a '.'
 b) Describe the test in terms of given input and expected output, so this:

19 + def test_multi_key(self):
20 + """Tests that when the multi_key is pressed it will exepect a sequences"""

would be better written like this:

19 + def test_multi_key(self):
20 + """Pressing Multi_Key must not add add any characters to the search bar."""

and another example - before:

33 + def test_multi_key_o(self):
34 + """Tests the multi_key sequences ^ + o"""

after:

33 + def test_multi_key_o(self):
34 + """Pressing the Multi_Key followed by '^' and 'o' must produce ô."""

Number 3 is something that's good to aim for - I often don't remember to do this myself, but it helps produce tests that are easy to read and verify.

Otherwise, looks great!

2108. By Brandon Schaefer on 2012-03-13

* Fixed using ensure_dash in ALL test cases, now only in setUp and tearDown
* Fixed self.dash = Dash() being used everytime in setUp. Now in AutopilotTest

Thomi Richards (thomir) wrote :

Awesome tests, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/autopilot/tests/__init__.py'
2--- tests/autopilot/autopilot/tests/__init__.py 2012-03-13 03:15:23 +0000
3+++ tests/autopilot/autopilot/tests/__init__.py 2012-03-13 23:19:20 +0000
4@@ -15,6 +15,7 @@
5 import time
6
7 from autopilot.emulators.bamf import Bamf
8+from autopilot.emulators.unity.dash import Dash
9 from autopilot.emulators.unity.launcher import LauncherController
10 from autopilot.emulators.unity.switcher import Switcher
11 from autopilot.emulators.unity.workspace import WorkspaceManager
12@@ -169,6 +170,7 @@
13 self.bamf = Bamf()
14 self.keyboard = Keyboard()
15 self.mouse = Mouse()
16+ self.dash = Dash()
17 self.switcher = Switcher()
18 self.workspace = WorkspaceManager()
19 self.launcher = self._get_launcher_controller()
20
21=== modified file 'tests/autopilot/autopilot/tests/test_dash.py'
22--- tests/autopilot/autopilot/tests/test_dash.py 2012-03-13 07:31:25 +0000
23+++ tests/autopilot/autopilot/tests/test_dash.py 2012-03-13 23:19:20 +0000
24@@ -9,7 +9,6 @@
25 from gtk import Clipboard
26 from time import sleep
27
28-from autopilot.emulators.unity.dash import Dash
29 from autopilot.emulators.X11 import Keyboard, Mouse
30 from autopilot.tests import AutopilotTestCase
31
32@@ -19,7 +18,7 @@
33
34 def setUp(self):
35 super(DashRevealTests, self).setUp()
36- self.dash = Dash()
37+ self.dash.ensure_hidden()
38
39 def tearDown(self):
40 super(DashRevealTests, self).tearDown()
41@@ -27,8 +26,6 @@
42
43 def test_dash_reveal(self):
44 """Ensure we can show and hide the dash."""
45- self.dash.ensure_hidden()
46-
47 self.assertFalse(self.dash.get_is_visible())
48 self.dash.toggle_reveal()
49 self.assertTrue(self.dash.get_is_visible())
50@@ -46,28 +43,24 @@
51
52 def test_application_lens_shortcut(self):
53 """Application lense must reveal when Super+a is pressed."""
54- self.dash.ensure_hidden()
55 self.dash.reveal_application_lens()
56 lensbar = self.dash.view.get_lensbar()
57 self.assertEqual(lensbar.active_lens, u'applications.lens')
58
59 def test_music_lens_shortcut(self):
60 """Music lense must reveal when Super+w is pressed."""
61- self.dash.ensure_hidden()
62 self.dash.reveal_music_lens()
63 lensbar = self.dash.view.get_lensbar()
64 self.assertEqual(lensbar.active_lens, u'music.lens')
65
66 def test_file_lens_shortcut(self):
67 """File lense must reveal when Super+f is pressed."""
68- self.dash.ensure_hidden()
69 self.dash.reveal_file_lens()
70 lensbar = self.dash.view.get_lensbar()
71 self.assertEqual(lensbar.active_lens, u'files.lens')
72
73 def test_command_lens_shortcut(self):
74 """Run Command lens must reveat on alt+F2."""
75- self.dash.ensure_hidden()
76 self.dash.reveal_command_lens()
77 lensbar = self.dash.view.get_lensbar()
78 self.assertEqual(lensbar.active_lens, u'commands.lens')
79@@ -85,7 +78,7 @@
80
81 def setUp(self):
82 super(DashKeyNavTests, self).setUp()
83- self.dash = Dash()
84+ self.dash.ensure_hidden()
85
86 def tearDown(self):
87 super(DashKeyNavTests, self).tearDown()
88@@ -137,7 +130,6 @@
89 """Test that the dash autoscroll when a category header gets
90 the focus.
91 """
92- self.dash.ensure_hidden()
93 self.dash.reveal_application_lens()
94 app_lens = self.dash.get_current_lens()
95
96@@ -185,7 +177,6 @@
97 2. A category header stays highlight when it loses the focus
98 and mouse is close to it (but not inside).
99 """
100- self.dash.ensure_hidden()
101 self.dash.reveal_application_lens()
102
103 kb = Keyboard()
104@@ -218,7 +209,6 @@
105
106 def test_cltr_tab(self):
107 """ This test makes sure that Ctlr + Tab works well."""
108- self.dash.ensure_hidden()
109 self.dash.toggle_reveal()
110
111 kb = Keyboard()
112@@ -241,7 +231,6 @@
113
114 def test_tab(self):
115 """ This test makes sure that Tab works well."""
116- self.dash.ensure_hidden()
117 self.dash.reveal_application_lens()
118 app_lens = self.dash.get_current_lens()
119
120@@ -277,7 +266,7 @@
121
122 def setUp(self):
123 super(DashClipboardTests, self).setUp()
124- self.dash = Dash()
125+ self.dash.ensure_hidden()
126
127 def tearDown(self):
128 super(DashClipboardTests, self).tearDown()
129@@ -285,7 +274,6 @@
130
131 def test_ctrl_a(self):
132 """ This test if ctrl+a selects all text """
133- self.dash.ensure_hidden()
134 self.dash.toggle_reveal()
135
136 kb = Keyboard();
137@@ -300,7 +288,6 @@
138
139 def test_ctrl_c(self):
140 """ This test if ctrl+c copies text into the clipboard """
141- self.dash.ensure_hidden()
142 self.dash.toggle_reveal()
143
144 kb = Keyboard();
145@@ -317,7 +304,6 @@
146
147 def test_ctrl_x(self):
148 """ This test if ctrl+x deletes all text and copys it """
149- self.dash.ensure_hidden()
150 self.dash.toggle_reveal()
151
152 kb = Keyboard();
153@@ -336,7 +322,6 @@
154
155 def test_ctrl_c_v(self):
156 """ This test if ctrl+c and ctrl+v copies and pastes text"""
157- self.dash.ensure_hidden()
158 self.dash.toggle_reveal()
159
160 kb = Keyboard();
161@@ -353,7 +338,6 @@
162
163 def test_ctrl_x_v(self):
164 """ This test if ctrl+x and ctrl+v cuts and pastes text"""
165- self.dash.ensure_hidden()
166 self.dash.toggle_reveal()
167
168 kb = Keyboard();
169@@ -374,7 +358,7 @@
170
171 def setUp(self):
172 super(DashKeyboardFocusTests, self).setUp()
173- self.dash = Dash()
174+ self.dash.ensure_hidden()
175
176 def tearDown(self):
177 super(DashKeyboardFocusTests, self).tearDown()
178@@ -401,7 +385,7 @@
179
180 def setUp(self):
181 super(DashLensResultsTests, self).setUp()
182- self.dash = Dash()
183+ self.dash.ensure_hidden()
184
185 def tearDown(self):
186 super(DashLensResultsTests, self).tearDown()
187@@ -409,7 +393,6 @@
188
189 def test_results_message_empty_search(self):
190 """ This tests a message is not shown when there is no text"""
191- self.dash.ensure_hidden()
192 self.dash.reveal_application_lens()
193 lens = self.dash.get_current_lens()
194
195@@ -418,7 +401,6 @@
196
197 def test_results_message(self):
198 """ This test no mesage will be shown when results are there"""
199- self.dash.ensure_hidden()
200 self.dash.reveal_application_lens()
201 lens = self.dash.get_current_lens()
202
203@@ -431,7 +413,6 @@
204
205 def test_no_results_message(self):
206 """ This test shows a message will appear in the lens"""
207- self.dash.ensure_hidden()
208 self.dash.reveal_application_lens()
209 lens = self.dash.get_current_lens()
210
211@@ -446,7 +427,7 @@
212 """Tests that the dash visual is correct."""
213 def setUp(self):
214 super(DashVisualTests, self).setUp()
215- self.dash = Dash()
216+ self.dash.ensure_hidden()
217
218 def tearDown(self):
219 super(DashVisualTests, self).tearDown()
220@@ -465,3 +446,64 @@
221 if (group.is_visible):
222 self.assertTrue(not group.expand_label_is_visible or
223 (group.expand_label_y + group.expand_label_baseline == group.name_label_y + group.name_label_baseline))
224+
225+class DashSpecialKeysTests(AutopilotTestCase):
226+ """Tests composition sequences, dead keys or any other special keys."""
227+ def setUp(self):
228+ super(DashSpecialKeysTests, self).setUp()
229+ self.dash.ensure_hidden()
230+
231+ def tearDown(self):
232+ super(DashSpecialKeysTests, self).tearDown()
233+ self.dash.ensure_hidden()
234+
235+ def test_multi_key(self):
236+ """Pressing 'Multi_key' must not add any characters to the search."""
237+ self.dash.reveal_application_lens()
238+
239+ kb = Keyboard();
240+ kb.press_and_release('Multi_key')
241+ kb.type("o")
242+ sleep(1)
243+
244+ searchbar = self.dash.get_searchbar()
245+ self.assertEqual("", searchbar.search_string)
246+
247+ def test_multi_key_o(self):
248+ """Pressing the sequences 'Multi_key' + '^' + 'o' must produce 'ô'."""
249+ self.dash.reveal_application_lens()
250+
251+ kb = Keyboard();
252+ kb.press_and_release('Multi_key')
253+ kb.type("^o")
254+ sleep(1)
255+
256+ searchbar = self.dash.get_searchbar()
257+ self.assertEqual("ô", searchbar.search_string)
258+
259+ def test_multi_key_copyright(self):
260+ """Pressing the sequences 'Multi_key' + 'c' + 'o' must produce '©'."""
261+ self.dash.reveal_application_lens()
262+
263+ kb = Keyboard();
264+ kb.press_and_release('Multi_key')
265+ kb.type("oc")
266+ sleep(1)
267+
268+ searchbar = self.dash.get_searchbar()
269+ self.assertEqual("©", searchbar.search_string)
270+
271+ def test_multi_key_delete(self):
272+ """Pressing 'Multi_key' must not get stuck looking for a sequence."""
273+ self.dash.reveal_application_lens()
274+
275+ kb = Keyboard();
276+ kb.type("dd")
277+ sleep(1)
278+ kb.press_and_release('Multi_key')
279+ kb.press_and_release('BackSpace')
280+ kb.press_and_release('BackSpace')
281+ sleep(1)
282+
283+ searchbar = self.dash.get_searchbar()
284+ self.assertEqual("d", searchbar.search_string)