Merge lp:~ssweeny/savilerow/fix-dconf-test into lp:savilerow

Proposed by Scott Sweeny
Status: Merged
Merged at revision: 9
Proposed branch: lp:~ssweeny/savilerow/fix-dconf-test
Merge into: lp:savilerow
Diff against target: 50 lines (+12/-15)
1 file modified
tests/api/test_dconf.py (+12/-15)
To merge this branch: bzr merge lp:~ssweeny/savilerow/fix-dconf-test
Reviewer Review Type Date Requested Status
Chris Wayne (community) Approve
Review via email: mp+215883@code.launchpad.net

Description of the change

Since dconf key files are in .ini format just use configparser to get the keys and values instead of regular expression shenanigans.

To post a comment you must log in.
lp:~ssweeny/savilerow/fix-dconf-test updated
10. By Scott Sweeny

Forgot to escape a split line

11. By Scott Sweeny

strip() dconf output to make comparisons work

Revision history for this message
Chris Wayne (cwayne) wrote :

cwayne@starbuck:~/fix-dconf-test/tests$ phablet-test-run custom
Loading tests from: /home/phablet/autopilot

Tests running...
No Custom Fonts Found

Ran 18 tests in 2.013s
OK

Seems OK to me, much cleaner, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/api/test_dconf.py'
2--- tests/api/test_dconf.py 2014-04-07 22:36:20 +0000
3+++ tests/api/test_dconf.py 2014-04-15 16:30:58 +0000
4@@ -1,7 +1,7 @@
5 from autopilot.testcase import AutopilotTestCase
6 import os
7 import subprocess
8-import re
9+import configparser
10
11 #: Path to pre-seeded custom dconf database
12 custom_dconf_key = '/custom/etc/dconf/db/custom.d/custom.key'
13@@ -21,26 +21,23 @@
14 This test verifies the custom dconf keys were properly
15 installed.
16 """
17+ parser = configparser.ConfigParser()
18+ dconf_keys = {}
19 try:
20- ck = open(custom_dconf_key, 'r')
21+ with open(custom_dconf_key, 'r') as ck:
22+ parser.read_file(ck)
23+
24+ for section in parser.sections():
25+ for key in parser[section]:
26+ dconf_keys["/{}/{}".format(section, key)] = \
27+ parser[section][key]
28+
29 except IOError:
30 print("File not found, has this image not been customized?")
31 self.assertTrue(False)
32
33- dconf_keys = {}
34-
35- for line in ck.readlines():
36- # XXX: This seems so broken.
37- if re.match('\[.*\]', line):
38- keybase = re.sub('[\[\]]', '', line)
39- keybase = '/%s/' % (keybase.strip('\n'))
40- if re.match('.*\=.*', line):
41- key = keybase + line.split('=')[0]
42- value = line.split('=')[1]
43- dconf_keys[key] = value
44-
45 for key, value in dconf_keys.items():
46 # Properly installed dconf keys should be visible via
47 # `dconf read`
48- dval = subprocess.check_output(['dconf', 'read', key]).decode()
49+ dval = subprocess.check_output(['dconf', 'read', key]).decode().strip()
50 self.assertEqual(dval, value)

Subscribers

People subscribed via source and target branches