[tracker/sam/functional-test-runner: 10/15] WIP: where has the pep8 gone



commit fe7c2a56fe0325ad1c99eb43eebbb677254a3573
Author: Sam Thursfield <sam afuera me uk>
Date:   Tue Dec 30 00:47:54 2014 +0000

    WIP: where has the pep8 gone

 tests/functional-tests/common/__init__.py          |    4 +-
 tests/functional-tests/common/helpers.py           |   36 +-
 tests/functional-tests/common/sandbox.py           |    2 +-
 tests/functional-tests/common/utils/system.py      |   66 ---
 tests/functional-tests/store/__init__.py           |   39 ++-
 .../functional-tests/store/test_backup_restore.py  |  416 ++++++++++----------
 tests/functional-tests/store/test_coalesce.py      |    4 +-
 tests/functional-tests/store/test_collation.py     |    4 +-
 .../store/test_concurrent_query.py                 |    4 +-
 tests/functional-tests/store/test_distance.py      |    4 +-
 tests/functional-tests/store/test_fts_functions.py |    4 +-
 tests/functional-tests/store/test_graph.py         |    4 +-
 tests/functional-tests/store/test_group_concat.py  |    4 +-
 tests/functional-tests/store/test_insertion.py     |   10 +-
 .../store/test_ontology_changes.py                 |   51 +--
 tests/functional-tests/store/test_signals.py       |    4 +-
 tests/functional-tests/store/test_sparql_bugs.py   |    4 +-
 .../store/test_sqlite_batch_misused.py             |    4 +-
 .../functional-tests/store/test_sqlite_misused.py  |    6 +-
 tests/functional-tests/store/test_statistics.py    |    4 +-
 .../functional-tests/store/test_threaded_store.py  |    4 +-
 tests/functional-tests/store/test_transactions.py  |   53 ++--
 .../store/test_unique_insertions.py                |    4 +-
 tests/functional-tests/store/testcase.py           |    8 +-
 24 files changed, 353 insertions(+), 390 deletions(-)
---
diff --git a/tests/functional-tests/common/__init__.py b/tests/functional-tests/common/__init__.py
index 2ad2bab..fa00d72 100644
--- a/tests/functional-tests/common/__init__.py
+++ b/tests/functional-tests/common/__init__.py
@@ -15,4 +15,6 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301, USA.
 
-import testcase
+
+import helpers
+import sandbox
diff --git a/tests/functional-tests/common/helpers.py b/tests/functional-tests/common/helpers.py
index ce204c4..5df4e2e 100644
--- a/tests/functional-tests/common/helpers.py
+++ b/tests/functional-tests/common/helpers.py
@@ -27,8 +27,8 @@ import time
 from dbus.mainloop.glib import DBusGMainLoop
 import re
 
-import configuration as cfg
-import options
+import utils.configuration as cfg
+from utils import options
 
 
 class NoMetadataException (Exception):
@@ -94,7 +94,7 @@ class Helper:
         self.bus_admin = dbus.Interface(
             obj, dbus_interface="org.freedesktop.DBus")
 
-    def _start_process(self):
+    def _start_process(self, extra_env=None):
         path = getattr(self,
                        "PROCESS_PATH",
                        os.path.join(cfg.EXEC_PREFIX, self.PROCESS_NAME))
@@ -113,6 +113,11 @@ class Helper:
 
             command = [path] + flags
             log("Starting %s" % ' '.join(command))
+
+            if extra_env:
+                kws['env'] = os.environ.copy()
+                kws['env'].update(extra_env)
+
             return subprocess.Popen([path] + flags, **kws)
 
     def _name_owner_changed_cb(self, name, old_owner, new_owner):
@@ -147,25 +152,24 @@ class Helper:
         self.timeout_id = None
         return False
 
-    def start(self, dbus_address):
+    def start(self, sandbox, extra_env=None):
         """
         Start an instance of process and wait for it to appear on the bus.
         """
 
         if self.bus is None:
-            self._get_bus(dbus_address)
+            self._get_bus(sandbox.dbus_address)
 
         if (self.bus_admin.NameHasOwner(self.BUS_NAME)):
             raise Exception(
                 "Unable to start test instance of %s: already running" % self.PROCESS_NAME)
 
         self.name_owner_match = self.bus.add_signal_receiver(
-            self._name_owner_changed_cb,
-                                                              signal_name="NameOwnerChanged",
-                                                              path="/org/freedesktop/DBus",
-                                                              dbus_interface="org.freedesktop.DBus")
+            self._name_owner_changed_cb, signal_name="NameOwnerChanged",
+                                         path="/org/freedesktop/DBus",
+                                         dbus_interface="org.freedesktop.DBus")
 
-        self.process = self._start_process()
+        self.process = self._start_process(extra_env)
         log('[%s] Started process %i' % (self.PROCESS_NAME, self.process.pid))
 
         self.process_watch_timeout = GLib.timeout_add(
@@ -179,8 +183,6 @@ class Helper:
         self.loop.run()
 
         if not self.available:
-            import pdb
-            pdb.set_trace()
             raise Exception(
                 "%s did not appear on message bus after %i seconds." % (
                     self.BUS_NAME, REASONABLE_TIMEOUT))
@@ -235,8 +237,14 @@ class StoreHelper (Helper):
 
     graph_updated_handler_id = 0
 
-    def start(self, dbus_address):
-        Helper.start(self, dbus_address)
+    def start(self, dbus_address, ontology_dir=None):
+        extra_env = {}
+
+        if ontology_dir:
+            info("TRACKER_DB_ONTOLOGIES_DIR=%s" % ontology_dir)
+            extra_env['TRACKER_DB_ONTOLOGIES_DIR'] = ontology_dir
+
+        Helper.start(self, dbus_address, extra_env)
 
         tracker = self.bus.get_object(cfg.TRACKER_BUSNAME,
                                       cfg.TRACKER_OBJ_PATH)
diff --git a/tests/functional-tests/common/sandbox.py b/tests/functional-tests/common/sandbox.py
index d3b9f2f..a84de97 100644
--- a/tests/functional-tests/common/sandbox.py
+++ b/tests/functional-tests/common/sandbox.py
@@ -61,7 +61,7 @@ class TrackerSandbox(object):
         dbus_process = subprocess.Popen(
             ["dbus-daemon", "--session", "--print-address=1", "--fork"],
             stdout=subprocess.PIPE)
-        dbus_address = self.dbus_process.stdout.readline().rstrip()
+        dbus_address = dbus_process.stdout.readline().rstrip()
 
         os.environ['DBUS_SESSION_BUS_ADDRESS'] = dbus_address
         info("DBUS_SESSION_BUS_ADDRESS=%s" % dbus_address)
diff --git a/tests/functional-tests/common/utils/system.py b/tests/functional-tests/common/utils/system.py
index bcbe499..f829837 100644
--- a/tests/functional-tests/common/utils/system.py
+++ b/tests/functional-tests/common/utils/system.py
@@ -58,11 +58,6 @@ class TrackerSystemAbstraction:
         for directory in EXTRA_DIRS:
             self.__recreate_directory(directory)
 
-        if ontodir:
-            helpers.log("export %s=%s" %
-                        ("TRACKER_DB_ONTOLOGIES_DIR", ontodir))
-            os.environ["TRACKER_DB_ONTOLOGIES_DIR"] = ontodir
-
         for var, value in TEST_ENV_VARS.iteritems():
             helpers.log("export %s=%s" % (var, value))
             os.environ[var] = value
@@ -80,37 +75,9 @@ class TrackerSystemAbstraction:
             for key, value in contents.iteritems():
                 dconf.write(key, value)
 
-    def tracker_store_testing_start(self, config=None, ontodir=None, dbus_address=None):
-        """
-        Stops any previous instance of the store, calls set_up_environment,
-        and starts a new instances of the store
-        """
-        self.set_up_environment(config, ontodir)
-
-        self.store = helpers.StoreHelper()
-        self.store.start(dbus_address)
-
-    def tracker_store_start(self):
-        self.store.start()
-
-    def tracker_store_stop_nicely(self):
-        self.store.stop()
-
     def tracker_store_stop_brutally(self):
         self.store.kill()
 
-    def tracker_store_restart_with_new_ontologies(self, ontodir):
-        self.store.stop()
-        if ontodir:
-            helpers.log("[Conf] Setting %s - %s" %
-                        ("TRACKER_DB_ONTOLOGIES_DIR", ontodir))
-            os.environ["TRACKER_DB_ONTOLOGIES_DIR"] = ontodir
-        try:
-            self.store.start()
-        except dbus.DBusException, e:
-            raise UnableToBootException(
-                "Unable to boot the store \n(" + str(e) + ")")
-
     def tracker_store_prepare_journal_replay(self):
         db_location = os.path.join(
             TEST_ENV_DIRS['XDG_CACHE_HOME'], "tracker", "meta.db")
@@ -144,13 +111,6 @@ class TrackerSystemAbstraction:
         shutil.rmtree(db_location)
         os.mkdir(db_location)
 
-    def tracker_store_testing_stop(self):
-        """
-        Stops a running tracker-store
-        """
-        assert self.store
-        self.store.stop()
-
     def tracker_miner_fs_testing_start(self, config, dbus_address):
         """
         Stops any previous instance of the store and miner, calls set_up_environment,
@@ -199,29 +159,3 @@ class TrackerSystemAbstraction:
         if (os.path.exists(directory)):
             shutil.rmtree(directory)
         os.makedirs(directory)
-
-
-if __name__ == "__main__":
-    import gtk
-    import glib
-    import time
-
-    def destroy_the_world(a):
-        a.tracker_store_testing_stop()
-        print "   stopped"
-        Gtk.main_quit()
-
-    print "-- Starting store --"
-    a = TrackerSystemAbstraction()
-    a.tracker_store_testing_start()
-    print "   started, waiting 5 sec. to stop it"
-    GLib.timeout_add_seconds(5, destroy_the_world, a)
-    Gtk.main()
-
-    print "-- Starting miner-fs --"
-    b = TrackerMinerFsLifeCycle()
-    b.start()
-    print "  started, waiting 3 secs. to stop it"
-    time.sleep(3)
-    b.stop()
-    print "  stopped"
diff --git a/tests/functional-tests/store/__init__.py b/tests/functional-tests/store/__init__.py
index 61b258f..a1766da 100644
--- a/tests/functional-tests/store/__init__.py
+++ b/tests/functional-tests/store/__init__.py
@@ -1,3 +1,36 @@
-"""
-This module contains functional tests for Tracker.
-"""
+# Copyright (C) 2014, 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.
+
+
+import test_backup_restore
+import test_coalesce
+import test_collation
+import test_concurrent_query
+import test_distance
+import test_fts_functions
+import test_graph
+import test_group_concat
+import test_insertion
+import test_ontology_changes
+import test_signals
+import test_sparql_bugs
+import test_sqlite_batch_misused
+import test_sqlite_misused
+import test_statistics
+import test_threaded_store
+import test_transactions
+import test_unique_insertions
diff --git a/tests/functional-tests/store/test_backup_restore.py 
b/tests/functional-tests/store/test_backup_restore.py
index 63cecdf..6a040f3 100644
--- a/tests/functional-tests/store/test_backup_restore.py
+++ b/tests/functional-tests/store/test_backup_restore.py
@@ -25,7 +25,7 @@ from common.utils.helpers import StoreHelper
 from common.utils import configuration as cfg
 from common.utils.expectedFailure import expectedFailureBug, expectedFailureJournal
 
-import storetest
+import testcase
 
 
 """
@@ -33,7 +33,7 @@ Call backup, restore, force the journal replay and check the data is correct aft
 """
 
 
-class BackupRestoreTest (storetest.TrackerStoreTest):
+class BackupRestoreTest (testcase.TrackerStoreTest):
 
     '''Backup and restore to/from valid/invalid files'''
 
@@ -45,214 +45,214 @@ class BackupRestoreTest (storetest.TrackerStoreTest):
         if (os.path.exists(self.BACKUP_FILE)):
             os.unlink(self.BACKUP_FILE)
 
-        def __insert_test_instance(self):
-            self.tracker.update("INSERT { <%s> a nco:Contact; nco:fullname 'test-backup' } "
-                                % (self.TEST_INSTANCE))
+    def __insert_test_instance(self):
+        self.tracker.update("INSERT { <%s> a nco:Contact; nco:fullname 'test-backup' } "
+                            % (self.TEST_INSTANCE))
+
+    def __delete_test_instance(self):
+        self.tracker.update(
+            "DELETE { <%s> a rdfs:Resource } " % (self.TEST_INSTANCE))
+
+    def __is_test_instance_there(self):
+        result = self.tracker.query(
+            "SELECT ?u WHERE { ?u a nco:Contact; nco:fullname 'test-backup'}")
+        if (len(result) == 1 and len(result[0]) == 1 and result[0][0] == self.TEST_INSTANCE):
+            return True
+        return False
+
+    def test_backup_01(self):
+        """
+        Inserted data is restored after backup
+
+        1.Insert contact
+        2.Take backup.
+        3.Delete contact. (check it is not there)
+        4.Restore the file.
+        5.Check the contact is back there
+        """
+
+        self.__insert_test_instance()
+        instances_before = self.tracker.count_instances("nco:Contact")
+
+        self.tracker.backup(self.BACKUP_FILE)
+
+        self.__delete_test_instance()
+        instances_now = self.tracker.count_instances("nco:Contact")
+
+        self.assertEquals(instances_before - 1, instances_now)
+
+        self.tracker.restore(self.BACKUP_FILE)
+
+        instances_after = self.tracker.count_instances("nco:Contact")
+
+        self.assertEquals(instances_before, instances_after)
+        self.assertTrue(self.__is_test_instance_there())
+
+        # Clean the DB for the next test
+        self.__delete_test_instance()
+
+    def test_backup_02(self):
+        """
+        Data inserted after backup is lost in restore
+
+        1.Take backup of db.
+        2.Insert a contact.
+        3.Restore the db.
+        4.Search for the contact inserted.
+        """
+
+        # Precondition: test backup contact shouldn't be there
+        self.assertFalse(self.__is_test_instance_there())
+
+        self.tracker.backup(self.BACKUP_FILE)
+
+        self.__insert_test_instance()
+        self.assertTrue(self.__is_test_instance_there())
+
+        self.tracker.restore(self.BACKUP_FILE)
+
+        self.assertFalse(self.__is_test_instance_there())
+
+    def test_backup_03(self):
+        """
+        Restore from a random text file
+        """
+        TEST_FILE = os.path.join(cfg.TEST_TMP_DIR, "trash_file")
+        trashfile = open(TEST_FILE, "w")
+        trashfile.write(
+            "Here some useless text that obviously is NOT a backup")
+        trashfile.close()
+
+        self.assertRaises(dbus.DBusException,
+                            self.tracker.restore,
+                            "file://" + TEST_FILE)
+        os.unlink(TEST_FILE)
+
+    def test_backup_04(self):
+        """
+        Restore from a random binary file
+        """
+        TEST_FILE = os.path.join(cfg.TEST_TMP_DIR, "trash_file.dat")
+
+        import struct
+        trashfile = open(TEST_FILE, "wb")
+        for n in range(0, 50):
+            data = struct.pack('i', n)
+            trashfile.write(data)
+        trashfile.close()
+
+        instances_before = self.tracker.count_instances(
+            "nie:InformationElement")
+        self.assertRaises(dbus.DBusException,
+                            self.tracker.restore,
+                            "file://" + TEST_FILE)
+
+        os.unlink(TEST_FILE)
+
+    def test_backup_05(self):
+        """
+        Take backup of db to a invalid path.
+        Expected: Backup should not be taken and tracker should behave normally.
+        """
+        self.assertRaises(dbus.DBusException,
+                            self.tracker.backup,
+                            "file://%s/this/is/a/non-existant/folder/backup" % (cfg.TEST_TMP_DIR))
+
+    def test_backup_06(self):
+        """
+        Try to restore an invalid path
+        """
+        self.assertRaises(dbus.DBusException,
+                            self.tracker.restore,
+                            "file://%s/this/is/a/non-existant/folder/backup" % (cfg.TEST_TMP_DIR))
+
+    def test_backup_07(self):
+        """
+        Restore after removing the DBs and journal
+
+        1.Insert a contact.
+        2.Take backup of db.
+        4.Delete the database
+        5.Restore the db.
+        6.Search for the contact inserted.
+        """
+        self.__insert_test_instance()
+        instances_before = self.tracker.count_instances("nco:Contact")
+        self.tracker.backup(self.BACKUP_FILE)
+
+        self.system.tracker_store_stop_nicely()
+        self.system.tracker_store_remove_dbs()
+        self.system.tracker_store_remove_journal()
+        self.system.tracker_store_start()
+
+        instances_before_restore = self.tracker.count_instances(
+            "nco:Contact")
+        self.assertNotEqual(instances_before_restore, instances_before)
+
+        self.tracker.restore(self.BACKUP_FILE)
+        self.assertTrue(self.__is_test_instance_there())
+
+        self.__delete_test_instance()
+
+    def test_backup_08(self):
+        """
+        Restore after corrupting DB
+
+        1.Insert a contact.
+        2.Take backup of db.
+        5.Restore the db.
+        6.Search for the contact inserted.
+        """
+        self.__insert_test_instance()
+        instances_before = self.tracker.count_instances("nco:Contact")
+        self.tracker.backup(self.BACKUP_FILE)
+
+        self.system.tracker_store_stop_brutally()
+        self.system.tracker_store_corrupt_dbs()
+        self.system.tracker_store_remove_journal()
+        self.system.tracker_store_start()
+
+        instances_before_restore = self.tracker.count_instances(
+            "nco:Contact")
+        self.assertNotEqual(instances_before_restore, instances_before)
+
+        self.tracker.restore(self.BACKUP_FILE)
+        self.assertTrue(self.__is_test_instance_there())
+
+        # DB to the original state
+        self.__delete_test_instance()
+
+    def test_backup_11(self):
+        """
+        Backup ignores the file extension
+
+        1.Insert a contact.
+        2.Take backup of db in .jpg format.
+        3.Restore the db.
+        4.Search for the contact inserted.
+        """
+        BACKUP_JPG_EXT = "file://%s/tracker-test-backup.jpg" % (
+            cfg.TEST_TMP_DIR)
+
+        self.__insert_test_instance()
+
+        instances_before = self.tracker.count_instances("nco:Contact")
+
+        self.tracker.backup(BACKUP_JPG_EXT)
+
+        self.__delete_test_instance()
+        instances_now = self.tracker.count_instances("nco:Contact")
+        self.assertEquals(instances_before, instances_now + 1)
+
+        self.tracker.restore(BACKUP_JPG_EXT)
+        instances_after = self.tracker.count_instances("nco:Contact")
+        self.assertEquals(instances_before, instances_after)
+
+        # Restore the DB to the original state
+        self.__delete_test_instance()
 
-        def __delete_test_instance(self):
-            self.tracker.update(
-                "DELETE { <%s> a rdfs:Resource } " % (self.TEST_INSTANCE))
 
-        def __is_test_instance_there(self):
-            result = self.tracker.query(
-                "SELECT ?u WHERE { ?u a nco:Contact; nco:fullname 'test-backup'}")
-            if (len(result) == 1 and len(result[0]) == 1 and result[0][0] == self.TEST_INSTANCE):
-                return True
-            return False
-
-        def test_backup_01(self):
-            """
-            Inserted data is restored after backup
-
-            1.Insert contact
-            2.Take backup.
-            3.Delete contact. (check it is not there)
-            4.Restore the file.
-            5.Check the contact is back there
-            """
-
-            self.__insert_test_instance()
-            instances_before = self.tracker.count_instances("nco:Contact")
-
-            self.tracker.backup(self.BACKUP_FILE)
-
-            self.__delete_test_instance()
-            instances_now = self.tracker.count_instances("nco:Contact")
-
-            self.assertEquals(instances_before - 1, instances_now)
-
-            self.tracker.restore(self.BACKUP_FILE)
-
-            instances_after = self.tracker.count_instances("nco:Contact")
-
-            self.assertEquals(instances_before, instances_after)
-            self.assertTrue(self.__is_test_instance_there())
-
-            # Clean the DB for the next test
-            self.__delete_test_instance()
-
-        def test_backup_02(self):
-            """
-            Data inserted after backup is lost in restore
-
-            1.Take backup of db.
-            2.Insert a contact.
-            3.Restore the db.
-            4.Search for the contact inserted.
-            """
-
-            # Precondition: test backup contact shouldn't be there
-            self.assertFalse(self.__is_test_instance_there())
-
-            self.tracker.backup(self.BACKUP_FILE)
-
-            self.__insert_test_instance()
-            self.assertTrue(self.__is_test_instance_there())
-
-            self.tracker.restore(self.BACKUP_FILE)
-
-            self.assertFalse(self.__is_test_instance_there())
-
-        def test_backup_03(self):
-            """
-            Restore from a random text file
-            """
-            TEST_FILE = os.path.join(cfg.TEST_TMP_DIR, "trash_file")
-            trashfile = open(TEST_FILE, "w")
-            trashfile.write(
-                "Here some useless text that obviously is NOT a backup")
-            trashfile.close()
-
-            self.assertRaises(dbus.DBusException,
-                              self.tracker.restore,
-                              "file://" + TEST_FILE)
-            os.unlink(TEST_FILE)
-
-        def test_backup_04(self):
-            """
-            Restore from a random binary file
-            """
-            TEST_FILE = os.path.join(cfg.TEST_TMP_DIR, "trash_file.dat")
-
-            import struct
-            trashfile = open(TEST_FILE, "wb")
-            for n in range(0, 50):
-                data = struct.pack('i', n)
-                trashfile.write(data)
-            trashfile.close()
-
-            instances_before = self.tracker.count_instances(
-                "nie:InformationElement")
-            self.assertRaises(dbus.DBusException,
-                              self.tracker.restore,
-                              "file://" + TEST_FILE)
-
-            os.unlink(TEST_FILE)
-
-        def test_backup_05(self):
-            """
-            Take backup of db to a invalid path.
-            Expected: Backup should not be taken and tracker should behave normally.
-            """
-            self.assertRaises(dbus.DBusException,
-                              self.tracker.backup,
-                              "file://%s/this/is/a/non-existant/folder/backup" % (cfg.TEST_TMP_DIR))
-
-        def test_backup_06(self):
-            """
-            Try to restore an invalid path
-            """
-            self.assertRaises(dbus.DBusException,
-                              self.tracker.restore,
-                              "file://%s/this/is/a/non-existant/folder/backup" % (cfg.TEST_TMP_DIR))
-
-        def test_backup_07(self):
-            """
-            Restore after removing the DBs and journal
-
-            1.Insert a contact.
-            2.Take backup of db.
-            4.Delete the database
-            5.Restore the db.
-            6.Search for the contact inserted.
-            """
-            self.__insert_test_instance()
-            instances_before = self.tracker.count_instances("nco:Contact")
-            self.tracker.backup(self.BACKUP_FILE)
-
-            self.system.tracker_store_stop_nicely()
-            self.system.tracker_store_remove_dbs()
-            self.system.tracker_store_remove_journal()
-            self.system.tracker_store_start()
-
-            instances_before_restore = self.tracker.count_instances(
-                "nco:Contact")
-            self.assertNotEqual(instances_before_restore, instances_before)
-
-            self.tracker.restore(self.BACKUP_FILE)
-            self.assertTrue(self.__is_test_instance_there())
-
-            self.__delete_test_instance()
-
-        def test_backup_08(self):
-            """
-            Restore after corrupting DB
-
-            1.Insert a contact.
-            2.Take backup of db.
-            5.Restore the db.
-            6.Search for the contact inserted.
-            """
-            self.__insert_test_instance()
-            instances_before = self.tracker.count_instances("nco:Contact")
-            self.tracker.backup(self.BACKUP_FILE)
-
-            self.system.tracker_store_stop_brutally()
-            self.system.tracker_store_corrupt_dbs()
-            self.system.tracker_store_remove_journal()
-            self.system.tracker_store_start()
-
-            instances_before_restore = self.tracker.count_instances(
-                "nco:Contact")
-            self.assertNotEqual(instances_before_restore, instances_before)
-
-            self.tracker.restore(self.BACKUP_FILE)
-            self.assertTrue(self.__is_test_instance_there())
-
-            # DB to the original state
-            self.__delete_test_instance()
-
-        def test_backup_11(self):
-            """
-            Backup ignores the file extension
-
-            1.Insert a contact.
-            2.Take backup of db in .jpg format.
-            3.Restore the db.
-            4.Search for the contact inserted.
-            """
-            BACKUP_JPG_EXT = "file://%s/tracker-test-backup.jpg" % (
-                cfg.TEST_TMP_DIR)
-
-            self.__insert_test_instance()
-
-            instances_before = self.tracker.count_instances("nco:Contact")
-
-            self.tracker.backup(BACKUP_JPG_EXT)
-
-            self.__delete_test_instance()
-            instances_now = self.tracker.count_instances("nco:Contact")
-            self.assertEquals(instances_before, instances_now + 1)
-
-            self.tracker.restore(BACKUP_JPG_EXT)
-            instances_after = self.tracker.count_instances("nco:Contact")
-            self.assertEquals(instances_before, instances_after)
-
-            # Restore the DB to the original state
-            self.__delete_test_instance()
-
-
-class JournalReplayTest (CommonTrackerStoreTest):
+class JournalReplayTest (testcase.TrackerStoreTest):
 
     """
     Force journal replaying and check that the DB is correct aftewards
diff --git a/tests/functional-tests/store/test_coalesce.py b/tests/functional-tests/store/test_coalesce.py
index b90f6ae..78f3596 100644
--- a/tests/functional-tests/store/test_coalesce.py
+++ b/tests/functional-tests/store/test_coalesce.py
@@ -27,10 +27,10 @@ import random
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 
 
-class TestCoalesce (CommonTrackerStoreTest):
+class TestCoalesce (testcase.TrackerStoreTest):
 
     """
     Insert and instance with some values, and tracker coalesce of some of them
diff --git a/tests/functional-tests/store/test_collation.py b/tests/functional-tests/store/test_collation.py
index ed8a46e..a4af211 100644
--- a/tests/functional-tests/store/test_collation.py
+++ b/tests/functional-tests/store/test_collation.py
@@ -28,10 +28,10 @@ import locale
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 
 
-class TrackerStoreCollationTests (CommonTrackerStoreTest):
+class TrackerStoreCollationTests (testcase.TrackerStoreTest):
 
     """
     Insert few instances with a text field containing collation-problematic words.
diff --git a/tests/functional-tests/store/test_concurrent_query.py 
b/tests/functional-tests/store/test_concurrent_query.py
index 2cfca60..1f3a379 100644
--- a/tests/functional-tests/store/test_concurrent_query.py
+++ b/tests/functional-tests/store/test_concurrent_query.py
@@ -33,13 +33,13 @@ from dbus.mainloop.glib import DBusGMainLoop
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 
 AMOUNT_OF_TEST_INSTANCES = 100
 AMOUNT_OF_QUERIES = 10
 
 
-class TestConcurrentQuery (CommonTrackerStoreTest):
+class TestConcurrentQuery (testcase.TrackerStoreTest):
 
     """
     Send a bunch of queries to the daemon asynchronously, to test the queue
diff --git a/tests/functional-tests/store/test_distance.py b/tests/functional-tests/store/test_distance.py
index 4a09ad4..047f3d4 100644
--- a/tests/functional-tests/store/test_distance.py
+++ b/tests/functional-tests/store/test_distance.py
@@ -26,14 +26,14 @@ import random
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 
 POINT_COORDS = [
     (0, 0), (1, 1), (2, 2), (3, 3), (4, 4)
 ]
 
 
-class TestDistanceFunctions (CommonTrackerStoreTest):
+class TestDistanceFunctions (testcase.TrackerStoreTest):
 
     """
     Insert some points and get the distance between them.
diff --git a/tests/functional-tests/store/test_fts_functions.py 
b/tests/functional-tests/store/test_fts_functions.py
index 4459538..dbfa957 100644
--- a/tests/functional-tests/store/test_fts_functions.py
+++ b/tests/functional-tests/store/test_fts_functions.py
@@ -28,10 +28,10 @@ import random
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 
 
-class TestFTSFunctions (CommonTrackerStoreTest):
+class TestFTSFunctions (testcase.TrackerStoreTest):
 
     """
     Insert data with text and check the fts:xxxx functions are returning the expected results
diff --git a/tests/functional-tests/store/test_graph.py b/tests/functional-tests/store/test_graph.py
index c43ca54..53558f2 100644
--- a/tests/functional-tests/store/test_graph.py
+++ b/tests/functional-tests/store/test_graph.py
@@ -26,10 +26,10 @@ import random
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 
 
-class TestGraphs (CommonTrackerStoreTest):
+class TestGraphs (testcase.TrackerStoreTest):
 
     """
     Insert triplets in different graphs and check the query results asking in
diff --git a/tests/functional-tests/store/test_group_concat.py 
b/tests/functional-tests/store/test_group_concat.py
index eadc7c6..7fb88da 100644
--- a/tests/functional-tests/store/test_group_concat.py
+++ b/tests/functional-tests/store/test_group_concat.py
@@ -26,10 +26,10 @@ import random
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 
 
-class TestGroupConcat (CommonTrackerStoreTest):
+class TestGroupConcat (testcase.TrackerStoreTest):
 
     """
     Insert a multivalued property and request the results in GROUP_CONCAT
diff --git a/tests/functional-tests/store/test_insertion.py b/tests/functional-tests/store/test_insertion.py
index 8eb58a6..18ecd6b 100644
--- a/tests/functional-tests/store/test_insertion.py
+++ b/tests/functional-tests/store/test_insertion.py
@@ -33,10 +33,10 @@ import datetime
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 
 
-class TrackerStoreInsertionTests (CommonTrackerStoreTest):
+class TrackerStoreInsertionTests (testcase.TrackerStoreTest):
 
     """
     Insert single and multiple-valued properties, dates (ok and broken)
@@ -633,7 +633,7 @@ class TrackerStoreInsertionTests (CommonTrackerStoreTest):
             """DELETE { <test://instance-ds3> a rdfs:Resource. }""")
 
 
-class TrackerStoreDeleteTests (CommonTrackerStoreTest):
+class TrackerStoreDeleteTests (testcase.TrackerStoreTest):
 
     """
     Use DELETE in Sparql and check the information is actually removed
@@ -720,7 +720,7 @@ class TrackerStoreDeleteTests (CommonTrackerStoreTest):
         self.assertEquals(after_removal, initial)
 
 
-class TrackerStoreBatchUpdateTest (CommonTrackerStoreTest):
+class TrackerStoreBatchUpdateTest (testcase.TrackerStoreTest):
 
     """
     Insert data using the BatchSparqlUpdate method in the store
@@ -791,7 +791,7 @@ class TrackerStoreBatchUpdateTest (CommonTrackerStoreTest):
         self.assertEquals(count_before_insert, count_final)
 
 
-class TrackerStorePhoneNumberTest (CommonTrackerStoreTest):
+class TrackerStorePhoneNumberTest (testcase.TrackerStoreTest):
 
     """
     Tests around phone numbers (maemo specific). Inserting correct/incorrect ones
diff --git a/tests/functional-tests/store/test_ontology_changes.py 
b/tests/functional-tests/store/test_ontology_changes.py
index a38cc2d..41de9e0 100644
--- a/tests/functional-tests/store/test_ontology_changes.py
+++ b/tests/functional-tests/store/test_ontology_changes.py
@@ -1,5 +1,3 @@
-#!/usr/bin/python
-#
 # Copyright (C) 2010, Nokia <ivan frade nokia com>
 #
 # This program is free software; you can redistribute it and/or
@@ -22,19 +20,19 @@
 Stand-alone tests cases for the store, booting it with different ontology
 changes and checking if the data is still there.
 """
-import time
 
-import os
 import dbus  # Just for the Exception
-from common.utils import configuration as cfg
-import unittest as ut
-from common.utils.system import TrackerSystemAbstraction as TrackerSystemAbstraction
-from common.utils.system import UnableToBootException as UnableToBootException
-from common.utils.helpers import StoreHelper as StoreHelper
-from common.utils.expectedFailure import expectedFailureBug, expectedFailureJournal
+
+import os
+import re
+import time
+import unittest
 
 import common
 
+from common.utils import configuration as cfg
+from common.utils.expectedFailure import expectedFailureJournal
+
 
 RDFS_RANGE = "http://www.w3.org/2000/01/rdf-schema#range";
 XSD_DATETIME = "http://www.w3.org/2001/XMLSchema#dateTime";
@@ -43,11 +41,8 @@ XSD_INTEGER = "http://www.w3.org/2001/XMLSchema#integer";
 
 TEST_PREFIX = "http://example.org/ns#";
 
-import re
-import time
-
 
-class OntologyChangeTestTemplate (common.testcase.TrackerTestCase):
+class OntologyChangeTestTemplate (unittest.TestCase):
 
     """
     Template class for the ontology changes tests. The tests are subclasses
@@ -72,17 +67,14 @@ class OntologyChangeTestTemplate (common.testcase.TrackerTestCase):
                                 "test-ontologies", param)
 
     def setUp(self):
-        super(OntologyChangeTestTemplate, self).setUp()
-
-        self.system = TrackerSystemAbstraction()
+        self.sandbox = common.sandbox.TrackerSandbox()
 
     def tearDown(self):
-        self.system.tracker_store_testing_stop()
+        self.store.stop()
 
-        super(OntologyChangeTestTemplate, self).tearDown()
+        self.sandbox.close()
 
     def template_test_ontology_change(self):
-
         self.set_ontology_dirs()
 
         basic_ontologies = self.get_ontology_dir(self.FIRST_ONTOLOGY_DIR)
@@ -90,17 +82,16 @@ class OntologyChangeTestTemplate (common.testcase.TrackerTestCase):
 
         self.__assert_ontology_dates(basic_ontologies, modified_ontologies)
 
-        self.system.tracker_store_testing_start(ontodir=basic_ontologies)
-        self.tracker = self.system.store
+        self.store = common.helpers.StoreHelper()
+        self.store.start(self.sandbox,
+                         ontology_dir=basic_ontologies)
+        self.tracker = self.store
 
         self.insert_data()
 
-        try:
-            # Boot the second set of ontologies
-            self.system.tracker_store_restart_with_new_ontologies(
-                modified_ontologies)
-        except UnableToBootException, e:
-            self.fail(str(self.__class__) + " " + str(e))
+        # Boot the second set of ontologies
+        self.store.stop()
+        self.store.start(self.sandbox, ontology_dir=modified_ontologies)
 
         self.validate_status()
 
@@ -929,7 +920,3 @@ class PropertyRelegationTest (OntologyChangeTestTemplate):
                                     % (self.instance_b))
         self.assertEquals(result[0][0], "content-b-test")
         self.assertEquals(result[0][1], "b-test-n")
-
-
-if __name__ == "__main__":
-    ut.main()
diff --git a/tests/functional-tests/store/test_signals.py b/tests/functional-tests/store/test_signals.py
index bf2f697..8157116 100644
--- a/tests/functional-tests/store/test_signals.py
+++ b/tests/functional-tests/store/test_signals.py
@@ -24,7 +24,7 @@ are tested)
 """
 
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 from common.utils import configuration as cfg
 
 from gi.repository import GObject
@@ -43,7 +43,7 @@ CONTACT_CLASS_URI = "http://www.semanticdesktop.org/ontologies/2007/03/22/nco#Pe
 REASONABLE_TIMEOUT = 10  # Time waiting for the signal to be emitted
 
 
-class TrackerStoreSignalsTests (CommonTrackerStoreTest):
+class TrackerStoreSignalsTests (testcase.TrackerStoreTest):
 
     """
     Insert/update/remove instances from nco:PersonContact
diff --git a/tests/functional-tests/store/test_sparql_bugs.py 
b/tests/functional-tests/store/test_sparql_bugs.py
index 655f945..4515feb 100644
--- a/tests/functional-tests/store/test_sparql_bugs.py
+++ b/tests/functional-tests/store/test_sparql_bugs.py
@@ -32,11 +32,11 @@ import datetime
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 from common.utils.expectedFailure import expectedFailureBug
 
 
-class TrackerStoreSparqlBugsTests (CommonTrackerStoreTest):
+class TrackerStoreSparqlBugsTests (testcase.TrackerStoreTest):
 
     def test_01_NB217566_union_exists_filter(self):
         """
diff --git a/tests/functional-tests/store/test_sqlite_batch_misused.py 
b/tests/functional-tests/store/test_sqlite_batch_misused.py
index 6f6cfd0..cb7cd49 100644
--- a/tests/functional-tests/store/test_sqlite_batch_misused.py
+++ b/tests/functional-tests/store/test_sqlite_batch_misused.py
@@ -28,13 +28,13 @@ from dbus.mainloop.glib import DBusGMainLoop
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 
 # Number of instances per batch
 BATCH_SIZE = 3000
 
 
-class TestSqliteBatchMisused (CommonTrackerStoreTest):
+class TestSqliteBatchMisused (testcase.TrackerStoreTest):
 
     """
     Send big batchSparqlUpdates and run queries at the same time
diff --git a/tests/functional-tests/store/test_sqlite_misused.py 
b/tests/functional-tests/store/test_sqlite_misused.py
index 58e7cc8..6087de4 100644
--- a/tests/functional-tests/store/test_sqlite_misused.py
+++ b/tests/functional-tests/store/test_sqlite_misused.py
@@ -28,17 +28,17 @@ from dbus.mainloop.glib import DBusGMainLoop
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 
 
-class TestSqliteMisused (CommonTrackerStoreTest):
+class TestSqliteMisused (testcase.TrackerStoreTest):
 
     """
     Send queries while importing files (in .ttl directory)
     """
 
     def setUp(self):
-        super(CommonTrackerStoreTest, self).setUp()
+        super(testcase.TrackerStoreTest, self).setUp()
 
         self.main_loop = GObject.MainLoop()
         self.files_counter = 0
diff --git a/tests/functional-tests/store/test_statistics.py b/tests/functional-tests/store/test_statistics.py
index 86c2ce0..1841daa 100644
--- a/tests/functional-tests/store/test_statistics.py
+++ b/tests/functional-tests/store/test_statistics.py
@@ -26,14 +26,14 @@ import time
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 
 RDFS_RESOURCE = "rdfs:Resource"
 NIE_IE = "nie:InformationElement"
 RDFS_CLASS = "rdfs:Class"
 
 
-class TrackerStoreStatisticsTests (CommonTrackerStoreTest):
+class TrackerStoreStatisticsTests (testcase.TrackerStoreTest):
 
     """
     Check initial statistics, add, remove, update content and check results stats
diff --git a/tests/functional-tests/store/test_threaded_store.py 
b/tests/functional-tests/store/test_threaded_store.py
index 5bc6829..b8a03e4 100644
--- a/tests/functional-tests/store/test_threaded_store.py
+++ b/tests/functional-tests/store/test_threaded_store.py
@@ -30,7 +30,7 @@ from dbus.mainloop.glib import DBusGMainLoop
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 
 MAX_TEST_TIME = 60  # seconds to finish the tests (to avoid infinite waitings)
 
@@ -41,7 +41,7 @@ COMPLEX_QUERY_TIMEOUT = 15000
 SIMPLE_QUERY_FREQ = 2
 
 
-class TestThreadedStore (CommonTrackerStoreTest):
+class TestThreadedStore (testcase.TrackerStoreTest):
 
     """
     When the database is big, running a complex query takes ages.
diff --git a/tests/functional-tests/store/test_transactions.py 
b/tests/functional-tests/store/test_transactions.py
index 1f3ef95..5f6a53c 100644
--- a/tests/functional-tests/store/test_transactions.py
+++ b/tests/functional-tests/store/test_transactions.py
@@ -20,18 +20,18 @@
 """
 Make sure that when COMMIT returns, the data is in the DB
 """
+
 import time
 
 from common.utils import configuration as cfg
 from common.utils.helpers import StoreHelper as StoreHelper
-import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
 
-TEST_INSTANCE_PATTERN = "test://12-transactions-%d"
+import testcase
 
 
-class TrackerTransactionsTest (CommonTrackerStoreTest):
+TEST_INSTANCE_PATTERN = "test://12-transactions-%d"
 
+class TrackerTransactionsTest(testcase.TrackerSToreTest):
     """
     In a loop:
        1. Inserts a Batch of instances
@@ -42,53 +42,50 @@ class TrackerTransactionsTest (CommonTrackerStoreTest):
     If the commit was real, all the inserted instances should be there.
     """
 
-    def setUp(self):
+    def setUp (self):
         super(TrackerTransactionsTest, self).setUp()
 
         self.instance_counter = 0
 
-    def tearDown(self):
+    def tearDown (self):
         print "Tear down (will take some time to remove all resources)"
         delete_sparql = "DELETE { ?u a rdfs:Resource } WHERE { ?u a nmo:Email} \n"
-        self.tracker.update(delete_sparql,
-                            timeout=60000)
+        self.tracker.update (delete_sparql,
+                             timeout=60000)
         self.instance_counter = 0
 
         super(TrackerTransactionsTest, self).tearDown()
 
-    def insert_and_commit(self, number):
+    def insert_and_commit (self, number):
         insert_sparql = "INSERT {\n"
-        for i in range(0, number):
-            insert_sparql += "  <" + \
-                TEST_INSTANCE_PATTERN % (self.instance_counter) + ">"
+        for i in range (0, number):
+            insert_sparql += "  <" + TEST_INSTANCE_PATTERN % (self.instance_counter) + ">"
             insert_sparql += " a nmo:Email.\n "
             self.instance_counter += 1
 
         insert_sparql += "}"
-        self.tracker.batch_update(insert_sparql)
-        # print "Waiting for commit (", number," instances)"
+        self.tracker.batch_update (insert_sparql)
+        #print "Waiting for commit (", number," instances)"
         #start = time.time ()
-        self.tracker.batch_commit()
+        self.tracker.batch_commit ()
         #end = time.time ()
-        # print "BatchCommit returned (after %d s.)" % (end - start)
+        #print "BatchCommit returned (after %d s.)" % (end - start)
 
-    def test_commit_and_abort(self):
 
-        for i in range(0, 20):
+    def test_commit_and_abort (self):
+
+        for i in range (0, 20):
             NUMBER_OF_INSTANCES = 1000
-            self.insert_and_commit(NUMBER_OF_INSTANCES)
+            self.insert_and_commit (NUMBER_OF_INSTANCES)
 
-            self.system.tracker_store_stop_brutally()
-            self.system.tracker_store_start()
+            self.system.tracker_store_stop_brutally ()
+            self.system.tracker_store_start ()
             try:
-                results = self.tracker.count_instances("nmo:Email")
+                results = self.tracker.count_instances ("nmo:Email")
             except:
                 print "Timeout, probably replaying journal or something (wait 20 sec.)"
-                time.sleep(20)
-                results = self.tracker.count_instances()
+                time.sleep (20)
+                results = self.tracker.count_instances ()
 
             # Every iteration we are adding new instances in the store!
-            self.assertEquals(results, NUMBER_OF_INSTANCES * (i + 1))
-
-if __name__ == "__main__":
-    ut.main()
+            self.assertEquals (results, NUMBER_OF_INSTANCES * (i+1))
diff --git a/tests/functional-tests/store/test_unique_insertions.py 
b/tests/functional-tests/store/test_unique_insertions.py
index 88929ce..d422379 100644
--- a/tests/functional-tests/store/test_unique_insertions.py
+++ b/tests/functional-tests/store/test_unique_insertions.py
@@ -26,10 +26,10 @@ import random
 
 from common.utils import configuration as cfg
 import unittest as ut
-from common.utils.storetest import CommonTrackerStoreTest as CommonTrackerStoreTest
+import testcase
 
 
-class TestMinerInsertBehaviour (CommonTrackerStoreTest):
+class TestMinerInsertBehaviour (testcase.TrackerStoreTest):
 
     """
     Mimic the behaviour of the miner, removing the previous information of the resource
diff --git a/tests/functional-tests/store/testcase.py b/tests/functional-tests/store/testcase.py
index f26960d..4403d7a 100644
--- a/tests/functional-tests/store/testcase.py
+++ b/tests/functional-tests/store/testcase.py
@@ -35,13 +35,15 @@ class TrackerStoreTest(unittest.TestCase):
 
     @classmethod
     def setUpClass(self):
-        sandbox = common.sandbox.TrackerSandbox()
+        self.sandbox = common.sandbox.TrackerSandbox()
 
         self.store = common.helpers.StoreHelper()
-        self.store.start(sandbox.dbus_address)
+        self.store.start(self.sandbox)
 
-        self.tracker = self.system.store
+        self.tracker = self.store
 
     @classmethod
     def tearDownClass(self):
         self.store.stop()
+
+        self.sandbox.close()



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