summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam@afuera.me.uk>2019-01-05 15:41:55 +0100
committerSam Thursfield <sam@afuera.me.uk>2019-01-05 15:49:12 +0100
commitfe5979e9f9ed37014f491b3e73231cb328219010 (patch)
tree263bb9d6799a8c4972361fb804ed6bab93b19bf1
parent34d4f524370cb5338b40cd830fccd8786350a331 (diff)
downloadtracker-fe5979e9f9ed37014f491b3e73231cb328219010.tar.gz
functional-tests: Rationalize handling of test directories
This corresponds with a fix from tracker-miners.git in https://gitlab.gnome.org/GNOME/tracker-miners/merge_requests/27.
-rwxr-xr-xtests/functional-tests/17-ontology-changes.py48
-rw-r--r--tests/functional-tests/common/utils/configuration.py13
2 files changed, 26 insertions, 35 deletions
diff --git a/tests/functional-tests/17-ontology-changes.py b/tests/functional-tests/17-ontology-changes.py
index fcfe0074b..6b76896da 100755
--- a/tests/functional-tests/17-ontology-changes.py
+++ b/tests/functional-tests/17-ontology-changes.py
@@ -28,6 +28,7 @@ from gi.repository import GLib
import os
import shutil
import re
+import tempfile
import time
from common.utils import configuration as cfg
@@ -45,14 +46,8 @@ XSD_INTEGER = "http://www.w3.org/2001/XMLSchema#integer"
TEST_PREFIX = "http://example.org/ns#"
-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
@@ -63,6 +58,13 @@ class UnableToBootException (Exception):
class TrackerSystemAbstraction (object):
def __init__(self, settings=None):
self.store = None
+ self._dirs = {}
+
+ def xdg_data_home(self):
+ return os.path.join(self._basedir, 'data')
+
+ def xdg_cache_home(self):
+ return os.path.join(self._basedir, 'cache')
def set_up_environment (self, settings=None, ontodir=None):
"""
@@ -73,14 +75,17 @@ class TrackerSystemAbstraction (object):
should map key->value, where key is a key name and value is a suitable
GLib.Variant instance.
"""
+ self._basedir = tempfile.mkdtemp()
- for var, directory in TEST_ENV_DIRS.iteritems ():
- helpers.log ("export %s=%s" %(var, directory))
- self.__recreate_directory (directory)
- os.environ [var] = directory
+ self._dirs = {
+ "XDG_DATA_HOME" : self.xdg_data_home(),
+ "XDG_CACHE_HOME": self.xdg_cache_home()
+ }
- for directory in EXTRA_DIRS:
- self.__recreate_directory (directory)
+ for var, directory in self._dirs.items():
+ os.makedirs (directory)
+ os.makedirs (os.path.join(directory, 'tracker'))
+ os.environ [var] = directory
if ontodir:
helpers.log ("export %s=%s" % ("TRACKER_DB_ONTOLOGIES_DIR", ontodir))
@@ -120,17 +125,17 @@ class TrackerSystemAbstraction (object):
except GLib.Error:
raise UnableToBootException ("Unable to boot the store \n(" + str(e) + ")")
- def tracker_store_testing_stop (self):
+ def finish (self):
"""
- Stops a running tracker-store
+ Stop all running processes and remove all test data.
"""
- assert self.store
- self.store.stop ()
- def __recreate_directory (self, directory):
- if (os.path.exists (directory)):
- shutil.rmtree (directory)
- os.makedirs (directory)
+ if self.store:
+ self.store.stop ()
+
+ for path in self._dirs.values():
+ shutil.rmtree(path)
+ os.rmdir(self._basedir)
class OntologyChangeTestTemplate (ut.TestCase):
@@ -154,8 +159,7 @@ class OntologyChangeTestTemplate (ut.TestCase):
self.system = TrackerSystemAbstraction ()
def tearDown (self):
- if self.system.store is not None:
- self.system.tracker_store_testing_stop ()
+ self.system.finish()
def template_test_ontology_change (self):
diff --git a/tests/functional-tests/common/utils/configuration.py b/tests/functional-tests/common/utils/configuration.py
index c8a125bae..5d965f6d2 100644
--- a/tests/functional-tests/common/utils/configuration.py
+++ b/tests/functional-tests/common/utils/configuration.py
@@ -86,19 +86,6 @@ TRACKER_STORE_PATH = os.path.normpath(expandvars(config['TRACKER_STORE_PATH']))
disableJournal = (len(config['disableJournal']) == 0)
-TEST_TMP_DIR = os.path.join (os.environ["HOME"], "tracker-tests")
-
-TEST_MONITORED_TMP_DIR = TEST_TMP_DIR
-
-if TEST_TMP_DIR.startswith('/tmp'):
- if os.environ.has_key('REAL_HOME'):
- TEST_MONITORED_TMP_DIR = os.path.join (os.environ["REAL_HOME"], "tracker-tests")
- else:
- 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.")
-
-
def generated_ttl_dir():
if TOP_BUILDDIR:
return os.path.join(TOP_BUILDDIR, 'tests', 'functional-tests', 'ttl')