[tracker/sam/tracker-3.0-functional-tests: 89/89] Update for changes in https://gitlab.gnome.org/GNOME/tracker/merge_requests/172



commit 85b126776498f58e66b9d6bdbd634bea80a2b606
Author: Sam Thursfield <sam afuera me uk>
Date:   Mon Jan 27 22:16:43 2020 +0100

    Update for changes in https://gitlab.gnome.org/GNOME/tracker/merge_requests/172

 tests/functional-tests/meson.build |   1 +
 tests/functional-tests/notifier.py |  24 ++------
 tests/functional-tests/query.py    | 112 +++++++++++++++++++++++++++++++++++++
 3 files changed, 119 insertions(+), 18 deletions(-)
---
diff --git a/tests/functional-tests/meson.build b/tests/functional-tests/meson.build
index f909e1450..5507e676d 100644
--- a/tests/functional-tests/meson.build
+++ b/tests/functional-tests/meson.build
@@ -14,6 +14,7 @@ config_json = configure_file(
 
 functional_tests = [
   'insertion',
+  'query',
   'sparql-bugs',
   'group-concat',
   'coalesce',
diff --git a/tests/functional-tests/notifier.py b/tests/functional-tests/notifier.py
index cfc143dd0..a40984cd5 100644
--- a/tests/functional-tests/notifier.py
+++ b/tests/functional-tests/notifier.py
@@ -32,7 +32,7 @@ import unittest as ut
 import fixtures
 
 
-REASONABLE_TIMEOUT = 10  # Time waiting for the signal to be emitted
+REASONABLE_TIMEOUT = 10000  # Time waiting for the signal to be emitted
 
 
 class TrackerNotifierTests():
@@ -51,12 +51,9 @@ class TrackerNotifierTests():
         self.results_inserts = []
         self.results_updates = []
 
-        self.notifier = self.conn.create_notifier(Tracker.NotifierFlags.NONE)
-        # FIXME: uncomment this to cause a deadlock in TrackerNotifier.
-        #self.notifier = self.conn.create_notifier(Tracker.NotifierFlags.QUERY_URN)
+        self.notifier = self.conn.create_notifier(Tracker.NotifierFlags.QUERY_URN)
         self.notifier.connect('events', self.__signal_received_cb)
 
-
     def __wait_for_signal(self):
         """
         In the callback of the signals, there should be a self.loop.quit ()
@@ -73,9 +70,7 @@ class TrackerNotifierTests():
         """
         Save the content of the signal and disconnect the callback
         """
-        logging.debug("Received TrackerNotifier::events signal with %i events", len(events))
         for event in events:
-            print("Got event in callback: %s", event)
             if event.get_event_type() == Tracker.NotifierEventType.CREATE:
                 self.results_inserts.append(event)
             elif event.get_event_type() == Tracker.NotifierEventType.UPDATE:
@@ -83,17 +78,10 @@ class TrackerNotifierTests():
             elif event.get_event_type() == Tracker.NotifierEventType.DELETE:
                 self.results_deletes.append(event)
 
-        # FIXME: I don't think this should be needed. Without it, the signal
-        # callback fires *before* the main loop is started, because it's
-        # triggered from TrackerNotifier as soon as the database update
-        # happens.
-        def callback():
-            logging.debug("Main loop processing TrackerNotifier::events signal with %i events", len(events))
-            if self.timeout_id != 0:
-                GLib.source_remove(self.timeout_id)
-                self.timeout_id = 0
-            self.loop.quit()
-        GLib.idle_add(callback)
+        if self.timeout_id != 0:
+            GLib.source_remove(self.timeout_id)
+            self.timeout_id = 0
+        self.loop.quit()
 
     def test_01_insert_contact(self):
         CONTACT = """
diff --git a/tests/functional-tests/query.py b/tests/functional-tests/query.py
new file mode 100644
index 000000000..25b13ab32
--- /dev/null
+++ b/tests/functional-tests/query.py
@@ -0,0 +1,112 @@
+# Copyright (C) 2020, Sam Thursfield <sam afuera me uk>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+#
+
+"""
+Test queries using libtracker-sparql.
+"""
+
+import gi
+gi.require_version('Tracker', '3.0')
+from gi.repository import GLib
+from gi.repository import Tracker
+
+import logging
+import unittest as ut
+
+import fixtures
+
+
+class TrackerQueryTests():
+    """
+    Query test cases for TrackerSparqlConnection.
+
+    To allow testing with both local and D-Bus connections, this test suite is
+    a mixin, which is combined with different fixtures below.
+    """
+
+    def base_setup(self):
+        self.loop = GLib.MainLoop.new(None, False)
+        self.timeout_id = 0
+
+        self.notifier = self.conn.create_notifier(Tracker.NotifierFlags.QUERY_URN)
+        self.notifier.connect('events', self.__signal_received_cb)
+
+    def __wait_for_events_signal(self):
+        """
+        In the callback of the signals, there should be a self.loop.quit ()
+        """
+        self.timeout_id = GLib.timeout_add_seconds(
+            REASONABLE_TIMEOUT, self.__timeout_on_idle)
+        self.loop.run()
+
+    def __timeout_on_idle(self):
+        self.loop.quit()
+        self.fail("Timeout, the signal never came after %i seconds!" % REASONABLE_TIMEOUT)
+
+    def __signal_received_cb(self, notifier, service, graph, events):
+        """
+        Save the content of the signal and disconnect the callback
+        """
+        logging.debug("Received TrackerNotifier::events signal with %i events", len(events))
+        for event in events:
+            if event.get_event_type() == Tracker.NotifierEventType.CREATE:
+                self.results_inserts.append(event)
+            elif event.get_event_type() == Tracker.NotifierEventType.UPDATE:
+                self.results_updates.append(event)
+            elif event.get_event_type() == Tracker.NotifierEventType.DELETE:
+                self.results_deletes.append(event)
+
+        if self.timeout_id != 0:
+            GLib.source_remove(self.timeout_id)
+            self.timeout_id = 0
+        self.loop.quit()
+
+
+    def test_row_types(self):
+        """Check the value types returned by TrackerSparqlCursor."""
+
+        CONTACT = """
+        INSERT {
+        <test://test1> a nfo:FileDataObject ;
+             nie:url <file://test.test> ;
+             nfo:fileSize 1234 .
+        }
+        """
+        self.tracker.update(CONTACT)
+        self.__wait_for_events_signal()
+
+        cursor = self.conn.query('SELECT ?url ?filesize { ?url a nfo:FileDataObject }')
+
+        cursor.next()
+        assert cursor.get_n_columns() == 2
+        assert cursor.get_value_type(0) == Tracker.SparqlValue.STRING
+        assert cursor.get_value_type(1) == Tracker.SparqlValue.INTEGER
+
+
+class TrackerLocalQueryTest (fixtures.TrackerSparqlDirectTest, TrackerQueryTests):
+    def setUp(self):
+        self.base_setup()
+
+
+class TrackerBusQueryTest (fixtures.TrackerSparqlBusTest, TrackerQueryTests):
+    def setUp(self):
+        self.base_setup()
+
+
+if __name__ == "__main__":
+    ut.main(verbosity=2)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]