Merge lp:~nskaggs/music-app/fix-1292044 into lp:music-app/trusty
- fix-1292044
- Merge into trusty
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Nicholas Skaggs | ||||
Approved revision: | 386 | ||||
Merged at revision: | 441 | ||||
Proposed branch: | lp:~nskaggs/music-app/fix-1292044 | ||||
Merge into: | lp:music-app/trusty | ||||
Diff against target: |
191 lines (+25/-81) 1 file modified
tests/autopilot/music_app/tests/__init__.py (+25/-81) |
||||
To merge this branch: | bzr merge lp:~nskaggs/music-app/fix-1292044 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Victor Thompson | Approve | ||
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Review via email: mp+211637@code.launchpad.net |
Commit message
Fix phablet device test runs not using mocked home
Description of the change
Fix phablet device test runs not using mocked home
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
Victor Thompson (vthompson) wrote : | # |
I ran a click test against this change. I think there's instance(s) of calls to 'temp_move_
=======
ERROR: music_app.
-------
Traceback (most recent call last):
File "/home/
super(TestMainW
File "/home/
self.temp_
AttributeError: 'TestMainWindow' object has no attribute 'temp_move_
Nicholas Skaggs (nskaggs) wrote : | # |
Yes, sorry, this is still WIP :-)
Nicholas Skaggs (nskaggs) wrote : | # |
So this simply removes not using the mocking process on devices. It seems like mediascanner doesn't take kindly to the changes on the device and although everything is lined up, music doesn't see any music when run.
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
FAILED: Continuous integration, rev:379
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:380
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Victor Thompson (vthompson) wrote : | # |
Here's a comment from Sergio about getting the click home directory mocking to work [1]:
"You can't mock the env with click as it's launched with upstart; in any case you could inject stuff in upstart with initctl set-env"
[1] https:/
Nicholas Skaggs (nskaggs) wrote : | # |
Sounds like Leo has a proper solution for us here:
https:/
I guess we can deal with the pain till it lands and use it eh?
Nicholas Skaggs (nskaggs) wrote : | # |
Setting to WIP until then.
Nicholas Skaggs (nskaggs) wrote : | # |
initctl_env has been added to the sdk autopilot helper, so going to update the MP using this.
- 383. By Nicholas Skaggs
-
change str replace func
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:382
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 384. By Nicholas Skaggs
-
more tweaks with str replace ;-)
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:384
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Nicholas Skaggs (nskaggs) wrote : | # |
Python3, 1; me, 0.
I <3 UnicodeDecodeError.
- 385. By Nicholas Skaggs
-
files are binary, d'oh
Nicholas Skaggs (nskaggs) wrote : | # |
This properly runs on my device now :-) Due note jenkins is still running using fake env, so the review really needs to happen on a real device so you can confirm the bug is fixed.
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:385
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Victor Thompson (vthompson) wrote : | # |
Do we need to add another dependency to the app? Or do I need a certain version of the toolkit? When I run I get the following error from phablet-test-run. Note this is on Trusty image r303:
=======
ERROR: unittest.
-------
Traceback (most recent call last):
File "/usr/lib/
test.debug()
File "/usr/lib/
getattr(self, self._testMetho
File "/usr/lib/
raise exception
ImportError: Failed to import test module: music_app.
Traceback (most recent call last):
File "/usr/lib/
module = self._get_
File "/usr/lib/
__import__(name)
File "/home/
from ubuntuuitoolkit import (
ImportError: cannot import name 'environment'
Installed ubuntu-
$apt-cache policy qtdeclarative5-
qtdeclarative5-
Installed: 0.1.46+
Candidate: 0.1.46+
Version table:
*** 0.1.46+
500 http://
100 /var/lib/
Victor Thompson (vthompson) wrote : | # |
Tests pass on the device. However, after running the tests the next launch of the app says that no music can be found. I'll dig a bit more, but the ~/Music directory is still intact and ~/.cache/
Nicholas Skaggs (nskaggs) wrote : | # |
I'll have a look.. I'm assuming you are saying the tests aren't cleaning up well after running.
Victor Thompson (vthompson) wrote : | # |
Correct, and IIRC everything went back to normal after a reboot.
Victor Thompson (vthompson) wrote : | # |
I verified again and a reboot fixed it. The contents of the mediascanner db was identical before and after the reboot... So I don't know what the issue is. Perhaps the environment faking is becoming permanent until we reboot? If we truly can't figure out what's going on, I'm perfectly fine approving this so we only need to reboot to return to normalcy. I'll start reviewing the code changes.
Victor Thompson (vthompson) wrote : | # |
I reviewed the code changes and I don't see any issues. To fix the cleanup issue, this seems to be all that is needed:
=== modified file 'tests/
--- tests/autopilot
+++ tests/autopilot
@@ -118,6 +118,7 @@
#click can use initctl env (upstart), but desktop still requires mock
if self.test_type == 'click':
+ self.addCleanup
else:
Once that is in place, I think we can merge this branch.
Nicholas Skaggs (nskaggs) wrote : | # |
vthompson, sorry didn't get to this, but yes that finishes it. Need to tell the env to cleanup as well, hah!
- 386. By Nicholas Skaggs
-
ty Victor; adding cleanup step so env cleans up after too!
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:386
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Victor Thompson (vthompson) wrote : | # |
Looks good! Thanks for doing this--I will no longer shudder at the thought of testing the app!
Preview Diff
1 | === modified file 'tests/autopilot/music_app/tests/__init__.py' |
2 | --- tests/autopilot/music_app/tests/__init__.py 2014-03-07 20:10:34 +0000 |
3 | +++ tests/autopilot/music_app/tests/__init__.py 2014-04-30 15:25:17 +0000 |
4 | @@ -8,7 +8,6 @@ |
5 | """Music app autopilot tests.""" |
6 | |
7 | import tempfile |
8 | - |
9 | try: |
10 | from unittest import mock |
11 | except ImportError: |
12 | @@ -28,7 +27,8 @@ |
13 | |
14 | from ubuntuuitoolkit import ( |
15 | base, |
16 | - emulators as toolkit_emulators |
17 | + emulators as toolkit_emulators, |
18 | + environment |
19 | ) |
20 | |
21 | |
22 | @@ -50,9 +50,6 @@ |
23 | local_location_dir = os.path.dirname(os.path.dirname(working_dir)) |
24 | local_location = local_location_dir + "/music-app.qml" |
25 | installed_location = "/usr/share/music-app/music-app.qml" |
26 | - sqlite_dir = os.path.expanduser( |
27 | - "~/.local/share/com.ubuntu.music/Databases") |
28 | - backup_dir = sqlite_dir + ".backup" |
29 | |
30 | def setup_environment(self): |
31 | if os.path.exists(self.local_location): |
32 | @@ -67,15 +64,8 @@ |
33 | return launch, test_type |
34 | |
35 | def setUp(self): |
36 | - #backup and wipe db's before testing |
37 | - self.temp_move_sqlite_db() |
38 | - self.addCleanup(self.restore_sqlite_db) |
39 | - |
40 | launch, self.test_type = self.setup_environment() |
41 | - if self.test_type != 'click': |
42 | - self.home_dir = self._patch_home() |
43 | - else: |
44 | - self.home_dir = self._save_home() |
45 | + self.home_dir = self._patch_home() |
46 | self._create_music_library() |
47 | self.pointing_device = Pointer(self.input_device_class.create()) |
48 | super(MusicTestCase, self).setUp() |
49 | @@ -103,25 +93,10 @@ |
50 | "com.ubuntu.music", |
51 | emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase) |
52 | |
53 | - def _save_home(self): |
54 | - logger.debug('Saving HOME') |
55 | - home_dir = os.environ['HOME'] |
56 | - backup_list = ('Music', ) # '.cache/mediascanner') |
57 | - backup_path = [os.path.join(home_dir, i) for i in backup_list] |
58 | - backups = [(i, '%s.bak' % i) for i in backup_path if os.path.exists(i)] |
59 | - for b in backups: |
60 | - logger.debug('backing up %s to %s' % b) |
61 | - try: |
62 | - shutil.rmtree(b[1]) |
63 | - except: |
64 | - pass |
65 | - shutil.move(b[0], b[1]) |
66 | - #self.addCleanup(shutil.move(b[1], b[0])) |
67 | - return home_dir |
68 | - |
69 | def _patch_home(self): |
70 | #make a temp dir |
71 | temp_dir = tempfile.mkdtemp() |
72 | + |
73 | #delete it, and recreate it to the length |
74 | #required so our patching the db works |
75 | #require a length of 25 |
76 | @@ -130,6 +105,7 @@ |
77 | os.mkdir(temp_dir) |
78 | logger.debug("Created fake home directory " + temp_dir) |
79 | self.addCleanup(shutil.rmtree, temp_dir) |
80 | + |
81 | #if the Xauthority file is in home directory |
82 | #make sure we copy it to temp home, otherwise do nothing |
83 | xauth = os.path.expanduser(os.path.join('~', '.Xauthority')) |
84 | @@ -138,10 +114,17 @@ |
85 | shutil.copyfile( |
86 | os.path.expanduser(os.path.join('~', '.Xauthority')), |
87 | os.path.join(temp_dir, '.Xauthority')) |
88 | - patcher = mock.patch.dict('os.environ', {'HOME': temp_dir}) |
89 | - patcher.start() |
90 | + |
91 | + #click can use initctl env (upstart), but desktop still requires mock |
92 | + if self.test_type == 'click': |
93 | + environment.set_initctl_env_var('HOME', temp_dir) |
94 | + self.addCleanup(environment.unset_initctl_env_var, 'HOME') |
95 | + else: |
96 | + patcher = mock.patch.dict('os.environ', {'HOME': temp_dir}) |
97 | + patcher.start() |
98 | + self.addCleanup(patcher.stop) |
99 | + |
100 | logger.debug("Patched home to fake home directory " + temp_dir) |
101 | - self.addCleanup(patcher.stop) |
102 | return temp_dir |
103 | |
104 | def _create_music_library(self): |
105 | @@ -159,29 +142,19 @@ |
106 | |
107 | logger.debug("Content dir set to %s" % content_dir) |
108 | |
109 | - #stop media scanner |
110 | - #if self.test_type == 'click': |
111 | - # subprocess.check_call(['stop', 'mediascanner']) |
112 | - |
113 | #copy content |
114 | shutil.copy(os.path.join(content_dir, '1.ogg'), musicpath) |
115 | shutil.copy(os.path.join(content_dir, '2.ogg'), musicpath) |
116 | shutil.copy(os.path.join(content_dir, '3.mp3'), musicpath) |
117 | - if self.test_type != 'click': |
118 | - shutil.copytree(os.path.join(content_dir, 'mediascanner'), |
119 | - mediascannerpath) |
120 | + shutil.copytree( |
121 | + os.path.join(content_dir, 'mediascanner'), mediascannerpath) |
122 | |
123 | logger.debug("Music copied, files " + str(os.listdir(musicpath))) |
124 | |
125 | - if self.test_type != 'click': |
126 | - self._patch_mediascanner_home(mediascannerpath) |
127 | - logger.debug( |
128 | - "Mediascanner database copied, files " + |
129 | - str(os.listdir(mediascannerpath))) |
130 | - |
131 | - #start media scanner |
132 | - #if self.test_type == 'click': |
133 | - # subprocess.check_call(['start', 'mediascanner']) |
134 | + self._patch_mediascanner_home(mediascannerpath) |
135 | + logger.debug( |
136 | + "Mediascanner database copied, files " + |
137 | + str(os.listdir(mediascannerpath))) |
138 | |
139 | def _patch_mediascanner_home(self, mediascannerpath): |
140 | #do some inline db patching |
141 | @@ -204,10 +177,10 @@ |
142 | #replace all occurences of string find with string replace |
143 | #in the given file |
144 | out_filename = in_filename + ".tmp" |
145 | - infile = open(in_filename, 'r') |
146 | - outfile = open(out_filename, 'w') |
147 | - for s in infile.xreadlines(): |
148 | - outfile.write(s.replace(find, replace)) |
149 | + infile = open(in_filename, 'rb') |
150 | + outfile = open(out_filename, 'wb') |
151 | + for line in infile: |
152 | + outfile.write(line.replace(str.encode(find), str.encode(replace))) |
153 | infile.close() |
154 | outfile.close() |
155 | |
156 | @@ -215,35 +188,6 @@ |
157 | os.remove(in_filename) |
158 | os.rename(out_filename, in_filename) |
159 | |
160 | - def temp_move_sqlite_db(self): |
161 | - try: |
162 | - shutil.rmtree(self.backup_dir) |
163 | - except: |
164 | - pass |
165 | - else: |
166 | - logger.warning("Prexisting backup database found and removed") |
167 | - |
168 | - try: |
169 | - shutil.move(self.sqlite_dir, self.backup_dir) |
170 | - except: |
171 | - logger.warning("No current database found") |
172 | - else: |
173 | - logger.debug("Backed up database") |
174 | - |
175 | - def restore_sqlite_db(self): |
176 | - if os.path.exists(self.backup_dir): |
177 | - if os.path.exists(self.sqlite_dir): |
178 | - try: |
179 | - shutil.rmtree(self.sqlite_dir) |
180 | - except: |
181 | - logger.error("Failed to remove test database and restore" / |
182 | - "database") |
183 | - return |
184 | - try: |
185 | - shutil.move(self.backup_dir, self.sqlite_dir) |
186 | - except: |
187 | - logger.error("Failed to restore database") |
188 | - |
189 | @property |
190 | def player(self): |
191 | return self.main_view.get_player() |
FAILED: Continuous integration, rev:378 91.189. 93.70:8080/ job/music- app-ci/ 649/ 91.189. 93.70:8080/ job/generic- mediumtests- trusty/ 1794/console 91.189. 93.70:8080/ job/music- app-raring- amd64-ci/ 649/console 91.189. 93.70:8080/ job/music- app-saucy- amd64-ci/ 651/console 91.189. 93.70:8080/ job/music- app-trusty- amd64-ci/ 370/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: 91.189. 93.70:8080/ job/music- app-ci/ 649/rebuild
http://