Merge lp:~canonical-platform-qa/autopilot/add_osk_show_workaround into lp:autopilot

Proposed by Christopher Lee on 2015-07-16
Status: Merged
Approved by: Christopher Lee on 2015-07-16
Approved revision: 572
Merged at revision: 565
Proposed branch: lp:~canonical-platform-qa/autopilot/add_osk_show_workaround
Merge into: lp:autopilot
Diff against target: 195 lines (+131/-4)
4 files modified
autopilot/_fixtures.py (+67/-0)
autopilot/testcase.py (+6/-0)
autopilot/tests/unit/test_fixtures.py (+57/-4)
debian/control (+1/-0)
To merge this branch: bzr merge lp:~canonical-platform-qa/autopilot/add_osk_show_workaround
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve on 2015-07-16
Autopilot Hackers 2015-07-16 Pending
Review via email: mp+264944@code.launchpad.net

Commit message

Add fixture that forces a gsetting for unity8 so that OSK is shown even when a UInput keyboard is present.

Description of the change

Add fixture that forces a gsetting for unity8 so that OSK is shown even when a UInput keyboard is present.

To post a comment you must log in.
570. By Christopher Lee on 2015-07-16

Fix patch/mock import

571. By Christopher Lee on 2015-07-16

Add build-dep for building in CI etc.

572. By Christopher Lee on 2015-07-16

Be explicit in gsettings path

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'autopilot/_fixtures.py'
2--- autopilot/_fixtures.py 2014-07-09 03:09:29 +0000
3+++ autopilot/_fixtures.py 2015-07-16 03:26:52 +0000
4@@ -18,6 +18,11 @@
5 #
6
7 from fixtures import Fixture
8+import logging
9+import subprocess
10+
11+
12+logger = logging.getLogger(__name__)
13
14
15 class FixtureWithDirectAddDetail(Fixture):
16@@ -40,3 +45,65 @@
17 """
18 super().__init__()
19 self.caseAddDetail = caseAddDetail or self.addDetail
20+
21+
22+class OSKAlwaysEnabled(Fixture):
23+ """Enable the OSK to be shown regardless of if there is a keyboard (virtual
24+ or real) plugged in.
25+
26+ This is a workaround for bug lp:1474444
27+
28+ """
29+
30+ osk_schema = 'com.canonical.keyboard.maliit'
31+ osk_show_key = 'stay-hidden'
32+
33+ def __init__(self):
34+ super().__init__()
35+ self._original_value = get_gsettings_value(
36+ self.osk_schema,
37+ self.osk_show_key
38+ )
39+
40+ def setUp(self):
41+ super().setUp()
42+ set_gsettings_value(self.osk_schema, self.osk_show_key, 'false')
43+ self.addCleanup(
44+ set_gsettings_value,
45+ self.osk_schema,
46+ self.osk_show_key,
47+ self._original_value
48+ )
49+
50+
51+def get_gsettings_value(schema, key):
52+ """Return the output of gsettings get as a string or None if the call
53+ fails.
54+
55+ """
56+ command = ['/usr/bin/gsettings', 'get', schema, key]
57+ try:
58+ output = subprocess.check_output(
59+ command,
60+ stderr=subprocess.PIPE,
61+ universal_newlines=True
62+ )
63+ return output.rstrip('\n')
64+ except subprocess.CalledProcessError as e:
65+ logger.warning(
66+ 'Failed to get gsettings value for {schema}/{key}: {error}'.format(
67+ schema=schema, key=key, error=e.output
68+ )
69+ )
70+
71+
72+def set_gsettings_value(schema, key, value):
73+ command = ['/usr/bin/gsettings', 'set', schema, key, value]
74+ try:
75+ subprocess.check_output(command, stderr=subprocess.PIPE)
76+ except subprocess.CalledProcessError as e:
77+ logger.warning(
78+ 'Failed to set gsettings value {sch}/{key} to {v}: {error}'.format(
79+ sch=schema, key=key, v=value, error=e.output
80+ )
81+ )
82
83=== modified file 'autopilot/testcase.py'
84--- autopilot/testcase.py 2015-07-15 21:18:42 +0000
85+++ autopilot/testcase.py 2015-07-16 03:26:52 +0000
86@@ -69,6 +69,7 @@
87 from autopilot.platform import get_display_server
88 from autopilot.process import ProcessManager
89 from autopilot.utilities import deprecated, on_test_started
90+from autopilot._fixtures import OSKAlwaysEnabled
91 from autopilot._timeout import Timeout
92 from autopilot._logging import TestCaseLoggingFixture
93 from autopilot._video import get_video_recording_fixture
94@@ -164,6 +165,11 @@
95 self._display = None
96 self._kb = Keyboard.create()
97
98+ # Instatiate this after keyboard creation to ensure it doesn't get
99+ # overwritten
100+ # Workaround for bug lp:1474444
101+ self.useFixture(OSKAlwaysEnabled())
102+
103 # Work around for bug lp:1297592.
104 _ensure_uinput_device_created()
105
106
107=== modified file 'autopilot/tests/unit/test_fixtures.py'
108--- autopilot/tests/unit/test_fixtures.py 2014-07-09 03:04:46 +0000
109+++ autopilot/tests/unit/test_fixtures.py 2015-07-16 03:26:52 +0000
110@@ -19,16 +19,69 @@
111
112
113 from testtools import TestCase
114-
115-from autopilot._fixtures import FixtureWithDirectAddDetail
116+from testtools.matchers import (
117+ Not,
118+ Raises,
119+)
120+from unittest.mock import patch
121+import autopilot._fixtures as ap_fixtures
122
123
124 class FixtureWithDirectAddDetailTests(TestCase):
125
126 def test_sets_caseAddDetail_method(self):
127- fixture = FixtureWithDirectAddDetail(self.addDetail)
128+ fixture = ap_fixtures.FixtureWithDirectAddDetail(self.addDetail)
129 self.assertEqual(fixture.caseAddDetail, self.addDetail)
130
131 def test_can_construct_without_arguments(self):
132- fixture = FixtureWithDirectAddDetail()
133+ fixture = ap_fixtures.FixtureWithDirectAddDetail()
134 self.assertEqual(fixture.caseAddDetail, fixture.addDetail)
135+
136+
137+class GSettingsAccessTests(TestCase):
138+
139+ def test_incorrect_schema_doesnt_raise_exception(self):
140+ self.assertThat(
141+ lambda: ap_fixtures.get_gsettings_value('foo', 'bar'),
142+ Not(Raises())
143+ )
144+
145+ def test_get_value_returns_expected_value(self):
146+ with patch.object(ap_fixtures.subprocess, 'check_output') as check_out:
147+ check_out.return_value = 'buzz'
148+ self.assertEqual(
149+ ap_fixtures.get_gsettings_value('foo', 'bar'),
150+ 'buzz'
151+ )
152+
153+ def test_get_value_strips_newline(self):
154+ with patch.object(ap_fixtures.subprocess, 'check_output') as check_out:
155+ check_out.return_value = 'buzz\n'
156+ self.assertEqual(
157+ ap_fixtures.get_gsettings_value('foo', 'bar'),
158+ 'buzz'
159+ )
160+
161+
162+class OSKAlwaysEnabledTests(TestCase):
163+
164+ def test_sets_stayhidden_to_false(self):
165+ with patch.object(ap_fixtures, 'set_gsettings_value') as set_gsetting:
166+ with ap_fixtures.OSKAlwaysEnabled():
167+ set_gsetting.assert_called_once_with(
168+ 'com.canonical.keyboard.maliit',
169+ 'stay-hidden',
170+ 'false'
171+ )
172+
173+ def test_resets_value_to_original(self):
174+ with patch.object(ap_fixtures, 'set_gsettings_value') as set_gset:
175+ with patch.object(ap_fixtures, 'get_gsettings_value') as get_gset:
176+ get_gset.return_value = 'foo'
177+ with ap_fixtures.OSKAlwaysEnabled():
178+ pass
179+ set_gset.assert_called_with(
180+ 'com.canonical.keyboard.maliit',
181+ 'stay-hidden',
182+ 'foo'
183+ )
184
185=== modified file 'debian/control'
186--- debian/control 2015-03-18 17:24:48 +0000
187+++ debian/control 2015-07-16 03:26:52 +0000
188@@ -11,6 +11,7 @@
189 gir1.2-ibus-1.0,
190 gir1.2-ubuntu-app-launch-2 | gir1.2-upstart-app-launch-2,
191 graphviz,
192+ libglib2.0-bin,
193 libjs-jquery,
194 libjs-underscore,
195 liblttng-ust-dev,

Subscribers

People subscribed via source and target branches