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

Proposed by Christopher Lee
Status: Merged
Approved by: Jean-Baptiste Lallement
Approved revision: 571
Merged at revision: 566
Proposed branch: lp:~canonical-platform-qa/autopilot/depends_for_gsettings
Merge into: lp:autopilot
Diff against target: 240 lines (+92/-80)
3 files modified
autopilot/_fixtures.py (+60/-49)
autopilot/tests/unit/test_fixtures.py (+31/-30)
debian/control (+1/-1)
To merge this branch: bzr merge lp:~canonical-platform-qa/autopilot/depends_for_gsettings
Reviewer Review Type Date Requested Status
Iain Lane (community) Approve
PS Jenkins bot continuous-integration Approve
Autopilot Hackers Pending
Review via email: mp+265621@code.launchpad.net

Commit message

Resolves dependencies that not everyone cares about. Using Gio API instead of gsettings binary.

Description of the change

Resolves dependencies that not everyone cares about. Using Gio API instead of gsettings binary.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
570. By Christopher Lee

Correct test

571. By Christopher Lee

Actually change setting now (needs to be bool, not string). test now passes.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Iain Lane (laney) wrote :

OK, thanks!

Two minor comments

  - Recommends probably isn't that useful here since it isn't installed in many circumstances. I'd probably remove it and just ask consumers to install the package if they want this. They probably already have it if they are testing the osk anyway.
  - Do you need to upgrade gir1.2-glib-2.0 to Depends now? This isn't actually *that* important since python3-gi depends on it, but if you rely on something then it's best to have depends explicitly.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'autopilot/_fixtures.py'
--- autopilot/_fixtures.py 2015-07-16 03:26:31 +0000
+++ autopilot/_fixtures.py 2015-07-23 02:56:28 +0000
@@ -19,8 +19,7 @@
1919
20from fixtures import Fixture20from fixtures import Fixture
21import logging21import logging
22import subprocess22from gi.repository import Gio
23
2423
25logger = logging.getLogger(__name__)24logger = logging.getLogger(__name__)
2625
@@ -58,52 +57,64 @@
58 osk_schema = 'com.canonical.keyboard.maliit'57 osk_schema = 'com.canonical.keyboard.maliit'
59 osk_show_key = 'stay-hidden'58 osk_show_key = 'stay-hidden'
6059
61 def __init__(self):
62 super().__init__()
63 self._original_value = get_gsettings_value(
64 self.osk_schema,
65 self.osk_show_key
66 )
67
68 def setUp(self):60 def setUp(self):
69 super().setUp()61 super().setUp()
70 set_gsettings_value(self.osk_schema, self.osk_show_key, 'false')62
71 self.addCleanup(63 try:
72 set_gsettings_value,64 _original_value = get_bool_gsettings_value(
73 self.osk_schema,65 self.osk_schema,
74 self.osk_show_key,66 self.osk_show_key
75 self._original_value67 )
76 )68 set_bool_gsettings_value(
7769 self.osk_schema,
7870 self.osk_show_key,
79def get_gsettings_value(schema, key):71 False
80 """Return the output of gsettings get as a string or None if the call72 )
81 fails.73 self.addCleanup(
8274 set_bool_gsettings_value,
83 """75 self.osk_schema,
84 command = ['/usr/bin/gsettings', 'get', schema, key]76 self.osk_show_key,
85 try:77 _original_value
86 output = subprocess.check_output(78 )
87 command,79 except ValueError as e:
88 stderr=subprocess.PIPE,80 logger.warning('Failed to set OSK gsetting: {}'.format(e))
89 universal_newlines=True81
90 )82
91 return output.rstrip('\n')83def get_bool_gsettings_value(schema, key):
92 except subprocess.CalledProcessError as e:84 """Return the boolean value for schema/key combo.
93 logger.warning(85
94 'Failed to get gsettings value for {schema}/{key}: {error}'.format(86 :raises ValueError: If either ``schema`` or ``key`` are not valid.
95 schema=schema, key=key, error=e.output87
96 )88 """
97 )89 setting = _gsetting_get_setting(schema, key)
9890
9991 return setting.get_boolean(key)
100def set_gsettings_value(schema, key, value):92
101 command = ['/usr/bin/gsettings', 'set', schema, key, value]93
102 try:94def set_bool_gsettings_value(schema, key, value):
103 subprocess.check_output(command, stderr=subprocess.PIPE)95 """Set the boolean value ``value`` for schema/key combo.
104 except subprocess.CalledProcessError as e:96
105 logger.warning(97 :raises ValueError: If either ``schema`` or ``key`` are not valid.
106 'Failed to set gsettings value {sch}/{key} to {v}: {error}'.format(98
107 sch=schema, key=key, v=value, error=e.output99 """
108 )100
109 )101 setting = _gsetting_get_setting(schema, key)
102
103 setting.set_boolean(key, value)
104
105
106def _gsetting_get_setting(schema, key):
107 if schema not in Gio.Settings.list_schemas():
108 raise ValueError('schema {} is not installed.'.format(schema))
109
110 setting = Gio.Settings.new(schema)
111
112 if key not in setting.keys():
113 raise ValueError(
114 'key \'{key}\' is not available for schema \'{schema}\''.format(
115 key=key,
116 schema=schema
117 )
118 )
119
120 return setting
110121
=== modified file 'autopilot/tests/unit/test_fixtures.py'
--- autopilot/tests/unit/test_fixtures.py 2015-07-16 01:52:23 +0000
+++ autopilot/tests/unit/test_fixtures.py 2015-07-23 02:56:28 +0000
@@ -19,11 +19,8 @@
1919
2020
21from testtools import TestCase21from testtools import TestCase
22from testtools.matchers import (22from testtools.matchers import raises
23 Not,23from unittest.mock import patch, Mock
24 Raises,
25)
26from unittest.mock import patch
27import autopilot._fixtures as ap_fixtures24import autopilot._fixtures as ap_fixtures
2825
2926
@@ -40,47 +37,51 @@
4037
41class GSettingsAccessTests(TestCase):38class GSettingsAccessTests(TestCase):
4239
43 def test_incorrect_schema_doesnt_raise_exception(self):40 def test_incorrect_schema_raises_exception(self):
44 self.assertThat(41 self.assertThat(
45 lambda: ap_fixtures.get_gsettings_value('foo', 'bar'),42 lambda: ap_fixtures._gsetting_get_setting('com.foo.', 'baz'),
46 Not(Raises())43 raises(ValueError)
44 )
45
46 def test_incorrect_key_raises_exception(self):
47 self.assertThat(
48 lambda: ap_fixtures._gsetting_get_setting(
49 'org.gnome.system.locale',
50 'baz'
51 ),
52 raises(ValueError)
47 )53 )
4854
49 def test_get_value_returns_expected_value(self):55 def test_get_value_returns_expected_value(self):
50 with patch.object(ap_fixtures.subprocess, 'check_output') as check_out:56 with patch.object(ap_fixtures, '_gsetting_get_setting') as get_setting:
51 check_out.return_value = 'buzz'57 setting = Mock()
52 self.assertEqual(58 setting.get_boolean.return_value = True
53 ap_fixtures.get_gsettings_value('foo', 'bar'),59 get_setting.return_value = setting
54 'buzz'60 self.assertEqual(
55 )61 ap_fixtures.get_bool_gsettings_value('foo', 'bar'),
5662 True
57 def test_get_value_strips_newline(self):
58 with patch.object(ap_fixtures.subprocess, 'check_output') as check_out:
59 check_out.return_value = 'buzz\n'
60 self.assertEqual(
61 ap_fixtures.get_gsettings_value('foo', 'bar'),
62 'buzz'
63 )63 )
6464
6565
66class OSKAlwaysEnabledTests(TestCase):66class OSKAlwaysEnabledTests(TestCase):
6767
68 def test_sets_stayhidden_to_false(self):68 @patch.object(ap_fixtures, '_gsetting_get_setting')
69 with patch.object(ap_fixtures, 'set_gsettings_value') as set_gsetting:69 def test_sets_stayhidden_to_False(self, gs):
70 with patch.object(ap_fixtures, 'set_bool_gsettings_value') as set_gs:
70 with ap_fixtures.OSKAlwaysEnabled():71 with ap_fixtures.OSKAlwaysEnabled():
71 set_gsetting.assert_called_once_with(72 set_gs.assert_called_once_with(
72 'com.canonical.keyboard.maliit',73 'com.canonical.keyboard.maliit',
73 'stay-hidden',74 'stay-hidden',
74 'false'75 False
75 )76 )
7677
77 def test_resets_value_to_original(self):78 def test_resets_value_to_original(self):
78 with patch.object(ap_fixtures, 'set_gsettings_value') as set_gset:79 with patch.object(ap_fixtures, 'set_bool_gsettings_value') as set_gs:
79 with patch.object(ap_fixtures, 'get_gsettings_value') as get_gset:80 with patch.object(ap_fixtures, 'get_bool_gsettings_value') as get_gs: # NOQA
80 get_gset.return_value = 'foo'81 get_gs.return_value = 'foo'
81 with ap_fixtures.OSKAlwaysEnabled():82 with ap_fixtures.OSKAlwaysEnabled():
82 pass83 pass
83 set_gset.assert_called_with(84 set_gs.assert_called_with(
84 'com.canonical.keyboard.maliit',85 'com.canonical.keyboard.maliit',
85 'stay-hidden',86 'stay-hidden',
86 'foo'87 'foo'
8788
=== modified file 'debian/control'
--- debian/control 2015-07-16 03:24:34 +0000
+++ debian/control 2015-07-23 02:56:28 +0000
@@ -11,7 +11,6 @@
11 gir1.2-ibus-1.0,11 gir1.2-ibus-1.0,
12 gir1.2-ubuntu-app-launch-2 | gir1.2-upstart-app-launch-2,12 gir1.2-ubuntu-app-launch-2 | gir1.2-upstart-app-launch-2,
13 graphviz,13 graphviz,
14 libglib2.0-bin,
15 libjs-jquery,14 libjs-jquery,
16 libjs-underscore,15 libjs-underscore,
17 liblttng-ust-dev,16 liblttng-ust-dev,
@@ -69,6 +68,7 @@
69 python3-evdev,68 python3-evdev,
70 python3-xlib (>=0.14+20091101-1ubuntu3),69 python3-xlib (>=0.14+20091101-1ubuntu3),
71 recordmydesktop,70 recordmydesktop,
71 ubuntu-keyboard-data,
72Breaks: libautopilot-gtk (<< 1.4),72Breaks: libautopilot-gtk (<< 1.4),
73 libautopilot-qt (<< 1.4),73 libautopilot-qt (<< 1.4),
74Description: Utility to write and run integration tests easily (Python 3)74Description: Utility to write and run integration tests easily (Python 3)

Subscribers

People subscribed via source and target branches