Merge lp:~brandontschaefer/unity/move-ibus-emulator-from-autopilot into lp:unity

Proposed by Brandon Schaefer on 2013-08-05
Status: Merged
Approved by: Brandon Schaefer on 2013-08-11
Approved revision: 3453
Merged at revision: 3460
Proposed branch: lp:~brandontschaefer/unity/move-ibus-emulator-from-autopilot
Merge into: lp:unity
Diff against target: 135 lines (+114/-3)
2 files modified
tests/autopilot/unity/emulators/ibus.py (+113/-0)
tests/autopilot/unity/tests/test_ibus.py (+1/-3)
To merge this branch: bzr merge lp:~brandontschaefer/unity/move-ibus-emulator-from-autopilot
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve on 2013-08-12
Christopher Townsend 2013-08-05 Approve on 2013-08-09
Review via email: mp+178614@code.launchpad.net

Commit message

Add ibus.py to the tests/autopilot/unity/emulators from lp:autopilot.

Description of the change

Add ibus.py to the tests/autopilot/unity/emulators from lp:autopilot. As this is where it'll live now :)

To post a comment you must log in.
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Marco Trevisan (Treviño) (3v1n0) wrote :

Mh, ok...

After this would you reconsider to add back what reverted in http://http://bazaar.launchpad.net/~unity-team/unity/trunk/revision/3449?

Marco Trevisan (Treviño) (3v1n0) wrote :

Mh, I've also noticed that the release tests I added in 2591 have been removed... Could we try to re-add them? As I remember that some people complained that the release key support was broken, so we should ensure it keeps working...

Brandon Schaefer (brandontschaefer) wrote :

@ Marco

What I removed in 3449 has to be re implemented, not just added back in... ibus 1.5 no longer users gconf and it was causing tests to fail. So we need to figure out how to correctly set hot keys now using gsettings + python, which I need to spend time digging into....

Christopher Townsend (townsend) wrote :

@ Marco,

Brandon has added https://bugs.launchpad.net/ubuntu/+source/unity/+bug/1210658 about the tests removed in rev. 3449. We are not 100% sure which tests you say have been removed that you added in rev. 2591. Could you open a new bug open those?

Otherwise, this looks good and is needed to get the ibus tests into Unity.

review: Approve
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'tests/autopilot/unity/emulators/ibus.py'
2--- tests/autopilot/unity/emulators/ibus.py 1970-01-01 00:00:00 +0000
3+++ tests/autopilot/unity/emulators/ibus.py 2013-08-05 17:55:40 +0000
4@@ -0,0 +1,113 @@
5+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
6+#
7+# Autopilot Functional Test Tool
8+# Copyright (C) 2012-2013 Canonical
9+#
10+# This program is free software: you can redistribute it and/or modify
11+# it under the terms of the GNU General Public License as published by
12+# the Free Software Foundation, either version 3 of the License, or
13+# (at your option) any later version.
14+#
15+# This program is distributed in the hope that it will be useful,
16+# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+# GNU General Public License for more details.
19+#
20+# You should have received a copy of the GNU General Public License
21+# along with this program. If not, see <http://www.gnu.org/licenses/>.
22+#
23+
24+
25+"""Functions to deal with ibus service."""
26+
27+from __future__ import absolute_import
28+
29+from gi.repository import IBus, GLib
30+import os
31+import logging
32+import subprocess
33+
34+
35+logger = logging.getLogger(__name__)
36+
37+
38+def get_ibus_bus():
39+ """Get the ibus bus object, possibly starting the ibus daemon if it's
40+ not already running.
41+
42+ :raises: **RuntimeError** in the case of ibus-daemon being unavailable.
43+
44+ """
45+ bus = IBus.Bus()
46+ if bus.is_connected():
47+ return bus
48+
49+ main_loop = GLib.MainLoop()
50+
51+ timeout = 5
52+ GLib.timeout_add_seconds(timeout, lambda *args: main_loop.quit())
53+ bus.connect("connected", lambda *args: main_loop.quit())
54+
55+ os.spawnlp(os.P_NOWAIT, "ibus-daemon", "ibus-daemon", "--xim")
56+
57+ main_loop.run()
58+
59+ if not bus.is_connected():
60+ raise RuntimeError(
61+ "Could not start ibus-daemon after %d seconds." % (timeout))
62+ return bus
63+
64+
65+def get_available_input_engines():
66+ """Get a list of available input engines."""
67+ bus = get_ibus_bus()
68+ return [e.get_name() for e in bus.list_engines()]
69+
70+
71+def get_active_input_engines():
72+ """Get the list of input engines that have been activated."""
73+ bus = get_ibus_bus()
74+ return [e.get_name() for e in bus.list_active_engines()]
75+
76+
77+def set_active_engines(engine_list):
78+ """Installs the engines in *engine_list* into the list of active iBus
79+ engines.
80+
81+ The specified engines must appear in the return list from
82+ get_available_input_engines().
83+
84+ .. note:: This function removes all other engines.
85+
86+ This function returns the list of engines installed before this function
87+ was called. The caller should pass this list to set_active_engines to
88+ restore ibus to it's old state once the test has finished.
89+
90+ :param engine_list: List of engine names
91+ :type engine_list: List of strings
92+ :raises: **TypeError** on invalid *engine_list* parameter.
93+ :raises: **ValueError** when engine_list contains invalid engine name.
94+
95+ """
96+ if type(engine_list) is not list:
97+ raise TypeError("engine_list must be a list of valid engine names.")
98+ available_engines = get_available_input_engines()
99+ for engine in engine_list:
100+ if not isinstance(engine, basestring):
101+ raise TypeError("Engines in engine_list must all be strings.")
102+ if engine not in available_engines:
103+ raise ValueError(
104+ "engine_list contains invalid engine name: '%s'", engine)
105+
106+ bus = get_ibus_bus()
107+ config = bus.get_config()
108+
109+ config.set_value("general",
110+ "preload_engine_mode",
111+ GLib.Variant.new_int32(IBus.PreloadEngineMode.USER))
112+
113+ old_engines = get_active_input_engines()
114+ config.set_value(
115+ "general", "preload_engines", GLib.Variant("as", engine_list))
116+
117+ return old_engines
118
119=== modified file 'tests/autopilot/unity/tests/test_ibus.py'
120--- tests/autopilot/unity/tests/test_ibus.py 2013-08-01 15:58:22 +0000
121+++ tests/autopilot/unity/tests/test_ibus.py 2013-08-05 17:55:40 +0000
122@@ -10,12 +10,10 @@
123
124 from __future__ import absolute_import
125
126-from autopilot.ibus import (
127+from unity.emulators.ibus import (
128 get_active_input_engines,
129 set_active_engines,
130 get_available_input_engines,
131- get_gconf_option,
132- set_gconf_option,
133 get_ibus_bus,
134 )
135 from autopilot.matchers import Eventually