Commit fd083be7 authored by Carlos Garnacho's avatar Carlos Garnacho

Merge branch 'sam/ft-dirs'

parents 1b482fae fe5979e9
Pipeline #50981 passed with stage
in 1 minute and 53 seconds
......@@ -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):
......
......@@ -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')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment