Merge lp:~brandontschaefer/unity/ibus-ap-fixes into lp:unity

Proposed by Brandon Schaefer
Status: Superseded
Proposed branch: lp:~brandontschaefer/unity/ibus-ap-fixes
Merge into: lp:unity
Diff against target: 206 lines (+47/-26)
1 file modified
tests/autopilot/autopilot/tests/test_ibus.py (+47/-26)
To merge this branch: bzr merge lp:~brandontschaefer/unity/ibus-ap-fixes
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+102803@code.launchpad.net

This proposal has been superseded by a proposal from 2012-04-20.

Commit message

More fixes to the ibus autopilot by reducing the number of times the ime context gets reset.

Description of the change

=== Problem ===
The ibus ap test still fails sometimes when trying to deactivate ibus and the context reseting to many times.

=== Fix ===
Call deactivate instead of adding it to the clean up.

Now the context only resets when changing to a different engine.

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Ran 32 tests in 202.414s
OK

:)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/autopilot/tests/test_ibus.py'
2--- tests/autopilot/autopilot/tests/test_ibus.py 2012-04-19 23:33:18 +0000
3+++ tests/autopilot/autopilot/tests/test_ibus.py 2012-04-20 08:02:18 +0000
4@@ -23,19 +23,26 @@
5
6 def setUp(self):
7 super(IBusTests, self).setUp()
8- self._old_engines = None
9
10 def tearDown(self):
11- if self._old_engines is not None:
12- set_active_engines(self._old_engines)
13 super(IBusTests, self).tearDown()
14
15- def activate_input_engine_or_skip(self, engine_name):
16+ @classmethod
17+ def setUpClass(cls):
18+ cls._old_engines = None
19+
20+ @classmethod
21+ def tearDownClass(cls):
22+ if cls._old_engines is not None:
23+ set_active_engines(cls._old_engines)
24+
25+ @classmethod
26+ def activate_input_engine_or_skip(cls, engine_name):
27 available_engines = get_available_input_engines()
28 if engine_name in available_engines:
29- self._old_engines = set_active_engines([engine_name])
30+ cls._old_engines = set_active_engines([engine_name])
31 else:
32- self.skipTest("This test requires the '%s' engine to be installed." % (engine_name))
33+ raise AutopilotTestCase.skipException("This test requires the '%s' engine to be installed." % (engine_name))
34
35 def activate_ibus(self, widget):
36 """Activate IBus, and wait till it's actived on 'widget'"""
37@@ -49,34 +56,36 @@
38 self.keyboard.press_and_release('Ctrl+Space')
39 self.assertThat(widget.im_active, Eventually(Equals(False)))
40
41- def do_dash_test_with_engine(self, engine_name):
42- self.activate_input_engine_or_skip(engine_name)
43+ def do_dash_test_with_engine(self):
44 self.dash.ensure_visible()
45 self.addCleanup(self.dash.ensure_hidden)
46 self.activate_ibus(self.dash.searchbar)
47- self.addCleanup(self.deactivate_ibus, self.dash.searchbar)
48 self.keyboard.type(self.input)
49 commit_key = getattr(self, 'commit_key', None)
50 if commit_key:
51 self.keyboard.press_and_release(commit_key)
52+ self.deactivate_ibus(self.dash.searchbar)
53 self.assertThat(self.dash.search_string, Eventually(Equals(self.result)))
54
55- def do_hud_test_with_engine(self, engine_name):
56- self.activate_input_engine_or_skip(engine_name)
57+ def do_hud_test_with_engine(self):
58 self.hud.ensure_visible()
59 self.addCleanup(self.hud.ensure_hidden)
60 self.activate_ibus(self.hud.searchbar)
61- self.addCleanup(self.deactivate_ibus, self.hud.searchbar)
62 self.keyboard.type(self.input)
63 commit_key = getattr(self, 'commit_key', None)
64 if commit_key:
65 self.keyboard.press_and_release(commit_key)
66+ self.deactivate_ibus(self.hud.searchbar)
67 self.assertThat(self.hud.search_string, Eventually(Equals(self.result)))
68
69
70 class IBusTestsPinyin(IBusTests):
71 """Tests for the Pinyin(Chinese) input engine."""
72
73+ @classmethod
74+ def setUpClass(cls):
75+ cls.activate_input_engine_or_skip("pinyin")
76+
77 scenarios = [
78 ('basic', {'input': 'abc1', 'result': u'\u963f\u5e03\u4ece'}),
79 ('photo', {'input': 'zhaopian ', 'result': u'\u7167\u7247'}),
80@@ -86,15 +95,19 @@
81 ]
82
83 def test_simple_input_dash(self):
84- self.do_dash_test_with_engine("pinyin")
85+ self.do_dash_test_with_engine()
86
87 def test_simple_input_hud(self):
88- self.do_hud_test_with_engine("pinyin")
89+ self.do_hud_test_with_engine()
90
91
92 class IBusTestsHangul(IBusTests):
93 """Tests for the Hangul(Korean) input engine."""
94
95+ @classmethod
96+ def setUpClass(cls):
97+ cls.activate_input_engine_or_skip("hangul")
98+
99 scenarios = [
100 ('transmission', {'input': 'xmfostmaltus ', 'result': u'\ud2b8\ub79c\uc2a4\ubbf8\uc158 '}),
101 ('social', {'input': 'httuf ', 'result': u'\uc18c\uc15c '}),
102@@ -102,15 +115,19 @@
103 ]
104
105 def test_simple_input_dash(self):
106- self.do_dash_test_with_engine("hangul")
107+ self.do_dash_test_with_engine()
108
109 def test_simple_input_hud(self):
110- self.do_hud_test_with_engine("hangul")
111+ self.do_hud_test_with_engine()
112
113
114 class IBusTestsAnthy(IBusTests):
115 """Tests for the Anthy(Japanese) input engine."""
116
117+ @classmethod
118+ def setUpClass(cls):
119+ cls.activate_input_engine_or_skip("anthy")
120+
121 scenarios = multiply_scenarios(
122 [
123 ('system', {'input': 'shisutemu ', 'result': u'\u30b7\u30b9\u30c6\u30e0'}),
124@@ -124,38 +141,40 @@
125 )
126
127 def test_simple_input_dash(self):
128- self.do_dash_test_with_engine("anthy")
129+ self.do_dash_test_with_engine()
130
131 def test_simple_input_hud(self):
132- self.do_hud_test_with_engine("anthy")
133+ self.do_hud_test_with_engine()
134
135
136 class IBusTestsPinyinIgnore(IBusTests):
137 """Tests for ignoring key events while the Pinyin input engine is active."""
138
139+ @classmethod
140+ def setUpClass(cls):
141+ cls.activate_input_engine_or_skip("pinyin")
142+
143 def test_ignore_key_events_on_dash(self):
144- self.activate_input_engine_or_skip("pinyin")
145 self.dash.ensure_visible()
146 self.addCleanup(self.dash.ensure_hidden)
147 self.activate_ibus(self.dash.searchbar)
148- self.addCleanup(self.deactivate_ibus, self.dash.searchbar)
149 self.keyboard.type("cipan")
150 self.keyboard.press_and_release("Tab")
151 self.keyboard.type(" ")
152+ self.deactivate_ibus(self.dash.searchbar)
153 self.assertThat(self.dash.search_string, Eventually(NotEquals(" ")))
154
155 def test_ignore_key_events_on_hud(self):
156- self.activate_input_engine_or_skip("pinyin")
157 self.hud.ensure_visible()
158 self.addCleanup(self.hud.ensure_hidden)
159
160 self.keyboard.type("a")
161 self.activate_ibus(self.hud.searchbar)
162- self.addCleanup(self.deactivate_ibus, self.hud.searchbar)
163 self.keyboard.type("riqi")
164 old_selected = self.hud.selected_button
165 self.keyboard.press_and_release("Down")
166 new_selected = self.hud.selected_button
167+ self.deactivate_ibus(self.hud.searchbar)
168
169 self.assertEqual(old_selected, new_selected)
170
171@@ -163,29 +182,31 @@
172 class IBusTestsAnthyIgnore(IBusTests):
173 """Tests for ignoring key events while the Anthy input engine is active."""
174
175+ @classmethod
176+ def setUpClass(cls):
177+ cls.activate_input_engine_or_skip("anthy")
178+
179 def test_ignore_key_events_on_dash(self):
180- self.activate_input_engine_or_skip("anthy")
181 self.dash.ensure_visible()
182 self.addCleanup(self.dash.ensure_hidden)
183 self.activate_ibus(self.dash.searchbar)
184- self.addCleanup(self.deactivate_ibus, self.dash.searchbar)
185 self.keyboard.type("shisutemu ")
186 self.keyboard.press_and_release("Tab")
187 self.keyboard.press_and_release("Ctrl+j")
188+ self.deactivate_ibus(self.dash.searchbar)
189 dash_search_string = self.dash.search_string
190
191 self.assertNotEqual("", dash_search_string)
192
193 def test_ignore_key_events_on_hud(self):
194- self.activate_input_engine_or_skip("anthy")
195 self.hud.ensure_visible()
196 self.addCleanup(self.hud.ensure_hidden)
197 self.keyboard.type("a")
198 self.activate_ibus(self.hud.searchbar)
199- self.addCleanup(self.deactivate_ibus, self.hud.searchbar)
200 self.keyboard.type("hiduke")
201 old_selected = self.hud.selected_button
202 self.keyboard.press_and_release("Down")
203 new_selected = self.hud.selected_button
204+ self.deactivate_ibus(self.hud.searchbar)
205
206 self.assertEqual(old_selected, new_selected)