[tracker/wip/sam/meson-functional-tests: 10/10] functional-tests: Fix tests that depend on generated .ttl files



commit 76505bcd1fe490fb6d61896ce37b7672c450514f
Author: Sam Thursfield <sam thursfield codethink co uk>
Date:   Wed Nov 1 18:05:50 2017 +0000

    functional-tests: Fix tests that depend on generated .ttl files
    
    These now execute as expected. Not all of them actually work though.

 tests/functional-tests/10-sqlite-misused.py        |   27 +++++++++++---------
 tests/functional-tests/11-sqlite-batch-misused.py  |   27 ++++++++++---------
 tests/functional-tests/13-threaded-store.py        |    4 +-
 tests/functional-tests/common/utils/helpers.py     |    3 ++
 .../functional-tests/configuration/__init__.py.in  |    9 ++++++
 tests/functional-tests/meson.build                 |   26 +++++++++++-------
 6 files changed, 59 insertions(+), 37 deletions(-)
---
diff --git a/tests/functional-tests/10-sqlite-misused.py b/tests/functional-tests/10-sqlite-misused.py
index 75ac7c2..d96969b 100755
--- a/tests/functional-tests/10-sqlite-misused.py
+++ b/tests/functional-tests/10-sqlite-misused.py
@@ -36,20 +36,24 @@ class TestSqliteMisused (CommonTrackerStoreTest):
     def setUp (self):
         self.main_loop = GObject.MainLoop ()
         self.files_counter = 0
-        
+
     def test_queries_while_import (self):
-        self.assertTrue (os.path.exists ('ttl'))
-        for root, dirs, files in os.walk('ttl'):
+        assert os.path.isdir(cfg.generated_ttl_dir())
+
+        for root, dirs, files in os.walk(cfg.generated_ttl_dir()):
             for ttl_file in filter (lambda f: f.endswith (".ttl"), files):
                 full_path = os.path.abspath(os.path.join (root, ttl_file))
                 self.files_counter += 1
-                self.tracker.query(
+
+                self.tracker.load(
                     "file://" + full_path, timeout=30000,
                     result_handler=self.loaded_success_cb,
-                    error_handler=self.loaded_failed_cb)
+                    error_handler=self.loaded_failed_cb,
+                    user_data = full_path)
 
         GObject.timeout_add_seconds (2, self.run_a_query)
         # Safeguard of 60 seconds. The last reply should quit the loop
+        # It doesn't matter if we didn't import all of the files yet.
         GObject.timeout_add_seconds (60, self.timeout_cb)
         self.main_loop.run ()
 
@@ -64,19 +68,18 @@ class TestSqliteMisused (CommonTrackerStoreTest):
     def reply_cb (self, obj, results, data):
         print "Query replied correctly"
 
-    def error_handler (self, error_msg):
-        print "ERROR in DBus call", error_msg
+    def error_handler (self, obj, error, data):
+        print "ERROR in DBus call: %s" % error
 
-    def loaded_success_cb (self, obj, results, data):
+    def loaded_success_cb (self, obj, results, user_data):
         self.files_counter -= 1
         if (self.files_counter == 0):
             print "Last file loaded"
             self.timeout_cb ()
-        print "Success loading a file"
+        print "Success loading %s" % user_data
 
-    def loaded_failed_cb (self, error):
-        print "Failed loading a file"
-        self.assertTrue (False)
+    def loaded_failed_cb (self, obj, error, user_data):
+        raise RuntimeError("Failed loading %s: %s" % (user_data, error))
 
     def timeout_cb (self):
         print "Forced timeout after 60 sec."
diff --git a/tests/functional-tests/11-sqlite-batch-misused.py 
b/tests/functional-tests/11-sqlite-batch-misused.py
index de79f81..6ab13ab 100755
--- a/tests/functional-tests/11-sqlite-batch-misused.py
+++ b/tests/functional-tests/11-sqlite-batch-misused.py
@@ -41,11 +41,11 @@ class TestSqliteBatchMisused (CommonTrackerStoreTest):
     def setUp (self):
         self.main_loop = GObject.MainLoop ()
         self.batch_counter = 0
-        
+
     def test_queries_while_batch_insert (self):
-        self.assertTrue (os.path.exists ('ttl'))
-        
-        for root, dirs, files in os.walk('ttl'):
+        self.assertTrue (os.path.exists (cfg.generated_ttl_dir()))
+
+        for root, dirs, files in os.walk(cfg.generated_ttl_dir()):
             for ttl_file in filter (lambda f: f.endswith (".ttl"), files):
                 full_path = os.path.abspath(os.path.join (root, ttl_file))
                 print full_path
@@ -58,10 +58,10 @@ class TestSqliteBatchMisused (CommonTrackerStoreTest):
                     current_batch += line
                     if len(line) > 1 and line[:-1].endswith ('.'):
                         counter += 1
-                
-                    if counter == BATCH_SIZE:
+
+                    if counter >= BATCH_SIZE:
                         query = "INSERT {" + current_batch + "}"
-                        self.tracker.batch_update(
+                        token = self.tracker.batch_update(
                             query,
                             timeout=20000,
                             result_handler=self.batch_success_cb,
@@ -70,8 +70,7 @@ class TestSqliteBatchMisused (CommonTrackerStoreTest):
                         counter = 0
                         current_batch = ""
                         self.batch_counter += 1
-                        
-        
+
         GObject.timeout_add_seconds (2, self.run_a_query)
         # Safeguard of 60 seconds. The last reply should quit the loop
         GObject.timeout_add_seconds (60, self.timeout_cb)
@@ -84,22 +83,24 @@ class TestSqliteBatchMisused (CommonTrackerStoreTest):
             reply_handler=self.reply_cb,
             error_handler=self.error_handler)
         return True
-        
+
     def reply_cb (self, obj, results, data):
         print "Query replied correctly"
 
     def error_handler (self, error_msg):
         print "Query failed", error_msg
+        raise error_msg
 
-    def batch_success_cb (self):
+    def batch_success_cb (self, obj, result, user_data):
         self.batch_counter -= 1
         if (self.batch_counter == 0):
             print "Last batch was success"
             self.timeout_cb ()
         print "Success processing a batch"
 
-    def batch_failed_cb (self, error):
-        print "Failed processing a batch"
+    def batch_failed_cb (self, obj, error, user_data):
+        print "Failed processing a batch: %s" % error
+        raise error
 
     def timeout_cb (self):
         print "Forced timeout after 60 sec."
diff --git a/tests/functional-tests/13-threaded-store.py b/tests/functional-tests/13-threaded-store.py
index 9032250..9cba71a 100755
--- a/tests/functional-tests/13-threaded-store.py
+++ b/tests/functional-tests/13-threaded-store.py
@@ -52,7 +52,7 @@ class TestThreadedStore (CommonTrackerStoreTest):
 
     def __populate_database (self):
 
-        self.assertTrue (os.path.exists ('ttl'))
+        self.assertTrue (os.path.exists (cfg.generated_ttl_dir()))
         for ttl_file in ["010-nco_EmailAddress.ttl",
                          "011-nco_PostalAddress.ttl",
                          "012-nco_PhoneNumber.ttl",
@@ -61,7 +61,7 @@ class TestThreadedStore (CommonTrackerStoreTest):
                          "018-nco_PersonContact.ttl",
                          "012-nco_PhoneNumber.ttl",
                          "016-nco_ContactIM.ttl"]:
-            full_path = os.path.abspath(os.path.join ("ttl", ttl_file))
+            full_path = os.path.abspath(os.path.join (cfg.generated_ttl_dir(), ttl_file))
             print full_path
             self.tracker.get_tracker_iface().Load(
                 '(s)', "file://" + full_path, timeout=30000)
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index 38458cc..974aedd 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -480,6 +480,9 @@ class StoreHelper (Helper):
     def update (self, update_sparql, timeout=5000, **kwargs):
         return self.resources.SparqlUpdate ('(s)', update_sparql, timeout=timeout, **kwargs)
 
+    def load (self, ttl_uri, timeout=5000, **kwargs):
+        return self.resources.Load ('(s)', ttl_uri, timeout=timeout, **kwargs)
+
     def batch_update (self, update_sparql, **kwargs):
         return self.resources.BatchSparqlUpdate ('(s)', update_sparql, **kwargs)
 
diff --git a/tests/functional-tests/configuration/__init__.py.in 
b/tests/functional-tests/configuration/__init__.py.in
index 06d5374..b9d5fc5 100644
--- a/tests/functional-tests/configuration/__init__.py.in
+++ b/tests/functional-tests/configuration/__init__.py.in
@@ -92,3 +92,12 @@ if TEST_TMP_DIR.startswith('/tmp'):
                print ("HOME is in the /tmp prefix - this will cause tests that rely " +
                       "on filesystem monitoring to fail as changes in that prefix are " +
                       "ignored.")
+
+
+BUILD_DIR = os.environ.get('TRACKER_FUNCTIONAL_TEST_BUILD_DIR')
+
+def generated_ttl_dir():
+    if BUILD_DIR:
+        return os.path.join(BUILD_DIR, 'tests', 'functional-tests', 'ttl')
+    else:
+        return 'ttl'
diff --git a/tests/functional-tests/meson.build b/tests/functional-tests/meson.build
index d50feb2..7128fbd 100644
--- a/tests/functional-tests/meson.build
+++ b/tests/functional-tests/meson.build
@@ -13,10 +13,7 @@ functional_tests = [
   '07-graph',
   '08-unique-insertions',
   '09-concurrent-query',
-  '10-sqlite-misused',
-  '11-sqlite-batch-misused',
   '12-transactions',
-  '13-threaded-store',
   '14-signals',
   '15-statistics',
   '16-collation',
@@ -24,20 +21,29 @@ functional_tests = [
   '200-backup-restore',
 ]
 
+subdir('ttl')
+functional_tests_with_test_data = [
+  '10-sqlite-misused',
+  '11-sqlite-batch-misused',
+  '13-threaded-store',
+]
+
 tracker_top_build_dir = join_paths(meson.current_build_dir(), '..', '..')
 
 tracker_nepomuk_ontologies = join_paths(meson.current_source_dir(), '..', '..', 'src', 'ontologies', 
'nepomuk')
 tracker_test_domain_ontology = join_paths(meson.current_source_dir(), '..', '..', 'src', 'tracker-store', 
'default.rule')
 
-foreach t: functional_tests
+test_env = [
+  'PYTHONPATH=@0@'.format(meson.current_build_dir()),
+  'TRACKER_FUNCTIONAL_TEST_BUILD_DIR=@0@'.format(tracker_top_build_dir),
+  'TRACKER_DB_ONTOLOGIES_DIR=@0@'.format(tracker_nepomuk_ontologies),
+  'TRACKER_TEST_DOMAIN_ONTOLOGY_RULE=@0@'.format(tracker_test_domain_ontology),
+]
+
+foreach t: functional_tests + functional_tests_with_test_data
   test('functional-' + t, test_runner,
     args: './' + t + '.py',
-    env: [
-        'PYTHONPATH=@0@'.format(meson.current_build_dir()),
-        'TRACKER_FUNCTIONAL_TEST_BUILD_DIR=@0@'.format(tracker_top_build_dir),
-        'TRACKER_DB_ONTOLOGIES_DIR=@0@'.format(tracker_nepomuk_ontologies),
-        'TRACKER_TEST_DOMAIN_ONTOLOGY_RULE=@0@'.format(tracker_test_domain_ontology),
-    ],
+    env: test_env,
     workdir: meson.current_source_dir(),
     # FIXME: these tests are all too slow
     timeout: 180)


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