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

tracker: use the mixin pattern in TrackerIndexerMixin

Summary:
This allows it to use self.assertEqual() and friends to
properly mark the test as failed.

Reviewers: smcv, pwith

Differential Revision: https://phabricator.apertis.org/D543
parent 7257dd3e
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@ from gi.repository import Tracker
from . import LONG_JPEG_NAME
class TrackerIndexer():
class TrackerIndexerMixin:
def __init__(self):
# Stop tracker and reset its DB
subprocess.check_call(
......@@ -96,16 +96,13 @@ class TrackerIndexer():
# Must have one and only one result
cursor = self.conn.query(query, None)
if not cursor.next(None):
raise Exception("Query '%s' returned no result" % query)
if cursor.next(None):
raise Exception("Query '%s' returned more than one result" % query)
self.assertTrue(cursor.next(None))
self.assertFalse(cursor.next(None))
def assert_not_indexed(self, path):
query = ('select ?urn where { ?urn nie:url "file://%s" }') % (path)
cursor = self.conn.query(query, None)
if cursor.next(None):
raise Exception("Query '%s' returned results" % query)
self.assertFalse(cursor.next(None))
def assert_all_indexed(self, root):
playable_query = '?urn bosch:playable true . '
......
......@@ -20,16 +20,19 @@ from gi.repository import Grl
# import from toplevel directory
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 LONG_JPEG_NAME
from apertis_tests_lib.tracker import TrackerIndexerMixin
from apertis_tests_lib import ApertisTest
from apertis_tests_lib import LONG_JPEG_NAME
class TrackerTest(ApertisTest, TrackerIndexerMixin):
def __init__(self, *args, **kwargs):
ApertisTest.__init__(self, *args, **kwargs)
TrackerIndexerMixin.__init__(self)
class TrackerTest(ApertisTest):
def setUp(self):
self.loop = GLib.MainLoop.new(None, False)
self.homedir = os.path.expanduser("~")
self.indexer = TrackerIndexer()
self.copy_medias(self.homedir)
# Monitor thumbnail creation to know when it's done. The DBus API
......@@ -104,7 +107,7 @@ class TrackerTest(ApertisTest):
def tracker_initial_tests(self):
print("TrackerTest: initial tests")
self.indexer.assert_all_indexed(self.homedir)
self.assert_all_indexed(self.homedir)
def tracker_update_tests(self):
print("TrackerTest: update tests")
......@@ -113,21 +116,20 @@ class TrackerTest(ApertisTest):
filename = self.homedir + '/Documents/something.txt'
with open(filename, 'w') as f:
f.write('something')
self.indexer.wait(True)
self.indexer.assert_indexed(
filename, '?urn nie:plainTextContent "something"')
self.wait(True)
self.assert_indexed(filename, '?urn nie:plainTextContent "something"')
# Modify the file should re-index it
with open(filename, 'w') as f:
f.write('something else')
self.indexer.wait(True)
self.indexer.assert_indexed(
self.wait(True)
self.assert_indexed(
filename, '?urn nie:plainTextContent "something else"')
# Delete file and assert it's not indexed anymore
os.remove(filename)
self.indexer.wait(False)
self.indexer.assert_not_indexed(filename)
self.wait(False)
self.assert_not_indexed(filename)
def assert_has_thumbnail(self, filename):
# Note that this is the path for local storage only, not for removable
......@@ -218,7 +220,7 @@ class TrackerTest(ApertisTest):
def test_all(self):
self.tracker_config_tests()
self.tracker_journal_tests()
self.indexer.start()
self.start()
self.tracker_initial_tests()
self.tracker_update_tests()
self.tracker_grilo_tests()
......
......@@ -18,11 +18,15 @@ from gi.repository import Gio
# import from toplevel directory
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 TrackerIndexerMixin
from apertis_tests_lib import ApertisTest
class TestRemovableDevice(ApertisTest):
class TestRemovableDevice(ApertisTest, TrackerIndexerMixin):
def __init__(self, *args, **kwargs):
ApertisTest.__init__(self, *args, **kwargs)
TrackerIndexerMixin.__init__(self)
def setUp(self):
self.loop = GLib.MainLoop.new(None, False)
self.monitor = Gio.VolumeMonitor.get()
......@@ -41,10 +45,9 @@ class TestRemovableDevice(ApertisTest):
self.loop.run()
# Copy our medias and start indexing
self.indexer = TrackerIndexer()
self.copy_medias(self.path)
self.indexer.start()
self.indexer.assert_all_indexed(self.path)
self.start()
self.assert_all_indexed(self.path)
if __name__ == "__main__":
unittest.main()
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