[tracker/functional-test-improvements: 3/5] functional-tests: Run all tests with a fake $HOME sandbox
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/functional-test-improvements: 3/5] functional-tests: Run all tests with a fake $HOME sandbox
- Date: Thu, 25 Aug 2011 10:52:15 +0000 (UTC)
commit 87827c18ac9a80e6c212a3336db843182f5ba816
Author: Sam Thursfield <samthursfield codethink co uk>
Date: Thu Aug 4 18:02:06 2011 +0100
functional-tests: Run all tests with a fake $HOME sandbox
Prefer storing test data in /tmp to avoid leaving cruft around the
home directory.
For tests that rely on filesystem monitoring, we must use the real
home directory anyway because FS miner currently ignores paths under
/tmp.
If /tmp is too small/unsuitable for test data, the preferred method
for using a different location is to set TMPDIR.
tests/functional-tests/300-miner-basic-ops.py | 40 ++++++++++----------
tests/functional-tests/310-fts-indexing.py | 2 +-
.../common/utils/applicationstest.py | 2 +-
.../common/utils/configuration.py.in | 13 +++++-
tests/functional-tests/common/utils/minertest.py | 12 +++---
tests/functional-tests/common/utils/system.py | 2 -
.../functional-tests/common/utils/writebacktest.py | 14 +++---
tests/functional-tests/test-runner.sh | 12 ++++++
8 files changed, 58 insertions(+), 39 deletions(-)
---
diff --git a/tests/functional-tests/300-miner-basic-ops.py b/tests/functional-tests/300-miner-basic-ops.py
index c28df97..7c3286a 100755
--- a/tests/functional-tests/300-miner-basic-ops.py
+++ b/tests/functional-tests/300-miner-basic-ops.py
@@ -30,7 +30,7 @@ import shutil
import time
import unittest2 as ut
-from common.utils.minertest import CommonTrackerMinerTest, BASEDIR, uri, path
+from common.utils.minertest import CommonTrackerMinerTest, MINER_TMP_DIR, uri, path
class MinerCrawlTest (CommonTrackerMinerTest):
"""
@@ -105,8 +105,8 @@ class MinerCrawlTest (CommonTrackerMinerTest):
Copy an file from unmonitored directory to monitored directory
and verify if data base is updated accordingly
"""
- source = os.path.join (BASEDIR, "test-no-monitored", "file0.txt")
- dest = os.path.join (BASEDIR, "test-monitored", "file0.txt")
+ source = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file0.txt")
+ dest = os.path.join (MINER_TMP_DIR, "test-monitored", "file0.txt")
shutil.copyfile (source, dest)
self.system.tracker_miner_fs_wait_for_idle ()
@@ -131,8 +131,8 @@ class MinerCrawlTest (CommonTrackerMinerTest):
"""
# Copy from monitored to unmonitored
- source = os.path.join (BASEDIR, "test-monitored", "file1.txt")
- dest = os.path.join (BASEDIR, "test-no-monitored", "file1.txt")
+ source = os.path.join (MINER_TMP_DIR, "test-monitored", "file1.txt")
+ dest = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file1.txt")
shutil.copyfile (source, dest)
time.sleep (1)
@@ -151,8 +151,8 @@ class MinerCrawlTest (CommonTrackerMinerTest):
"""
Copy a file between monitored directories
"""
- source = os.path.join (BASEDIR, "test-monitored", "file1.txt")
- dest = os.path.join (BASEDIR, "test-monitored", "dir1", "dir2", "file-test04.txt")
+ source = os.path.join (MINER_TMP_DIR, "test-monitored", "file1.txt")
+ dest = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "dir2", "file-test04.txt")
shutil.copyfile (source, dest)
self.system.tracker_miner_fs_wait_for_idle ()
@@ -174,8 +174,8 @@ class MinerCrawlTest (CommonTrackerMinerTest):
"""
Move a file from unmonitored to monitored directory
"""
- source = os.path.join (BASEDIR, "test-no-monitored", "file0.txt")
- dest = os.path.join (BASEDIR, "test-monitored", "dir1", "file-test05.txt")
+ source = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file0.txt")
+ dest = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "file-test05.txt")
shutil.move (source, dest)
self.system.tracker_miner_fs_wait_for_idle ()
@@ -200,8 +200,8 @@ class MinerCrawlTest (CommonTrackerMinerTest):
"""
Move a file from monitored to unmonitored directory
"""
- source = os.path.join (BASEDIR, "test-monitored", "dir1", "file2.txt")
- dest = os.path.join (BASEDIR, "test-no-monitored", "file2.txt")
+ source = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "file2.txt")
+ dest = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file2.txt")
shutil.move (source, dest)
self.system.tracker_miner_fs_wait_for_idle ()
@@ -221,10 +221,10 @@ class MinerCrawlTest (CommonTrackerMinerTest):
"""
Move a file between monitored directories
"""
- source = os.path.join (BASEDIR, "test-monitored", "dir1", "file2.txt")
- dest = os.path.join (BASEDIR, "test-monitored", "file2.txt")
+ source = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "file2.txt")
+ dest = os.path.join (MINER_TMP_DIR, "test-monitored", "file2.txt")
- source_dir_urn = self.__get_file_urn (os.path.join (BASEDIR, "test-monitored", "dir1"))
+ source_dir_urn = self.__get_file_urn (os.path.join (MINER_TMP_DIR, "test-monitored", "dir1"))
parent_before = self.__get_parent_urn (source)
self.assertEquals (source_dir_urn, parent_before)
@@ -233,7 +233,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
# Checking fix for NB#214413: After a move operation, nfo:belongsToContainer
# should be changed to the new one
- dest_dir_urn = self.__get_file_urn (os.path.join (BASEDIR, "test-monitored"))
+ dest_dir_urn = self.__get_file_urn (os.path.join (MINER_TMP_DIR, "test-monitored"))
parent_after = self.__get_parent_urn (dest)
self.assertNotEquals (parent_before, parent_after)
self.assertEquals (dest_dir_urn, parent_after)
@@ -259,7 +259,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
"""
Delete one of the files
"""
- victim = os.path.join (BASEDIR, "test-monitored", "dir1", "file2.txt")
+ victim = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "file2.txt")
os.remove (victim)
self.system.tracker_miner_fs_wait_for_idle ()
@@ -279,7 +279,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
"""
Delete a directory
"""
- victim = os.path.join (BASEDIR, "test-monitored", "dir1")
+ victim = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1")
shutil.rmtree (victim)
self.system.tracker_miner_fs_wait_for_idle ()
@@ -290,13 +290,13 @@ class MinerCrawlTest (CommonTrackerMinerTest):
# Restore the dirs
# Wait after each operation to be sure of the results
- os.makedirs (os.path.join (BASEDIR, "test-monitored", "dir1"))
+ os.makedirs (os.path.join (MINER_TMP_DIR, "test-monitored", "dir1"))
self.system.tracker_miner_fs_wait_for_idle ()
- os.makedirs (os.path.join (BASEDIR, "test-monitored", "dir1", "dir2"))
+ os.makedirs (os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "dir2"))
self.system.tracker_miner_fs_wait_for_idle ()
for f in ["test-monitored/dir1/file2.txt",
"test-monitored/dir1/dir2/file3.txt"]:
- filename = os.path.join (BASEDIR, f)
+ filename = os.path.join (MINER_TMP_DIR, f)
writer = open (filename, "w")
writer.write ("Don't panic, everything is fine")
writer.close ()
diff --git a/tests/functional-tests/310-fts-indexing.py b/tests/functional-tests/310-fts-indexing.py
index 334ab88..ee3e87d 100755
--- a/tests/functional-tests/310-fts-indexing.py
+++ b/tests/functional-tests/310-fts-indexing.py
@@ -31,7 +31,7 @@ import shutil
import locale
import unittest2 as ut
-from common.utils.minertest import CommonTrackerMinerTest, BASEDIR, uri, path, DEFAULT_TEXT
+from common.utils.minertest import CommonTrackerMinerTest, MINER_TMP_DIR, uri, path, DEFAULT_TEXT
from common.utils import configuration as cfg
class CommonMinerFTS (CommonTrackerMinerTest):
diff --git a/tests/functional-tests/common/utils/applicationstest.py b/tests/functional-tests/common/utils/applicationstest.py
index 421b46d..b4f7520 100644
--- a/tests/functional-tests/common/utils/applicationstest.py
+++ b/tests/functional-tests/common/utils/applicationstest.py
@@ -25,7 +25,7 @@ import shutil
import os
import time
-APPLICATIONS_TMP_DIR = os.path.join (cfg.TEST_TMP_DIR, "test-applications-monitored")
+APPLICATIONS_TMP_DIR = os.path.join (cfg.TEST_MONITORED_TMP_DIR, "test-applications-monitored")
CONF_OPTIONS = [
(cfg.DCONF_MINER_SCHEMA, "index-recursive-directories", [APPLICATIONS_TMP_DIR]),
diff --git a/tests/functional-tests/common/utils/configuration.py.in b/tests/functional-tests/common/utils/configuration.py.in
index da5c40b..0ea699d 100644
--- a/tests/functional-tests/common/utils/configuration.py.in
+++ b/tests/functional-tests/common/utils/configuration.py.in
@@ -82,5 +82,14 @@ haveMaemo = ("@HAVE_MAEMO_TRUE@" == "")
haveUpstart = ("@HAVE_UPSTART_TRUE@" == "")
disableJournal = ("@DISABLE_JOURNAL_TRUE@" == "")
-TEST_TMP_DIR = os.path.join (os.environ["HOME"], ".tracker-tests")
-
+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.")
diff --git a/tests/functional-tests/common/utils/minertest.py b/tests/functional-tests/common/utils/minertest.py
index 5b8f9a2..8651b05 100644
--- a/tests/functional-tests/common/utils/minertest.py
+++ b/tests/functional-tests/common/utils/minertest.py
@@ -25,19 +25,19 @@ import unittest2 as ut
import shutil
import os
-BASEDIR = os.environ['HOME']
+MINER_TMP_DIR = cfg.TEST_MONITORED_TMP_DIR
def path (filename):
- return os.path.join (BASEDIR, filename)
+ return os.path.join (MINER_TMP_DIR, filename)
def uri (filename):
- return "file://" + os.path.join (BASEDIR, filename)
+ return "file://" + os.path.join (MINER_TMP_DIR, filename)
DEFAULT_TEXT = "Some stupid content, to have a test file"
CONF_OPTIONS = [
- (cfg.DCONF_MINER_SCHEMA, "index-recursive-directories", [os.path.join (BASEDIR, "test-monitored")]),
+ (cfg.DCONF_MINER_SCHEMA, "index-recursive-directories", [os.path.join (MINER_TMP_DIR, "test-monitored")]),
(cfg.DCONF_MINER_SCHEMA, "index-single-directories", "[]"),
(cfg.DCONF_MINER_SCHEMA, "index-optical-discs", "false"),
(cfg.DCONF_MINER_SCHEMA, "index-removable-devices", "false"),
@@ -66,7 +66,7 @@ class CommonTrackerMinerTest (ut.TestCase):
"test-monitored/dir1",
"test-monitored/dir1/dir2",
"test-no-monitored"]:
- directory = os.path.join (BASEDIR, d)
+ directory = os.path.join (MINER_TMP_DIR, d)
if (os.path.exists (directory)):
shutil.rmtree (directory)
os.makedirs (directory)
@@ -75,7 +75,7 @@ class CommonTrackerMinerTest (ut.TestCase):
"test-monitored/dir1/file2.txt",
"test-monitored/dir1/dir2/file3.txt",
"test-no-monitored/file0.txt"]:
- testfile = os.path.join (BASEDIR, tf)
+ testfile = os.path.join (MINER_TMP_DIR, tf)
if (os.path.exists (testfile)):
os.remove (testfile)
f = open (testfile, 'w')
diff --git a/tests/functional-tests/common/utils/system.py b/tests/functional-tests/common/utils/system.py
index 6960c0f..4ab3e65 100644
--- a/tests/functional-tests/common/utils/system.py
+++ b/tests/functional-tests/common/utils/system.py
@@ -15,8 +15,6 @@ from dconf import DConfClient
import helpers
-# Don't use /tmp (not enough space there)
-
# Add this after fixing the backup/restore and ontology changes tests
#"G_DEBUG" : "fatal_criticals",
diff --git a/tests/functional-tests/common/utils/writebacktest.py b/tests/functional-tests/common/utils/writebacktest.py
index 7a0200d..c11d7b4 100644
--- a/tests/functional-tests/common/utils/writebacktest.py
+++ b/tests/functional-tests/common/utils/writebacktest.py
@@ -24,21 +24,21 @@ import os
from common.utils import configuration as cfg
import time
-BASEDIR = os.path.join (os.environ['HOME'], "test-writeback-monitored")
-
TEST_FILE_JPEG = "writeback-test-1.jpeg"
TEST_FILE_TIFF = "writeback-test-2.tif"
TEST_FILE_PNG = "writeback-test-4.png"
+WRITEBACK_TMP_DIR = os.path.join (cfg.TEST_MONITORED_TMP_DIR, "writeback")
+
CONF_OPTIONS = [
- (cfg.DCONF_MINER_SCHEMA, "index-recursive-directories", [BASEDIR]),
+ (cfg.DCONF_MINER_SCHEMA, "index-recursive-directories", [WRITEBACK_TMP_DIR]),
(cfg.DCONF_MINER_SCHEMA, "index-single-directories", "[]"),
(cfg.DCONF_MINER_SCHEMA, "index-optical-discs", "false"),
(cfg.DCONF_MINER_SCHEMA, "index-removable-devices", "false")
]
def uri (filename):
- return "file://" + os.path.join (BASEDIR, filename)
+ return "file://" + os.path.join (WRITEBACK_TMP_DIR, filename)
class CommonTrackerWritebackTest (ut.TestCase):
"""
@@ -53,7 +53,7 @@ class CommonTrackerWritebackTest (ut.TestCase):
#
for d in ["test-writeback-monitored"]:
- directory = os.path.join (BASEDIR, d)
+ directory = os.path.join (WRITEBACK_TMP_DIR, d)
if (os.path.exists (directory)):
shutil.rmtree (directory)
os.makedirs (directory)
@@ -68,8 +68,8 @@ class CommonTrackerWritebackTest (ut.TestCase):
for testfile in [TEST_FILE_JPEG, TEST_FILE_PNG,TEST_FILE_TIFF]:
origin = os.path.join (datadir, testfile)
- print "Copying", origin, BASEDIR
- shutil.copy (origin, BASEDIR)
+ print "Copying", origin, WRITEBACK_TMP_DIR
+ shutil.copy (origin, WRITEBACK_TMP_DIR)
time.sleep (2)
diff --git a/tests/functional-tests/test-runner.sh b/tests/functional-tests/test-runner.sh
index c6d7846..8b6be7e 100755
--- a/tests/functional-tests/test-runner.sh
+++ b/tests/functional-tests/test-runner.sh
@@ -4,6 +4,16 @@
DBUS_SESSION_BUS_PID=
+export TEMP_DIR=`mktemp --tmpdir -d tracker-test-XXXX`
+
+# We need to use the actual home directory for some tests because
+# Tracker will explicitly ignore files in /tmp ...
+export REAL_HOME=`echo ~`
+
+# ... but /tmp is preferred for test data, to avoid leaving debris
+# in the filesystem
+HOME=$TEMP_DIR
+
if test -h /targets/links/scratchbox.config ; then
export SBOX_REDIRECT_IGNORE=/usr/bin/python ;
@@ -18,3 +28,5 @@ else
kill $DBUS_SESSION_BUS_PID
fi ;
+
+rm -R $TEMP_DIR
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]