diff options
Diffstat (limited to 'tests/functional-tests/common/utils')
-rw-r--r-- | tests/functional-tests/common/utils/configuration.py | 13 | ||||
-rw-r--r-- | tests/functional-tests/common/utils/helpers.py | 20 | ||||
-rw-r--r-- | tests/functional-tests/common/utils/storetest.py | 24 | ||||
-rw-r--r-- | tests/functional-tests/common/utils/system.py | 152 |
4 files changed, 33 insertions, 176 deletions
diff --git a/tests/functional-tests/common/utils/configuration.py b/tests/functional-tests/common/utils/configuration.py index 182bdcee2..c8a125bae 100644 --- a/tests/functional-tests/common/utils/configuration.py +++ b/tests/functional-tests/common/utils/configuration.py @@ -65,7 +65,9 @@ def expandvars (variable): result = variable for var, value in [("${datarootdir}", RAW_DATAROOT_DIR), ("${exec_prefix}", RAW_EXEC_PREFIX), - ("${prefix}", PREFIX)]: + ("${prefix}", PREFIX), + ("@top_srcdir@", TOP_SRCDIR), + ("@top_builddir@", TOP_BUILDDIR)]: result = result.replace (var, value) return result @@ -75,6 +77,9 @@ PREFIX = config['PREFIX'] RAW_EXEC_PREFIX = config['RAW_EXEC_PREFIX'] RAW_DATAROOT_DIR = config['RAW_DATAROOT_DIR'] +TOP_SRCDIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))) +TOP_BUILDDIR = os.environ['TRACKER_FUNCTIONAL_TEST_BUILD_DIR'] + TEST_ONTOLOGIES_DIR = os.path.normpath(expandvars(config['TEST_ONTOLOGIES_DIR'])) TRACKER_STORE_PATH = os.path.normpath(expandvars(config['TRACKER_STORE_PATH'])) @@ -94,10 +99,8 @@ if TEST_TMP_DIR.startswith('/tmp'): "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') + if TOP_BUILDDIR: + return os.path.join(TOP_BUILDDIR, 'tests', 'functional-tests', 'ttl') else: return 'ttl' diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py index b4c02b331..a900b8b0a 100644 --- a/tests/functional-tests/common/utils/helpers.py +++ b/tests/functional-tests/common/utils/helpers.py @@ -77,7 +77,7 @@ class Helper: sys.exit(1) sys.excepthook = new_hook - def _start_process (self): + def _start_process (self, env=None): path = self.PROCESS_PATH flags = getattr (self, "FLAGS", @@ -87,7 +87,10 @@ class Helper: if not options.is_verbose (): FNULL = open ('/dev/null', 'w') - kws = { 'stdout': FNULL, 'stderr': subprocess.PIPE } + kws.update({ 'stdout': FNULL, 'stderr': subprocess.PIPE }) + + if env: + kws['env'] = env command = [path] + flags log ("Starting %s" % ' '.join(command)) @@ -120,7 +123,10 @@ class Helper: return True # continue else: self.process_watch_timeout = 0 - error = self.process.stderr.read() + if options.is_verbose(): + error = "" + else: + error = self.process.stderr.read() raise RuntimeError("%s exited with status: %i\n%s" % (self.PROCESS_NAME, status, error)) def _timeout_on_idle_cb (self): @@ -129,7 +135,7 @@ class Helper: self.timeout_id = None return False - def start (self): + def start (self, env=None): """ Start an instance of process and wait for it to appear on the bus. """ @@ -150,7 +156,7 @@ class Helper: raise Exception ("Unable to start test instance of %s: " "already running " % self.PROCESS_NAME) - self.process = self._start_process () + self.process = self._start_process (env=env) log ('[%s] Started process %i' % (self.PROCESS_NAME, self.process.pid)) self.process_watch_timeout = GLib.timeout_add (200, self._process_watch_cb) @@ -219,8 +225,8 @@ class StoreHelper (Helper): graph_updated_handler_id = 0 - def start (self): - Helper.start (self) + def start (self, env=None): + Helper.start (self, env=env) self.resources = Gio.DBusProxy.new_sync( self.bus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None, diff --git a/tests/functional-tests/common/utils/storetest.py b/tests/functional-tests/common/utils/storetest.py index be16b6caa..3a5da0372 100644 --- a/tests/functional-tests/common/utils/storetest.py +++ b/tests/functional-tests/common/utils/storetest.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # # Copyright (C) 2010, Nokia <ivan.frade@nokia.com> +# Copyright (C) 2018, 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 @@ -17,29 +18,28 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. # -import time -#sys.path.insert (0, "../..") +import unittest2 as ut + +import os +import time -from common.utils.system import TrackerSystemAbstraction from common.utils.helpers import StoreHelper from common.utils import configuration as cfg -import unittest2 as ut -#import unittest as ut class CommonTrackerStoreTest (ut.TestCase): """ Common superclass for tests that just require a fresh store running """ @classmethod - def setUpClass (self): - #print "Starting the daemon in test mode" - self.system = TrackerSystemAbstraction () - self.system.tracker_store_testing_start () - self.tracker = self.system.store + def setUpClass (self): + env = os.environ + env['LC_COLLATE'] = 'en_GB.utf8' + + self.tracker = StoreHelper() + self.tracker.start(env=env) @classmethod def tearDownClass (self): - #print "Stopping the daemon in test mode (Doing nothing now)" - self.system.tracker_store_testing_stop () + self.tracker.stop() diff --git a/tests/functional-tests/common/utils/system.py b/tests/functional-tests/common/utils/system.py index 3d15a3795..013e4b7ec 100644 --- a/tests/functional-tests/common/utils/system.py +++ b/tests/functional-tests/common/utils/system.py @@ -1,153 +1 @@ #!/usr/bin/python -import os -import subprocess -import shutil -import configuration as cfg - -from gi.repository import GObject -from gi.repository import GLib -import time - -import options -from dconf import DConfClient - -import helpers - -# Add this after fixing the backup/restore and ontology changes tests -#"G_DEBUG" : "fatal_criticals", - -TEST_ENV_DIRS = { "XDG_DATA_HOME" : os.path.join (cfg.TEST_TMP_DIR, "data"), - "XDG_CACHE_HOME": os.path.join (cfg.TEST_TMP_DIR, "cache")} - -TEST_ENV_VARS = { "LC_COLLATE": "en_GB.utf8" } - -EXTRA_DIRS = [os.path.join (cfg.TEST_TMP_DIR, "data", "tracker"), - os.path.join (cfg.TEST_TMP_DIR, "cache", "tracker")] - -REASONABLE_TIMEOUT = 5 - -class UnableToBootException (Exception): - pass - - -class TrackerSystemAbstraction (object): - def __init__(self, settings=None, ontodir=None): - self.set_up_environment (settings=settings, ontodir=ontodir) - self.store = None - - def set_up_environment (self, settings=None, ontodir=None): - """ - Sets up the XDG_*_HOME variables and make sure the directories exist - - Settings should be a dict mapping schema names to dicts that hold the - settings that should be changed in those schemas. The contents dicts - should map key->value, where key is a key name and value is a suitable - GLib.Variant instance. - """ - - helpers.log ("[Conf] Setting test environment...") - - for var, directory in TEST_ENV_DIRS.iteritems (): - helpers.log ("export %s=%s" %(var, directory)) - self.__recreate_directory (directory) - os.environ [var] = directory - - 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 - - # Previous loop should have set DCONF_PROFILE to the test location - if settings is not None: - self._apply_settings(settings) - - helpers.log ("[Conf] environment ready") - - def _apply_settings(self, settings): - for schema_name, contents in settings.iteritems(): - dconf = DConfClient(schema_name) - dconf.reset() - for key, value in contents.iteritems(): - dconf.write(key, value) - - def tracker_store_testing_start (self, confdir=None, ontodir=None): - """ - Stops any previous instance of the store, calls set_up_environment, - and starts a new instances of the store - """ - self.set_up_environment (confdir, ontodir) - - self.store = helpers.StoreHelper () - self.store.start () - - 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 GLib.Error: - 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") - os.unlink (db_location) - - lockfile = os.path.join (TEST_ENV_DIRS ['XDG_DATA_HOME'], "tracker", "data", ".ismeta.running") - f = open (lockfile, 'w') - f.write (" ") - f.close () - - def tracker_store_corrupt_dbs (self): - for filename in ["meta.db", "meta.db-wal"]: - db_path = os.path.join (TEST_ENV_DIRS ['XDG_CACHE_HOME'], "tracker", filename) - f = open (db_path, "w") - for i in range (0, 100): - f.write ("Some stupid content... hohohoho, not a sqlite file anymore!\n") - f.close () - - def tracker_store_remove_journal (self): - db_location = os.path.join (TEST_ENV_DIRS ['XDG_DATA_HOME'], "tracker", "data") - shutil.rmtree (db_location) - os.mkdir (db_location) - - def tracker_store_remove_dbs (self): - db_location = os.path.join (TEST_ENV_DIRS ['XDG_CACHE_HOME'], "tracker") - 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_all_testing_start (self, confdir=None): - # This will start all miner-fs, store and writeback - self.tracker_writeback_testing_start (confdir) - - def tracker_all_testing_stop (self): - # This will stop all miner-fs, store and writeback - self.tracker_writeback_testing_stop () - - def __recreate_directory (self, directory): - if (os.path.exists (directory)): - shutil.rmtree (directory) - os.makedirs (directory) |