Merge lp:~nskaggs/music-app/clean-up-mediascanner-tests into lp:music-app/trusty

Proposed by Nicholas Skaggs
Status: Merged
Approved by: Daniel Holm
Approved revision: 135
Merged at revision: 144
Proposed branch: lp:~nskaggs/music-app/clean-up-mediascanner-tests
Merge into: lp:music-app/trusty
Diff against target: 198 lines (+55/-34)
4 files modified
tests/autopilot/music_app/emulators.py (+14/-13)
tests/autopilot/music_app/emulators/__init__.py (+0/-6)
tests/autopilot/music_app/tests/__init__.py (+38/-9)
tests/autopilot/music_app/tests/test_music.py (+3/-6)
To merge this branch: bzr merge lp:~nskaggs/music-app/clean-up-mediascanner-tests
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Music App Developers Pending
Review via email: mp+188672@code.launchpad.net

Commit message

Clean up mediascanner autopilot tests and allow them to run properly in the lab

Description of the change

This will fix the issue with running the new mediascanner autopilot tests in the lab. In addition, I attempt to add some nice logging and clean up the code to be a bit more pythonic (no more os.system calls to sed, etc)

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed directory 'tests/autopilot/music_app/emulators'
2=== renamed file 'tests/autopilot/music_app/emulators/emulators.py' => 'tests/autopilot/music_app/emulators.py'
3--- tests/autopilot/music_app/emulators/emulators.py 2013-09-27 15:14:10 +0000
4+++ tests/autopilot/music_app/emulators.py 2013-10-01 19:27:03 +0000
5@@ -6,10 +6,11 @@
6 # by the Free Software Foundation.
7
8 """Music app autopilot emulators."""
9-
10-from ubuntuuitoolkit import emulators as uitk
11-
12-class MainView(uitk.MainView):
13+from ubuntuuitoolkit import emulators as toolkit_emulators
14+
15+
16+class MainView(toolkit_emulators.MainView):
17+
18 """An emulator class that makes it easy to interact with the
19 music-app.
20 """
21@@ -29,11 +30,11 @@
22 """Returns the item that is searched for with app.select_many
23 In case of no item was not found (not created yet) a second attempt is
24 taken 1 second later"""
25- items = self.select_many(object_type, **kwargs)
26+ items = self.app.select_many(object_type, **kwargs)
27 tries = 10
28 while len(items) < 1 and tries > 0:
29- sleep(self.retry_delay)
30- items = self.select_many(object_type, **kwargs)
31+ sleep(self.app.retry_delay)
32+ items = self.app.select_many(object_type, **kwargs)
33 tries = tries - 1
34 return items
35
36@@ -41,19 +42,19 @@
37 """Returns the item that is searched for with app.select_single
38 In case of the item was not found (not created yet) a second attempt is
39 taken 1 second later."""
40- item = self.select_single(object_type, **kwargs)
41+ item = self.app.select_single(object_type, **kwargs)
42 tries = 10
43 while item is None and tries > 0:
44- sleep(self.retry_delay)
45- item = self.select_single(object_type, **kwargs)
46+ sleep(self.app.retry_delay)
47+ item = self.app.select_single(object_type, **kwargs)
48 tries = tries - 1
49 return item
50
51 def tap_item(self, item):
52- self.pointing_device.move_to_object(item)
53- self.pointing_device.press()
54+ self.app.pointing_device.move_to_object(item)
55+ self.app.pointing_device.press()
56 sleep(2)
57- self.pointing_device.release()
58+ self.app.pointing_device.release()
59
60 def get_play_button(self):
61 return self.app.select_single("UbuntuShape", objectName = "playshape")
62
63=== removed file 'tests/autopilot/music_app/emulators/__init__.py'
64--- tests/autopilot/music_app/emulators/__init__.py 2013-06-21 23:06:10 +0000
65+++ tests/autopilot/music_app/emulators/__init__.py 1970-01-01 00:00:00 +0000
66@@ -1,6 +0,0 @@
67-# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
68-# Copyright 2013 Canonical
69-#
70-# This program is free software: you can redistribute it and/or modify it
71-# under the terms of the GNU General Public License version 3, as published
72-# by the Free Software Foundation.
73
74=== modified file 'tests/autopilot/music_app/tests/__init__.py'
75--- tests/autopilot/music_app/tests/__init__.py 2013-09-27 21:55:49 +0000
76+++ tests/autopilot/music_app/tests/__init__.py 2013-10-01 19:27:03 +0000
77@@ -13,15 +13,17 @@
78 import os
79 import os.path
80 import shutil
81+import logging
82
83 from autopilot.input import Mouse, Touch, Pointer
84 from autopilot.platform import model
85 from autopilot.testcase import AutopilotTestCase
86
87-from time import sleep
88-
89-from ubuntuuitoolkit import emulators as uitk
90-from music_app.emulators.emulators import MainView
91+from ubuntuuitoolkit import emulators as toolkit_emulators
92+from music_app.emulators import MainView
93+
94+logger = logging.getLogger(__name__)
95+
96
97 class MusicTestCase(AutopilotTestCase):
98
99@@ -78,22 +80,30 @@
100 shutil.rmtree(temp_dir)
101 temp_dir = temp_dir.ljust(25, 'X')
102 os.mkdir(temp_dir)
103+ logger.debug("Created fake home directory " + temp_dir)
104 self.addCleanup(shutil.rmtree, temp_dir)
105 patcher = mock.patch.dict('os.environ', {'HOME': temp_dir})
106 patcher.start()
107+ logger.debug("Patched home to fake home directory " + temp_dir)
108 self.addCleanup(patcher.stop)
109
110 def _create_music_library(self):
111 #use fake home
112 home = os.environ['HOME']
113+ logger.debug("Home set to " + home)
114 musicpath = home + '/Music'
115+ logger.debug("Music path set to " + musicpath)
116 mediascannerpath = home + '/.cache/mediascanner'
117 os.mkdir(musicpath)
118+ logger.debug("Mediascanner path set to " + mediascannerpath)
119
120 #copy over our index
121 shutil.copytree(self.working_dir + '/music_app/content/mediascanner',
122 mediascannerpath)
123
124+ logger.debug("Mediascanner database copied, files " + str(os.listdir(mediascannerpath)))
125+
126+ #copy over the music
127 if os.path.exists(self.local_location):
128 shutil.copy(self.working_dir + '/music_app/content/'
129 +'1.ogg',
130@@ -109,20 +119,39 @@
131 +'2.ogg',
132 musicpath)
133
134+ logger.debug("Music copied, files " + str(os.listdir(musicpath)))
135+
136 #do some inline db patching
137 #patch mediaindex to proper home
138 #these values are dependent upon our sampled db
139+ logger.debug("Patching fake mediascanner database")
140 relhome = home[1:]
141 dblocation = "home/autopilot-music-app"
142 dbfoldername = "ea50858c-4b21-4f87-9005-40aa960a84a3"
143 #patch mediaindex
144- os.system("sed -i 's!" + dblocation + "!" + str(relhome) + "!g' " + str(mediascannerpath) + "/mediaindex")
145+ self._file_find_replace(mediascannerpath + "/mediaindex", dblocation, relhome)
146
147 #patch file indexes
148- os.system("sed -i 's!" + dblocation + "!" + str(relhome) + "!g' " + str(mediascannerpath) + "/" + dbfoldername + "/_0.cfs")
149- os.system("sed -i 's!" + dblocation + "!" + str(relhome) + "!g' " + str(mediascannerpath) + "/" + dbfoldername + "/_1.cfs")
150- os.system("sed -i 's!" + dblocation + "!" + str(relhome) + "!g' " + str(mediascannerpath) + "/" + dbfoldername + "/_2.cfs")
151- os.system("sed -i 's!" + dblocation + "!" + str(relhome) + "!g' " + str(mediascannerpath) + "/" + dbfoldername + "/_3.cfs")
152+ self._file_find_replace(mediascannerpath + "/" + dbfoldername + "/_0.cfs", dblocation, relhome)
153+ self._file_find_replace(mediascannerpath + "/" + dbfoldername + "/_1.cfs", dblocation, relhome)
154+ self._file_find_replace(mediascannerpath + "/" + dbfoldername + "/_2.cfs", dblocation, relhome)
155+ self._file_find_replace(mediascannerpath + "/" + dbfoldername + "/_3.cfs", dblocation, relhome)
156+
157+ def _file_find_replace(self, in_filename, find, replace):
158+ #replace all occurences of string find with string replace
159+ #in the given file
160+ out_filename = in_filename + ".tmp"
161+ infile = open(in_filename, 'r')
162+ outfile = open(out_filename, 'w')
163+ for s in infile.xreadlines():
164+ outfile.write(s.replace(find, replace))
165+ infile.close()
166+ outfile.close()
167+
168+ #remove original file and copy new file back
169+ os.remove(in_filename)
170+ os.rename(out_filename, in_filename)
171+
172
173 @property
174 def main_view(self):
175
176=== modified file 'tests/autopilot/music_app/tests/test_music.py'
177--- tests/autopilot/music_app/tests/test_music.py 2013-09-15 13:43:45 +0000
178+++ tests/autopilot/music_app/tests/test_music.py 2013-10-01 19:27:03 +0000
179@@ -18,10 +18,9 @@
180
181 class TestMainWindow(MusicTestCase):
182
183- def test_reads_music_from_home(self):
184- """ tests if the music library is populated from our fake home
185- directory
186- """
187+ def test_reads_music_library(self):
188+ """ tests if the music library is populated from our
189+ fake mediascanner database"""
190
191 mainView = self.main_view.get_main_view()
192 title = lambda: mainView.currentTracktitle
193@@ -77,5 +76,3 @@
194 self.assertThat(mainView.isPlaying, Eventually(Equals(True)))
195 self.assertThat(title, Eventually(Equals("Swansong")))
196 self.assertThat(artist, Eventually(Equals("Josh Woodward")))
197-
198-

Subscribers

People subscribed via source and target branches

to status/vote changes: