[tracker-miners/wip/carlosg/writeback-refactor: 11/12] tests: Restore writeback-audio and writeback-images functional tests
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/writeback-refactor: 11/12] tests: Restore writeback-audio and writeback-images functional tests
- Date: Thu, 21 May 2020 14:24:25 +0000 (UTC)
commit 4bc5e0ef8dcdee036aba1f8b60d03db6876fc90f
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed May 20 22:28:42 2020 +0200
tests: Restore writeback-audio and writeback-images functional tests
Make these test the new DBus API.
tests/functional-tests/fixtures.py | 31 ++++++++++++------
tests/functional-tests/writeback-audio.py | 22 ++++++-------
tests/functional-tests/writeback-images.py | 50 ++++++++++++++++++++----------
3 files changed, 65 insertions(+), 38 deletions(-)
---
diff --git a/tests/functional-tests/fixtures.py b/tests/functional-tests/fixtures.py
index 95f27c7c8..5acaeb6a7 100644
--- a/tests/functional-tests/fixtures.py
+++ b/tests/functional-tests/fixtures.py
@@ -25,7 +25,8 @@ Fixtures used by the tracker-miners functional-tests.
import gi
gi.require_version('Gst', '1.0')
gi.require_version('Tracker', '3.0')
-from gi.repository import GLib
+gi.require_version('Gio', '2.0')
+from gi.repository import GLib, Gio
from gi.repository import Tracker
import errno
@@ -396,35 +397,47 @@ TEST_FILE_JPEG = "writeback-test-1.jpeg"
TEST_FILE_TIFF = "writeback-test-2.tif"
TEST_FILE_PNG = "writeback-test-4.png"
-
class TrackerWritebackTest (TrackerMinerTest):
"""
Superclass to share methods. Shouldn't be run by itself.
Start all processes including writeback, miner pointing to WRITEBACK_TMP_DIR
"""
+ WRITEBACK_BUSNAME = "org.freedesktop.Tracker3.Writeback"
+ WRITEBACK_PATH = "/org/freedesktop/Tracker3/Writeback"
+ WRITEBACK_IFACE = "org.freedesktop.Tracker3.Writeback"
+
+ def setUp(self):
+ super(TrackerWritebackTest, self).setUp()
+ self.writeback_proxy = Gio.DBusProxy.new_sync(
+ self.sandbox.get_connection(),
+ Gio.DBusProxyFlags.DO_NOT_AUTO_START_AT_CONSTRUCTION, None,
+ self.WRITEBACK_BUSNAME, self.WRITEBACK_PATH, self.WRITEBACK_IFACE)
def datadir_path(self, filename):
"""Returns the full path to a writeback test file."""
datadir = os.path.join(os.path.dirname(__file__), 'test-writeback-data')
return pathlib.Path(os.path.join(datadir, filename))
+ def writeback_data(self, variant):
+ self.writeback_proxy.Writeback('(a{sv})', variant)
+
def prepare_test_audio(self, filename):
path = pathlib.Path(os.path.join(self.indexed_dir, os.path.basename(filename)))
url = path.as_uri()
- # Copy and wait. The extractor adds the nfo:duration property.
- expected = f'a nfo:Audio ; nie:isStoredAs <{url}> ; nfo:duration ?duration'
- with self.tracker.await_insert(AUDIO_GRAPH, expected):
- shutil.copy(path, self.indexed_dir)
+ # Copy and wait.
+ expected = f'nie:url <{url}>'
+ with self.tracker.await_insert(FILESYSTEM_GRAPH, expected):
+ shutil.copy(filename, self.indexed_dir)
return path
def prepare_test_image(self, source_path):
dest_path = pathlib.Path(os.path.join(self.indexed_dir, os.path.basename(source_path)))
url = dest_path.as_uri()
- # Copy and wait. The extractor adds the nfo:width property.
- expected = f'a nfo:Image ; nie:isStoredAs <{url}> ; nfo:width ?width'
- with self.tracker.await_insert(PICTURES_GRAPH, expected):
+ # Copy and wait.
+ expected = f'nie:url <{url}>'
+ with self.tracker.await_insert(FILESYSTEM_GRAPH, expected):
shutil.copy(source_path, self.indexed_dir)
return dest_path
diff --git a/tests/functional-tests/writeback-audio.py b/tests/functional-tests/writeback-audio.py
index 8543507f7..dd9b1fbc5 100755
--- a/tests/functional-tests/writeback-audio.py
+++ b/tests/functional-tests/writeback-audio.py
@@ -20,25 +20,27 @@ import unittest
import fixtures
+import gi
+from gi.repository import GLib
class WritebackAudioTest(fixtures.TrackerWritebackTest):
def _writeback_test(self, path):
prop = 'nie:title'
- path = self.prepare_test_audio(path)
+ path = self.prepare_test_audio(self.datadir_path(path))
initial_mtime = path.stat().st_mtime
TEST_VALUE = prop.replace(":", "") + "test"
- SPARQL_TMPL = """
- DELETE { ?u a nie:InformationElement; %s ?v } WHERE { ?u nie:url '%s' ; %s ?v }
- INSERT { ?u a nie:InformationElement; %s '%s' }
- WHERE { ?u nie:url '%s' }
- """
- self.tracker.update(SPARQL_TMPL % (prop, path.as_uri(), prop, prop, TEST_VALUE, path.as_uri()))
+
+ self.writeback_data({
+ 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type': GLib.Variant('s',
'http://tracker.api.gnome.org/ontology/v3/nfo#Audio'),
+ 'http://tracker.api.gnome.org/ontology/v3/nie#isStoredAs': GLib.Variant('s', path.as_uri()),
+ 'http://tracker.api.gnome.org/ontology/v3/nie#title': GLib.Variant('s', TEST_VALUE),
+ })
self.wait_for_file_change(path, initial_mtime)
- results = fixtures.get_tracker_extract_jsonld_output(self.extra_env, path)
+ results = fixtures.get_tracker_extract_jsonld_output({}, path)
self.assertIn(TEST_VALUE, results[prop])
def test_writeback_mp3(self):
@@ -54,8 +56,4 @@ class WritebackAudioTest(fixtures.TrackerWritebackTest):
self._writeback_test(self.datadir_path('writeback-test-8.mp4'))
if __name__ == "__main__":
- print("FIXME: This test is skipped as it currently fails. See:
https://gitlab.gnome.org/GNOME/tracker-miners/issues/96")
- import sys
- sys.exit(77)
-
unittest.main(failfast=True, verbosity=2)
diff --git a/tests/functional-tests/writeback-images.py b/tests/functional-tests/writeback-images.py
index e455b7210..d5f167e55 100755
--- a/tests/functional-tests/writeback-images.py
+++ b/tests/functional-tests/writeback-images.py
@@ -26,6 +26,9 @@ import unittest as ut
import configuration
import fixtures
+import gi
+from gi.repository import GLib
+
log = logging.getLogger(__name__)
@@ -50,18 +53,17 @@ class WritebackImagesTest(fixtures.TrackerWritebackTest):
initial_mtime = path.stat().st_mtime
TEST_VALUE = prop.replace(":", "") + "test"
- SPARQL_TMPL = """
- DELETE { ?u %s ?v } WHERE { ?u nie:url '%s' ; %s ?v }
- INSERT { ?u a nie:InformationElement; %s '%s' }
- WHERE { ?u nie:url '%s' }
- """
- self.tracker.update(SPARQL_TMPL % (prop, path.as_uri(), prop, prop, TEST_VALUE, path.as_uri()))
+ self.writeback_data({
+ 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type': GLib.Variant('s',
'http://tracker.api.gnome.org/ontology/v3/nfo#Image'),
+ 'http://tracker.api.gnome.org/ontology/v3/nie#isStoredAs': GLib.Variant('s', path.as_uri()),
+ prop: GLib.Variant('s', TEST_VALUE),
+ })
log.debug("Waiting for change on %s", path)
self.wait_for_file_change(path, initial_mtime)
log.debug("Got the change")
- results = fixtures.get_tracker_extract_jsonld_output(self.extra_env, path, mimetype)
+ results = fixtures.get_tracker_extract_jsonld_output({}, path, mimetype)
keyDict = expectedKey or prop
self.assertIn(TEST_VALUE, results[keyDict])
@@ -91,10 +93,16 @@ class WritebackImagesTest(fixtures.TrackerWritebackTest):
# JPEG test
def test_001_jpeg_title(self):
- self.__writeback_test("writeback-test-1.jpeg", "image/jpeg", "nie:title")
+ self.__writeback_test(
+ "writeback-test-1.jpeg", "image/jpeg",
+ "http://tracker.api.gnome.org/ontology/v3/nie#title",
+ "nie:title")
def test_002_jpeg_description(self):
- self.__writeback_test("writeback-test-1.jpeg", "image/jpeg", "nie:description")
+ self.__writeback_test(
+ "writeback-test-1.jpeg", "image/jpeg",
+ "http://tracker.api.gnome.org/ontology/v3/nie#description",
+ "nie:description")
# def test_003_jpeg_keyword (self):
# #FILENAME = "test-writeback-monitored/writeback-test-1.jpeg"
@@ -108,10 +116,16 @@ class WritebackImagesTest(fixtures.TrackerWritebackTest):
# TIFF tests
def test_011_tiff_title(self):
- self.__writeback_test("writeback-test-2.tif", "image/tiff", "nie:title")
+ self.__writeback_test(
+ "writeback-test-2.tif", "image/tiff",
+ "http://tracker.api.gnome.org/ontology/v3/nie#title",
+ "nie:title")
def test_012_tiff_description(self):
- self.__writeback_test("writeback-test-2.tif", "image/tiff", "nie:description")
+ self.__writeback_test(
+ "writeback-test-2.tif", "image/tiff",
+ "http://tracker.api.gnome.org/ontology/v3/nie#description",
+ "nie:description")
# def test_013_tiff_keyword (self):
# FILENAME = "test-writeback-monitored/writeback-test-2.tif"
@@ -125,10 +139,16 @@ class WritebackImagesTest(fixtures.TrackerWritebackTest):
# PNG tests
def test_021_png_title(self):
- self.__writeback_test("writeback-test-4.png", "image/png", "nie:title")
+ self.__writeback_test(
+ "writeback-test-4.png", "image/png",
+ "http://tracker.api.gnome.org/ontology/v3/nie#title",
+ "nie:title")
def test_022_png_description(self):
- self.__writeback_test("writeback-test-4.png", "image/png", "nie:description")
+ self.__writeback_test(
+ "writeback-test-4.png", "image/png",
+ "http://tracker.api.gnome.org/ontology/v3/nie#description",
+ "nie:description")
# def test_023_png_keyword (self):
# FILENAME = "test-writeback-monitored/writeback-test-4.png"
@@ -140,8 +160,4 @@ class WritebackImagesTest(fixtures.TrackerWritebackTest):
if __name__ == "__main__":
- print("FIXME: This test is skipped as it currently fails. See:
https://gitlab.gnome.org/GNOME/tracker-miners/issues/96")
- import sys
- sys.exit(77)
-
ut.main(failfast=True, verbosity=2)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]