diff --git a/apertis_tests_lib/__init__.py b/apertis_tests_lib/__init__.py index 9e2f0e7c8bdd6e32229eb8150e9a2a2f5a73dfd8..109589c31fa57b72a76e8e7ae323d28fe476d4e3 100644 --- a/apertis_tests_lib/__init__.py +++ b/apertis_tests_lib/__init__.py @@ -7,3 +7,40 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. +import unittest +import shutil +import os + +MEDIADIR = '/usr/lib/apertis-tests/resources/media' + +# define this here to make lint happy with too long lines +LONG_JPEG_NAME = '320px-European_Common_Frog_Rana_temporaria.jpg' + + +class ApertisTest(unittest.TestCase): + def copy_medias(self, dst): + """ + Copy media resources from apertis-tests to @dst with per media type + subdirectory corresponding to the default subdirectories in $HOME. + """ + print("ApertisTest: copying medias to " + dst) + self.__copytree(MEDIADIR + '/audio', dst + '/Music') + self.__copytree(MEDIADIR + '/documents', dst + '/Documents') + self.__copytree(MEDIADIR + '/images', dst + '/Pictures') + self.__copytree(MEDIADIR + '/playlists', dst + '/Music') + self.__copytree(MEDIADIR + '/videos', dst + '/Videos') + + def __copytree(self, root_src_dir, root_dst_dir): + # This is our own version of shutil.copytree. The difference is that + # if the destination directory already exists it adds files into it. If + # files already exists they are overwritten. + for src_dir, dirs, files in os.walk(root_src_dir): + dst_dir = src_dir.replace(root_src_dir, root_dst_dir) + if not os.path.exists(dst_dir): + os.mkdir(dst_dir) + for file_ in files: + src_file = os.path.join(src_dir, file_) + dst_file = os.path.join(dst_dir, file_) + if os.path.exists(dst_file): + os.remove(dst_file) + shutil.copy2(src_file, dst_dir) diff --git a/apertis_tests_lib/tracker.py b/apertis_tests_lib/tracker.py index b8ebce52119c09f29bd268727c2670e2cf1698b7..49133933eb10a8d04792b2850a420cc1ea5b74b6 100644 --- a/apertis_tests_lib/tracker.py +++ b/apertis_tests_lib/tracker.py @@ -15,10 +15,7 @@ from gi.repository import GLib from gi.repository import TrackerControl from gi.repository import Tracker -MEDIADIR = '/usr/lib/apertis-tests/resources/media' - -# define this here to make lint happy with too long lines -LONG_JPEG_NAME = '320px-European_Common_Frog_Rana_temporaria.jpg' +from . import LONG_JPEG_NAME class TrackerIndexer(): @@ -33,33 +30,6 @@ class TrackerIndexer(): self.loop = GLib.MainLoop.new(None, False) - def copy_medias(self, dst): - """ - Copy media resources from apertis-tests to @dst with per media type - subdirectory corresponding to the default subdirectories in $HOME. - """ - print("TrackerIndexer: copying medias to " + dst) - self.copytree(MEDIADIR + '/audio', dst + '/Music') - self.copytree(MEDIADIR + '/documents', dst + '/Documents') - self.copytree(MEDIADIR + '/images', dst + '/Pictures') - self.copytree(MEDIADIR + '/playlists', dst + '/Music') - self.copytree(MEDIADIR + '/videos', dst + '/Videos') - - def copytree(self, root_src_dir, root_dst_dir): - # This is our own version of shutil.copytree. The difference is that - # if the destination directory already exists it adds files into it. If - # files already exists they are overwritten. - for src_dir, dirs, files in os.walk(root_src_dir): - dst_dir = src_dir.replace(root_src_dir, root_dst_dir) - if not os.path.exists(dst_dir): - os.mkdir(dst_dir) - for file_ in files: - src_file = os.path.join(src_dir, file_) - dst_file = os.path.join(dst_dir, file_) - if os.path.exists(dst_file): - os.remove(dst_file) - shutil.copy2(src_file, dst_dir) - def miner_progress_cb(self, manager, miner, status, progress, remaining_time): # Ignore signal if status didn't change diff --git a/tracker/automated/test-tracker.py b/tracker/automated/test-tracker.py index f823da4c536039b7da8b008d0a1c5f567132bb2f..44e477772890daee21fd23c3a46a2dfd0725bf4b 100755 --- a/tracker/automated/test-tracker.py +++ b/tracker/automated/test-tracker.py @@ -21,15 +21,16 @@ from gi.repository import Grl sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) from apertis_tests_lib.tracker import TrackerIndexer -from apertis_tests_lib.tracker import LONG_JPEG_NAME +from apertis_tests_lib import LONG_JPEG_NAME +from apertis_tests_lib import ApertisTest -class TrackerTest(unittest.TestCase): +class TrackerTest(ApertisTest): def setUp(self): self.loop = GLib.MainLoop.new(None, False) self.homedir = os.path.expanduser("~") self.indexer = TrackerIndexer() - self.indexer.copy_medias(self.homedir) + self.copy_medias(self.homedir) # Monitor thumbnail creation to know when it's done. The DBus API # doesn't have a method to query the initial state but we can be diff --git a/tracker/manual/test-removable-device.py b/tracker/manual/test-removable-device.py index 5f412e3bb4fc99c3d3dcf471581845413a6b248f..03ba80a0fb966a350c602ecf8047b359884b7b1a 100755 --- a/tracker/manual/test-removable-device.py +++ b/tracker/manual/test-removable-device.py @@ -19,9 +19,10 @@ from gi.repository import Gio sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) from apertis_tests_lib.tracker import TrackerIndexer +from apertis_tests_lib import ApertisTest -class TestRemovableDevice(unittest.TestCase): +class TestRemovableDevice(ApertisTest): def setUp(self): self.loop = GLib.MainLoop.new(None, False) self.monitor = Gio.VolumeMonitor.get() @@ -41,7 +42,7 @@ class TestRemovableDevice(unittest.TestCase): # Copy our medias and start indexing self.indexer = TrackerIndexer() - self.indexer.copy_medias(self.path) + self.copy_medias(self.path) self.indexer.start() self.indexer.assert_all_indexed(self.path)