Skip to content
Snippets Groups Projects
Commit 7257dd3e authored by Xavier Claessens's avatar Xavier Claessens Committed by Sjoerd Simons
Browse files

tracker: factor out a base class for python tests

Reviewers: smcv, pwith

Differential Revision: https://phabricator.apertis.org/D542
parent b379c632
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......@@ -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
......
......@@ -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
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment