Merge lp:~thomir-deactivatedaccount/unity/ibus-ap-fixes into lp:unity

Proposed by Thomi Richards
Status: Merged
Approved by: Thomi Richards
Approved revision: no longer in the source branch.
Merged at revision: 2323
Proposed branch: lp:~thomir-deactivatedaccount/unity/ibus-ap-fixes
Merge into: lp:unity
Diff against target: 197 lines (+38/-26)
1 file modified
tests/autopilot/autopilot/tests/test_ibus.py (+38/-26)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/unity/ibus-ap-fixes
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) Approve
Thomi Richards (community) Approve
Review via email: mp+102808@code.launchpad.net

This proposal supersedes a proposal from 2012-04-20.

Commit message

Update IBus tests to only set the IME once per test case class.

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 : Posted in a previous version of this proposal

Ran 32 tests in 202.414s
OK

:)

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

I approve brandon's code :)

review: Approve
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

+1

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