summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam@afuera.me.uk>2014-12-27 17:01:37 +0000
committerSam Thursfield <sam@afuera.me.uk>2014-12-29 17:55:55 +0000
commit1b7ee32a55feeb4e444f23d7a30d08ab5738582a (patch)
treea772fefea0a36e9d85220769a589181d20d772ca
parentd7af2d000142f8a9373184a5f510d25c0843233b (diff)
downloadtracker-1b7ee32a55feeb4e444f23d7a30d08ab5738582a.tar.gz
WIP: trying to get rid of test-runner.sh for 60* tests
The second test fails to setup because it never receives the NameOwnerChanged signal on the session bus ... I have a feeling this is because dbus-glib is looking on the wrong bus, I imagine it's not designed to switch the bus in use at runtime. Using dbus.bus.BusConnection instead of dbus.SessionBus in common/utils/helpers.py is probably the way forwards!
-rw-r--r--tests/functional-tests/apps/__init__.py3
-rwxr-xr-xtests/functional-tests/apps/test_camera.py (renamed from tests/functional-tests/apps/600-applications-camera.py)0
-rwxr-xr-xtests/functional-tests/apps/test_sync.py (renamed from tests/functional-tests/apps/601-applications-sync.py)0
-rw-r--r--tests/functional-tests/common/utils/applicationstest.py59
-rw-r--r--tests/functional-tests/common/utils/helpers.py14
5 files changed, 66 insertions, 10 deletions
diff --git a/tests/functional-tests/apps/__init__.py b/tests/functional-tests/apps/__init__.py
deleted file mode 100644
index 61b258f1e..000000000
--- a/tests/functional-tests/apps/__init__.py
+++ /dev/null
@@ -1,3 +0,0 @@
-"""
-This module contains functional tests for Tracker.
-"""
diff --git a/tests/functional-tests/apps/600-applications-camera.py b/tests/functional-tests/apps/test_camera.py
index 333e982f5..333e982f5 100755
--- a/tests/functional-tests/apps/600-applications-camera.py
+++ b/tests/functional-tests/apps/test_camera.py
diff --git a/tests/functional-tests/apps/601-applications-sync.py b/tests/functional-tests/apps/test_sync.py
index 92b2127ad..92b2127ad 100755
--- a/tests/functional-tests/apps/601-applications-sync.py
+++ b/tests/functional-tests/apps/test_sync.py
diff --git a/tests/functional-tests/common/utils/applicationstest.py b/tests/functional-tests/common/utils/applicationstest.py
index 5f304fb71..708ee3629 100644
--- a/tests/functional-tests/common/utils/applicationstest.py
+++ b/tests/functional-tests/common/utils/applicationstest.py
@@ -45,8 +45,52 @@ CONF_OPTIONS = {
SLOWCOPY_RATE = 1024
-class CommonTrackerApplicationTest (ut.TestCase):
+import subprocess
+import tempfile
+class TrackerTestCase(ut.TestCase):
+ '''Base class for all Tracker functional tests.
+
+ This class handles isolating each test case from both other test cases and
+ from the host system.
+
+ '''
+ def setUp(self):
+ self._old_environ = os.environ
+
+ self.fake_home()
+ self.launch_session_bus()
+
+ def fake_home(self):
+ self.tempdir = tempfile.mkdtemp(prefix='tracker-test')
+
+ # We need to use the actual home directory for some tests because
+ # Tracker will explicitly ignore files in /tmp ...
+ os.environ['REAL_HOME'] = os.path.expanduser('~')
+
+ # ... but /tmp is preferred for test data, to avoid leaving debris
+ # in the filesystem
+ os.environ['HOME'] = self.tempdir
+ log("HOME=%s" % self.tempdir)
+
+ def launch_session_bus(self):
+ self.dbus_process = subprocess.Popen(
+ ["dbus-daemon", "--session", "--print-address=1", "--fork"],
+ stdout=subprocess.PIPE)
+ self.dbus_address = self.dbus_process.stdout.readline().rstrip()
+
+ os.environ['DBUS_SESSION_BUS_ADDRESS'] = self.dbus_address
+ log("DBUS_SESSION_BUS_ADDRESS=%s" % self.dbus_address)
+
+ def tearDown(self):
+ log('Stopping D-Bus daemon (PID %i) ...' % (self.dbus_process.pid))
+ self.dbus_process.terminate()
+ self.dbus_process.wait()
+
+ os.environ = self._old_environ
+
+
+class CommonTrackerApplicationTest(TrackerTestCase):
def get_urn_count_by_url(self, url):
select = """
SELECT ?u WHERE { ?u nie:url \"%s\" }
@@ -92,8 +136,9 @@ class CommonTrackerApplicationTest (ut.TestCase):
self.slowcopy_file_fd(src, fdest, rate)
fdest.close()
- @classmethod
def setUp(self):
+ super(CommonTrackerApplicationTest, self).setUp()
+
# Create temp directory to monitor
if (os.path.exists(APPLICATIONS_TMP_DIR)):
shutil.rmtree(APPLICATIONS_TMP_DIR)
@@ -117,11 +162,11 @@ class CommonTrackerApplicationTest (ut.TestCase):
log("Ready to go!")
- @classmethod
def tearDown(self):
- # print "Stopping the daemon in test mode (Doing nothing now)"
- self.system.tracker_all_testing_stop()
+ self.system.tracker_all_testing_stop ()
# Remove monitored directory
- if (os.path.exists(APPLICATIONS_TMP_DIR)):
- shutil.rmtree(APPLICATIONS_TMP_DIR)
+ if (os.path.exists (APPLICATIONS_TMP_DIR)):
+ shutil.rmtree (APPLICATIONS_TMP_DIR)
+
+ super(CommonTrackerApplicationTest, self).tearDown()
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index cf0d3ee16..a4e1c1018 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -67,6 +67,8 @@ class Helper:
self.bus = None
self.bus_admin = None
+ self.available = False
+
def install_glib_excepthook(self, loop):
"""
Handler to abort test if an exception occurs inside the GLib main loop.
@@ -81,6 +83,7 @@ class Helper:
def _get_bus(self):
if self.bus is not None:
+ log ("--- return existing bus %s" % self.bus)
return
self.loop = GObject.MainLoop()
@@ -171,11 +174,20 @@ class Helper:
self.process_watch_timeout = GLib.timeout_add(
200, self._process_watch_cb)
+ GLib.timeout_add_seconds(REASONABLE_TIMEOUT, self.loop.quit)
+
self.abort_if_process_exits_with_status_0 = True
# Run the loop until the bus name appears, or the process dies.
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))
+
self.abort_if_process_exits_with_status_0 = False
def stop(self):
@@ -197,6 +209,8 @@ class Helper:
self.process.wait()
log("[%s] stopped." % self.PROCESS_NAME)
+ self.loop.run()
+
# Disconnect the signals of the next start we get duplicated messages
self.bus._clean_up_signal_match(self.name_owner_match)