Merge lp:~savilerow-team/savilerow/test-cleanup-and-py3 into lp:savilerow
- test-cleanup-and-py3
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 8 |
Proposed branch: | lp:~savilerow-team/savilerow/test-cleanup-and-py3 |
Merge into: | lp:savilerow |
Diff against target: |
322 lines (+36/-47) 11 files modified
tests/api/test_clickapps.py (+2/-1) tests/api/test_dconf.py (+9/-21) tests/api/test_fonts.py (+3/-3) tests/api/test_infographic_themes.py (+2/-2) tests/api/test_lockscreen.py (+1/-0) tests/api/test_scopes.py (+5/-5) tests/api/test_themes.py (+4/-5) tests/api/test_webbrowser_settings.py (+2/-5) tests/core/test_build.py (+5/-4) tests/core/test_customization_enabled.py (+2/-1) tests/core/test_upstartjobs.py (+1/-0) |
To merge this branch: | bzr merge lp:~savilerow-team/savilerow/test-cleanup-and-py3 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alex Chiang (community) | Approve | ||
Scott Sweeny (community) | Approve | ||
Review via email: mp+214630@code.launchpad.net |
Commit message
Description of the change
Move to python3 so that phablet-test-run can be run
Chris Wayne (cwayne) wrote : | # |
Chris Wayne (cwayne) wrote : | # |
cwayne@athena:~$ phablet-test-run custom
Loading tests from: /home/phablet/
Tests running...
No Custom Fonts Found
Ran 18 tests in 1.972s
OK
Chris Wayne (cwayne) wrote : | # |
Also not that this MP does include some cleanup to the dconf test, which is frankly still less than ideal. However, the way this test is written must change imminently as the new dconf architecture is ready soon (since u-t-c-h has finally landed), so it doesn't make sense to put too much time fixing that test quite yet
Scott Sweeny (ssweeny) wrote : | # |
> Also not that this MP does include some cleanup to the dconf test, which is
> frankly still less than ideal. However, the way this test is written must
> change imminently as the new dconf architecture is ready soon (since u-t-c-h
> has finally landed), so it doesn't make sense to put too much time fixing that
> test quite yet
I'll take the action to update the test along with the rest of the dconf stuff.
Scott Sweeny (ssweeny) wrote : | # |
Update itself looks good.
Alex Chiang (achiang) wrote : | # |
In general, not a fan of mixing a "port to new language" and "logic changes to test" in the same MP.
No justification for *why* dconf test no longer needs to test for comments.
Line 77, try..except block removed. Why? Old logic, the test would display every key that failed. New logic, test will terminate on first failure, and you won't learn about any future failures.
Lines 123--125, why intermediate variable needed? Why not just chain together the methods, such as:
data_dirs = subprocess.
Lines 146, 147 -- did some tool really recommend to split whitespace that way? Looks kinda ugly to me.
Lines 232, same question as 123.
Lines 302--305 -- why we no longer care about ValueError exception?
Chris Wayne (cwayne) wrote : | # |
The dconf test wasn't actually using is_commented which made it clear to me that it wasn't necessary in the first place, and was just cluttering up the code.
Line 77, it would print out only information on one key, and then bail out of the test by doing self.assertTrue
TBH Line 123-125 was done that way just to stay under 80 chars to make pep8 not complain
146-147 again just trying to stay under 80 chars, couldn't figure out a better way to do it..
As for the ValueError, deleting that is an error on my part (was a little overzealous cleaning stuff up), will add it back in
- 9. By Chris Wayne
-
Shouldnt have removed valueerror, as that would indicate something wrong with the buildstamp and presumably the build itself
Alex Chiang (achiang) wrote : | # |
On Tue, Apr 8, 2014 at 11:46 AM, Chris Wayne <email address hidden> wrote:
> The dconf test wasn't actually using is_commented which made it clear to me that it wasn't necessary in the first place, and was just cluttering up the code.
Well, the code was broken. because line 46 was is_comment and line 50
it's is_commented.
But the intention of the code doesn't seem wrong to me...
What does happen if you get comments in a dconf file now? In fact, we
should add a fixture that has comments in it.
[save that for a future MP that fixes the overall dconf test as
originally mentioned...]
>
> Line 77, it would print out only information on one key, and then bail out of the test by doing self.assertTrue
Fair enough -- I read that wrong because I missed the assertTrue.
But I still think it would be more useful to try..except, and continue
in the exception case, so that the test shows all the broken keys at
once.
And that should be another test fixture -- a dconf test file with 2
broken keys, again saved for the future MP.
>
> TBH Line 123-125 was done that way just to stay under 80 chars to make pep8 not complain
>
> 146-147 again just trying to stay under 80 chars, couldn't figure out a better way to do it..
Frankly I'd just ignore pep8's advice for those particular lines
because they make the code more annoying to read.
> As for the ValueError, deleting that is an error on my part (was a little overzealous cleaning stuff up), will add it back in
Thanks.
- 10. By Chris Wayne
-
Following pep8 here really makes it more difficult to read the code
Chris Wayne (cwayne) wrote : | # |
So we do already ship comments in the dconf file today, and they're properly ignored, as we use re.match, the string will never match the given regex to find a key.
I do agree with the fact that getting a full list of failed keys will be useful, and plan to add it to a new MP.
Alex Chiang (achiang) wrote : | # |
Looking better.
Few final nits:
- Line 45 comment should be removed, no?
- what changed on lines 86/87?
- 144/145 still looks worse than original 143
- 176/177 - what changed?
- 194/195 - why remove the trailing '.'?
- 303 - now I know for sure we are not testing that code path ;) syntax error in print statement. need to write a test that covers that path.
- 11. By Chris Wayne
-
Addressing MR comments
Chris Wayne (cwayne) wrote : | # |
45 can be removed, but I thought it was referring to the test as a whole...
86/87 was trailing whitespace being removed (more pep8-ness)
176/177 more trailing whitespace
194/195 that . was the 80th char and I wanted clean pep8
Addressed 144/145 and 303
Alex Chiang (achiang) wrote : | # |
New line numbers... 184/185 is user-facing documentation, so removing the trailing '.' is not acceptable.
Remember -- pep8 is only a set of guidelines, not a hard rule. The rules can be bent when it makes sense to do so.
- 12. By Chris Wayne
-
Addressing MR comments
Chris Wayne (cwayne) wrote : | # |
Updated as per MR comments
Alex Chiang (achiang) wrote : | # |
Thanks.
Looking forward to the dconf cleanup MP. :)
Preview Diff
1 | === modified file 'tests/api/test_clickapps.py' |
2 | --- tests/api/test_clickapps.py 2014-03-06 16:14:03 +0000 |
3 | +++ tests/api/test_clickapps.py 2014-04-08 20:11:31 +0000 |
4 | @@ -5,6 +5,7 @@ |
5 | #: Custom click app installation directory |
6 | path = "/custom/click" |
7 | |
8 | + |
9 | class ClickAppVerificationTests(AutopilotTestCase): |
10 | """ |
11 | Downstream may ship pre-installed click packages as part of the |
12 | @@ -34,7 +35,7 @@ |
13 | against the file list in the target directory. |
14 | """ |
15 | # Get the list of installed click apps |
16 | - installed_apps = subprocess.check_output(['click', 'list']) |
17 | + installed_apps = subprocess.check_output(['click', 'list']).decode() |
18 | |
19 | apps = os.listdir(path) |
20 | for a in apps: |
21 | |
22 | === modified file 'tests/api/test_dconf.py' |
23 | --- tests/api/test_dconf.py 2014-03-06 16:14:03 +0000 |
24 | +++ tests/api/test_dconf.py 2014-04-08 20:11:31 +0000 |
25 | @@ -6,6 +6,7 @@ |
26 | #: Path to pre-seeded custom dconf database |
27 | custom_dconf_key = '/custom/etc/dconf/db/custom.d/custom.key' |
28 | |
29 | + |
30 | class DconfVerificationTests(AutopilotTestCase): |
31 | |
32 | os.environ['DCONF_DIR'] = '/custom/etc/dconf' |
33 | @@ -23,36 +24,23 @@ |
34 | try: |
35 | ck = open(custom_dconf_key, 'r') |
36 | except IOError: |
37 | - print "File not found, has this image not been customized?" |
38 | - self.asserttrue(False) |
39 | + print("File not found, has this image not been customized?") |
40 | + self.assertTrue(False) |
41 | |
42 | dconf_keys = {} |
43 | |
44 | for line in ck.readlines(): |
45 | # XXX: This seems so broken. |
46 | - is_comment = False |
47 | - if re.match('\#', line.lstrip()): |
48 | - # TODO turn to debug statements |
49 | - print 'KEY/VALUE IS COMMENTED SO NOT USED, SKIPPING' |
50 | - is_commented = True |
51 | - if re.match('\[.*\]', line) and not is_comment: |
52 | + if re.match('\[.*\]', line): |
53 | keybase = re.sub('[\[\]]', '', line) |
54 | keybase = '/%s/' % (keybase.strip('\n')) |
55 | - if re.match('.*\=.*', line) and not is_comment: |
56 | + if re.match('.*\=.*', line): |
57 | key = keybase + line.split('=')[0] |
58 | value = line.split('=')[1] |
59 | dconf_keys[key] = value |
60 | |
61 | - print dconf_keys |
62 | - |
63 | - for key, value in dconf_keys.iteritems(): |
64 | - # Properly installed dconf keys should be visible via |
65 | + for key, value in dconf_keys.items(): |
66 | + # Properly installed dconf keys should be visible via |
67 | # `dconf read` |
68 | - dval = subprocess.check_output(['dconf', 'read', key]) |
69 | - try: |
70 | - self.assertEqual(dval, value) |
71 | - except AssertionError: |
72 | - print "" |
73 | - print "ERROR" |
74 | - print "%s does not match. FAILING" % key |
75 | - self.asserttrue(False) |
76 | + dval = subprocess.check_output(['dconf', 'read', key]).decode() |
77 | + self.assertEqual(dval, value) |
78 | |
79 | === modified file 'tests/api/test_fonts.py' |
80 | --- tests/api/test_fonts.py 2014-03-06 16:14:03 +0000 |
81 | +++ tests/api/test_fonts.py 2014-04-08 20:11:31 +0000 |
82 | @@ -2,7 +2,7 @@ |
83 | import subprocess |
84 | import os |
85 | |
86 | -#: Path where pre-installed custom fonts are installed |
87 | +#: Path where pre-installed custom fonts are installed |
88 | fontspath = "/custom/usr/share/fonts" |
89 | fontlist = [] |
90 | |
91 | @@ -23,11 +23,11 @@ |
92 | fontlist.append(os.path.join(path, name)) |
93 | |
94 | # Properly installed fonts are visible to fc-list |
95 | - installed_fonts = subprocess.check_output(['fc-list']) |
96 | + installed_fonts = subprocess.check_output(['fc-list']).decode() |
97 | |
98 | # Compare filesystem list against fc-list output |
99 | for font in fontlist: |
100 | self.assertIn(font, installed_fonts) |
101 | else: |
102 | - print "No Custom Fonts Found" |
103 | + print("No Custom Fonts Found") |
104 | self.assertTrue(True) |
105 | |
106 | === modified file 'tests/api/test_infographic_themes.py' |
107 | --- tests/api/test_infographic_themes.py 2014-03-06 16:14:03 +0000 |
108 | +++ tests/api/test_infographic_themes.py 2014-04-08 20:11:31 +0000 |
109 | @@ -5,6 +5,7 @@ |
110 | #: Relative path to welcome screen infographic customization file |
111 | themefile = 'libusermetrics/themes/custom.xml' |
112 | |
113 | + |
114 | class InfographicThemeCustomizationTest(AutopilotTestCase): |
115 | |
116 | def test_theme_dir_in_datadirs(self): |
117 | @@ -16,8 +17,7 @@ |
118 | in the system. |
119 | """ |
120 | themefilefound = False |
121 | - data_dirs = subprocess.check_output(['initctl', 'get-env', |
122 | - 'XDG_DATA_DIRS']).split(':') |
123 | + data_dirs = subprocess.check_output(['initctl', 'get-env','XDG_DATA_DIRS']).decode().split(":") |
124 | for dir in data_dirs: |
125 | # We use a relative path in `themefile` because we don't |
126 | # necessarily know the full path to the custom XDG data |
127 | |
128 | === modified file 'tests/api/test_lockscreen.py' |
129 | --- tests/api/test_lockscreen.py 2014-03-06 16:14:03 +0000 |
130 | +++ tests/api/test_lockscreen.py 2014-04-08 20:11:31 +0000 |
131 | @@ -6,6 +6,7 @@ |
132 | #: Path to custom welcome screen graphic |
133 | lockscreenpath = "/custom/usr/share/backgrounds/welcome.png" |
134 | |
135 | + |
136 | class LockScreenCustomizationTests(AutopilotTestCase): |
137 | def test_lockscreen(self): |
138 | """ |
139 | |
140 | === modified file 'tests/api/test_scopes.py' |
141 | --- tests/api/test_scopes.py 2014-03-29 21:10:56 +0000 |
142 | +++ tests/api/test_scopes.py 2014-04-08 20:11:31 +0000 |
143 | @@ -1,14 +1,15 @@ |
144 | from autopilot.testcase import AutopilotTestCase |
145 | import os |
146 | import psutil |
147 | -import subprocess |
148 | |
149 | #: List of custom scopes that should be running |
150 | -scopes = ["scope-tourism", "scope-tourism-mocknews", "scope-tourism-mocktransport", |
151 | - "scope-tourism-mockrecommends", "scope-tourism-mockweather"] |
152 | +scopes = ["scope-tourism", "scope-tourism-mocknews", |
153 | + "scope-tourism-mocktransport", "scope-tourism-mockrecommends", |
154 | + "scope-tourism-mockweather"] |
155 | #: Custom scope installation directory |
156 | path = "/custom/lib/arm-linux-gnueabihf/unity-scopes" |
157 | |
158 | + |
159 | class ScopeVerificationTest(AutopilotTestCase): |
160 | """ |
161 | Downstream may ship pre-installed customized scopes as part of the |
162 | @@ -29,7 +30,7 @@ |
163 | def test_scope_customization_running_process(self): |
164 | """ |
165 | Insalled custom scopes should be running processes, started by |
166 | - scoperunner. This test ensures that the scopes are properly |
167 | + scoperunner. This test ensures that the scopes are properly |
168 | started |
169 | """ |
170 | proc_cmd_list = [] |
171 | @@ -38,4 +39,3 @@ |
172 | proc_cmd_list.append(proc_info) |
173 | for scope in scopes: |
174 | self.assertTrue(any(scope in proc for proc in proc_cmd_list)) |
175 | - |
176 | |
177 | === modified file 'tests/api/test_themes.py' |
178 | --- tests/api/test_themes.py 2014-03-06 16:14:03 +0000 |
179 | +++ tests/api/test_themes.py 2014-04-08 20:11:31 +0000 |
180 | @@ -8,6 +8,7 @@ |
181 | themedir = 'themes/Ubuntu/Custom' |
182 | themestring = "theme=themes.Ubuntu.Custom" |
183 | |
184 | + |
185 | class ThemeCustomizationTests(AutopilotTestCase): |
186 | """ |
187 | Downstreams may customize the visual color scheme of Ubuntu Touch, |
188 | @@ -17,7 +18,7 @@ |
189 | |
190 | * create the elements of a new visual theme |
191 | * configure the Unity shell to use the custom theme |
192 | - |
193 | + |
194 | Downstreams *may* create new visual themes. |
195 | |
196 | If a new visual theme is created, downstreams *must* specify the new |
197 | @@ -42,10 +43,9 @@ |
198 | if "%s" % (themestring) in customk.splitlines(): |
199 | self.assertTrue(True) |
200 | else: |
201 | - print "Error reading theme.ini at %s" % (custom_theme) |
202 | + print("Error reading theme.ini at %s" % (custom_theme)) |
203 | self.assertTrue(False) |
204 | |
205 | - |
206 | def test_theme_dir_in_datadirs(self): |
207 | """ |
208 | If a downstream creates a custom visual theme, the theme's files |
209 | @@ -60,8 +60,7 @@ |
210 | the specific subdirectory containing the custome theme files. |
211 | """ |
212 | themedirfound = False |
213 | - data_dirs = subprocess.check_output(['initctl', 'get-env', |
214 | - 'XDG_DATA_DIRS']).split(':') |
215 | + data_dirs = subprocess.check_output(['initctl', 'get-env','XDG_DATA_DIRS']).decode().split(":") |
216 | for dir in data_dirs: |
217 | # We use a relative path in `themedir` because we don't |
218 | # necessarily know the full path to the custom XDG data |
219 | |
220 | === modified file 'tests/api/test_webbrowser_settings.py' |
221 | --- tests/api/test_webbrowser_settings.py 2014-03-06 16:14:03 +0000 |
222 | +++ tests/api/test_webbrowser_settings.py 2014-04-08 20:11:31 +0000 |
223 | @@ -1,7 +1,6 @@ |
224 | from autopilot.testcase import AutopilotTestCase |
225 | import os |
226 | import sqlite3 |
227 | -import subprocess |
228 | |
229 | #: Pre-seeded browser bookmark database |
230 | dbpath = os.path.expanduser("~/.local/share/webbrowser-app/bookmarks.sqlite") |
231 | @@ -9,6 +8,7 @@ |
232 | #: File specifying custom browser home page |
233 | settingspath = os.path.expanduser("~/.config/webbrowser-app/settings.conf") |
234 | |
235 | + |
236 | class BrowserCustomizationTests(AutopilotTestCase): |
237 | """ |
238 | Downstreams *may* modify the default web browser with custom |
239 | @@ -25,9 +25,6 @@ |
240 | """ |
241 | Check that the pre-seeded bookmark database is properly formed. |
242 | """ |
243 | - # Quick ls -la and md5sum of the bookmarks.sqlite file for debug |
244 | - print subprocess.check_output(['ls', '-al', dbpath]) |
245 | - print subprocess.check_output(['md5sum', dbpath]) |
246 | conn = sqlite3.connect(dbpath) |
247 | conn.row_factory = sqlite3.Row |
248 | |
249 | @@ -36,7 +33,7 @@ |
250 | r = c.fetchone() |
251 | |
252 | # Any and every row's keys should have these columns |
253 | - schema = r.keys() |
254 | + schema = list(r.keys()) |
255 | dbcolumns = ['url', 'title', 'icon'] |
256 | self.assertTrue(schema == dbcolumns) |
257 | |
258 | |
259 | === modified file 'tests/core/test_build.py' |
260 | --- tests/core/test_build.py 2014-03-06 16:14:03 +0000 |
261 | +++ tests/core/test_build.py 2014-04-08 20:11:31 +0000 |
262 | @@ -1,9 +1,11 @@ |
263 | from autopilot.testcase import AutopilotTestCase |
264 | -import os, datetime |
265 | +import os |
266 | +import datetime |
267 | |
268 | #: Custom tarball build timestamp, generated by jenkins |
269 | path = "/custom/build_id" |
270 | |
271 | + |
272 | class BuildCustomizationTests(AutopilotTestCase): |
273 | |
274 | def test_build_id(self): |
275 | @@ -27,12 +29,11 @@ |
276 | self.assertTrue(os.path.exists(path)) |
277 | f = open(path, 'r') |
278 | build_id = f.read().strip() |
279 | - print(build_id) |
280 | self.assertTrue(datetime.date.fromtimestamp(float(build_id))) |
281 | f.close() |
282 | except IOError as e: |
283 | - print "build_id file does not exist: %s" % e |
284 | + print("build_id file does not exist: %s" % e) |
285 | self.assertTrue(False) |
286 | except ValueError as e: |
287 | - print "problem with the format of the build_id file: %s" % e |
288 | + print("problem with the format of the build_id file: %s" % e) |
289 | self.assertTrue(False) |
290 | |
291 | === modified file 'tests/core/test_customization_enabled.py' |
292 | --- tests/core/test_customization_enabled.py 2014-03-06 16:14:03 +0000 |
293 | +++ tests/core/test_customization_enabled.py 2014-04-08 20:11:31 +0000 |
294 | @@ -4,6 +4,7 @@ |
295 | #: Flag to indicate pre-loaded sample content has been copied once |
296 | customized_flag_path = os.path.expanduser("~/.customized") |
297 | |
298 | + |
299 | class GeneralCustomizationEnablement(AutopilotTestCase): |
300 | |
301 | def test_customization_enablement(self): |
302 | @@ -18,7 +19,7 @@ |
303 | The presence of the `~/.customized` flag signals that the sample |
304 | content has already been copied to the user area, and that it |
305 | should not be copied again. |
306 | - |
307 | + |
308 | This implementation allows the user to delete the sample |
309 | content if desired, but will also properly re-copy the content |
310 | to a new user after a 'factory reset' event. |
311 | |
312 | === modified file 'tests/core/test_upstartjobs.py' |
313 | --- tests/core/test_upstartjobs.py 2014-03-06 16:14:03 +0000 |
314 | +++ tests/core/test_upstartjobs.py 2014-04-08 20:11:31 +0000 |
315 | @@ -9,6 +9,7 @@ |
316 | '/custom/etc/dconf_profile', 'XDG_DATA_DIRS': '/custom/xdg/data' |
317 | } |
318 | |
319 | + |
320 | class UpstartCustomizationTests(AutopilotTestCase): |
321 | """ |
322 | To implement the Ubuntu Savvy architecture, the contents of the |
Tested by pushing these to /home/phablet/ autopilot/ custom then running 'phablet-test-run custom', and by ensuring they pass pep8 and pyflakes