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
=== removed directory 'tests/autopilot/music_app/emulators'
=== renamed file 'tests/autopilot/music_app/emulators/emulators.py' => 'tests/autopilot/music_app/emulators.py'
--- tests/autopilot/music_app/emulators/emulators.py 2013-09-27 15:14:10 +0000
+++ tests/autopilot/music_app/emulators.py 2013-10-01 19:27:03 +0000
@@ -6,10 +6,11 @@
6# by the Free Software Foundation.6# by the Free Software Foundation.
77
8"""Music app autopilot emulators."""8"""Music app autopilot emulators."""
99from ubuntuuitoolkit import emulators as toolkit_emulators
10from ubuntuuitoolkit import emulators as uitk10
1111
12class MainView(uitk.MainView):12class MainView(toolkit_emulators.MainView):
13
13 """An emulator class that makes it easy to interact with the14 """An emulator class that makes it easy to interact with the
14 music-app.15 music-app.
15 """16 """
@@ -29,11 +30,11 @@
29 """Returns the item that is searched for with app.select_many30 """Returns the item that is searched for with app.select_many
30 In case of no item was not found (not created yet) a second attempt is31 In case of no item was not found (not created yet) a second attempt is
31 taken 1 second later"""32 taken 1 second later"""
32 items = self.select_many(object_type, **kwargs)33 items = self.app.select_many(object_type, **kwargs)
33 tries = 1034 tries = 10
34 while len(items) < 1 and tries > 0:35 while len(items) < 1 and tries > 0:
35 sleep(self.retry_delay)36 sleep(self.app.retry_delay)
36 items = self.select_many(object_type, **kwargs)37 items = self.app.select_many(object_type, **kwargs)
37 tries = tries - 138 tries = tries - 1
38 return items39 return items
3940
@@ -41,19 +42,19 @@
41 """Returns the item that is searched for with app.select_single42 """Returns the item that is searched for with app.select_single
42 In case of the item was not found (not created yet) a second attempt is43 In case of the item was not found (not created yet) a second attempt is
43 taken 1 second later."""44 taken 1 second later."""
44 item = self.select_single(object_type, **kwargs)45 item = self.app.select_single(object_type, **kwargs)
45 tries = 1046 tries = 10
46 while item is None and tries > 0:47 while item is None and tries > 0:
47 sleep(self.retry_delay)48 sleep(self.app.retry_delay)
48 item = self.select_single(object_type, **kwargs)49 item = self.app.select_single(object_type, **kwargs)
49 tries = tries - 150 tries = tries - 1
50 return item51 return item
5152
52 def tap_item(self, item):53 def tap_item(self, item):
53 self.pointing_device.move_to_object(item)54 self.app.pointing_device.move_to_object(item)
54 self.pointing_device.press()55 self.app.pointing_device.press()
55 sleep(2)56 sleep(2)
56 self.pointing_device.release()57 self.app.pointing_device.release()
5758
58 def get_play_button(self):59 def get_play_button(self):
59 return self.app.select_single("UbuntuShape", objectName = "playshape")60 return self.app.select_single("UbuntuShape", objectName = "playshape")
6061
=== removed file 'tests/autopilot/music_app/emulators/__init__.py'
--- tests/autopilot/music_app/emulators/__init__.py 2013-06-21 23:06:10 +0000
+++ tests/autopilot/music_app/emulators/__init__.py 1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
1# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2# Copyright 2013 Canonical
3#
4# This program is free software: you can redistribute it and/or modify it
5# under the terms of the GNU General Public License version 3, as published
6# by the Free Software Foundation.
70
=== modified file 'tests/autopilot/music_app/tests/__init__.py'
--- tests/autopilot/music_app/tests/__init__.py 2013-09-27 21:55:49 +0000
+++ tests/autopilot/music_app/tests/__init__.py 2013-10-01 19:27:03 +0000
@@ -13,15 +13,17 @@
13import os13import os
14import os.path14import os.path
15import shutil15import shutil
16import logging
1617
17from autopilot.input import Mouse, Touch, Pointer18from autopilot.input import Mouse, Touch, Pointer
18from autopilot.platform import model19from autopilot.platform import model
19from autopilot.testcase import AutopilotTestCase20from autopilot.testcase import AutopilotTestCase
2021
21from time import sleep22from ubuntuuitoolkit import emulators as toolkit_emulators
2223from music_app.emulators import MainView
23from ubuntuuitoolkit import emulators as uitk24
24from music_app.emulators.emulators import MainView25logger = logging.getLogger(__name__)
26
2527
26class MusicTestCase(AutopilotTestCase):28class MusicTestCase(AutopilotTestCase):
2729
@@ -78,22 +80,30 @@
78 shutil.rmtree(temp_dir)80 shutil.rmtree(temp_dir)
79 temp_dir = temp_dir.ljust(25, 'X')81 temp_dir = temp_dir.ljust(25, 'X')
80 os.mkdir(temp_dir)82 os.mkdir(temp_dir)
83 logger.debug("Created fake home directory " + temp_dir)
81 self.addCleanup(shutil.rmtree, temp_dir)84 self.addCleanup(shutil.rmtree, temp_dir)
82 patcher = mock.patch.dict('os.environ', {'HOME': temp_dir})85 patcher = mock.patch.dict('os.environ', {'HOME': temp_dir})
83 patcher.start()86 patcher.start()
87 logger.debug("Patched home to fake home directory " + temp_dir)
84 self.addCleanup(patcher.stop)88 self.addCleanup(patcher.stop)
8589
86 def _create_music_library(self):90 def _create_music_library(self):
87 #use fake home91 #use fake home
88 home = os.environ['HOME']92 home = os.environ['HOME']
93 logger.debug("Home set to " + home)
89 musicpath = home + '/Music'94 musicpath = home + '/Music'
95 logger.debug("Music path set to " + musicpath)
90 mediascannerpath = home + '/.cache/mediascanner'96 mediascannerpath = home + '/.cache/mediascanner'
91 os.mkdir(musicpath)97 os.mkdir(musicpath)
98 logger.debug("Mediascanner path set to " + mediascannerpath)
9299
93 #copy over our index100 #copy over our index
94 shutil.copytree(self.working_dir + '/music_app/content/mediascanner',101 shutil.copytree(self.working_dir + '/music_app/content/mediascanner',
95 mediascannerpath)102 mediascannerpath)
96103
104 logger.debug("Mediascanner database copied, files " + str(os.listdir(mediascannerpath)))
105
106 #copy over the music
97 if os.path.exists(self.local_location):107 if os.path.exists(self.local_location):
98 shutil.copy(self.working_dir + '/music_app/content/'108 shutil.copy(self.working_dir + '/music_app/content/'
99 +'1.ogg',109 +'1.ogg',
@@ -109,20 +119,39 @@
109 +'2.ogg',119 +'2.ogg',
110 musicpath)120 musicpath)
111121
122 logger.debug("Music copied, files " + str(os.listdir(musicpath)))
123
112 #do some inline db patching124 #do some inline db patching
113 #patch mediaindex to proper home125 #patch mediaindex to proper home
114 #these values are dependent upon our sampled db126 #these values are dependent upon our sampled db
127 logger.debug("Patching fake mediascanner database")
115 relhome = home[1:]128 relhome = home[1:]
116 dblocation = "home/autopilot-music-app"129 dblocation = "home/autopilot-music-app"
117 dbfoldername = "ea50858c-4b21-4f87-9005-40aa960a84a3"130 dbfoldername = "ea50858c-4b21-4f87-9005-40aa960a84a3"
118 #patch mediaindex131 #patch mediaindex
119 os.system("sed -i 's!" + dblocation + "!" + str(relhome) + "!g' " + str(mediascannerpath) + "/mediaindex")132 self._file_find_replace(mediascannerpath + "/mediaindex", dblocation, relhome)
120133
121 #patch file indexes134 #patch file indexes
122 os.system("sed -i 's!" + dblocation + "!" + str(relhome) + "!g' " + str(mediascannerpath) + "/" + dbfoldername + "/_0.cfs")135 self._file_find_replace(mediascannerpath + "/" + dbfoldername + "/_0.cfs", dblocation, relhome)
123 os.system("sed -i 's!" + dblocation + "!" + str(relhome) + "!g' " + str(mediascannerpath) + "/" + dbfoldername + "/_1.cfs")136 self._file_find_replace(mediascannerpath + "/" + dbfoldername + "/_1.cfs", dblocation, relhome)
124 os.system("sed -i 's!" + dblocation + "!" + str(relhome) + "!g' " + str(mediascannerpath) + "/" + dbfoldername + "/_2.cfs")137 self._file_find_replace(mediascannerpath + "/" + dbfoldername + "/_2.cfs", dblocation, relhome)
125 os.system("sed -i 's!" + dblocation + "!" + str(relhome) + "!g' " + str(mediascannerpath) + "/" + dbfoldername + "/_3.cfs")138 self._file_find_replace(mediascannerpath + "/" + dbfoldername + "/_3.cfs", dblocation, relhome)
139
140 def _file_find_replace(self, in_filename, find, replace):
141 #replace all occurences of string find with string replace
142 #in the given file
143 out_filename = in_filename + ".tmp"
144 infile = open(in_filename, 'r')
145 outfile = open(out_filename, 'w')
146 for s in infile.xreadlines():
147 outfile.write(s.replace(find, replace))
148 infile.close()
149 outfile.close()
150
151 #remove original file and copy new file back
152 os.remove(in_filename)
153 os.rename(out_filename, in_filename)
154
126155
127 @property156 @property
128 def main_view(self):157 def main_view(self):
129158
=== modified file 'tests/autopilot/music_app/tests/test_music.py'
--- tests/autopilot/music_app/tests/test_music.py 2013-09-15 13:43:45 +0000
+++ tests/autopilot/music_app/tests/test_music.py 2013-10-01 19:27:03 +0000
@@ -18,10 +18,9 @@
1818
19class TestMainWindow(MusicTestCase):19class TestMainWindow(MusicTestCase):
2020
21 def test_reads_music_from_home(self):21 def test_reads_music_library(self):
22 """ tests if the music library is populated from our fake home22 """ tests if the music library is populated from our
23 directory23 fake mediascanner database"""
24 """
2524
26 mainView = self.main_view.get_main_view()25 mainView = self.main_view.get_main_view()
27 title = lambda: mainView.currentTracktitle26 title = lambda: mainView.currentTracktitle
@@ -77,5 +76,3 @@
77 self.assertThat(mainView.isPlaying, Eventually(Equals(True)))76 self.assertThat(mainView.isPlaying, Eventually(Equals(True)))
78 self.assertThat(title, Eventually(Equals("Swansong")))77 self.assertThat(title, Eventually(Equals("Swansong")))
79 self.assertThat(artist, Eventually(Equals("Josh Woodward")))78 self.assertThat(artist, Eventually(Equals("Josh Woodward")))
80
81

Subscribers

People subscribed via source and target branches

to status/vote changes: