[tracker/sam/functional-test-runner: 7/15] WIP: trying to get rid of test-runner.sh for 60* tests
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/sam/functional-test-runner: 7/15] WIP: trying to get rid of test-runner.sh for 60* tests
- Date: Tue, 30 Dec 2014 21:21:14 +0000 (UTC)
commit 1b7ee32a55feeb4e444f23d7a30d08ab5738582a
Author: Sam Thursfield <sam afuera me uk>
Date: Sat Dec 27 17:01:37 2014 +0000
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!
tests/functional-tests/apps/__init__.py | 3 -
.../{600-applications-camera.py => test_camera.py} | 0
.../{601-applications-sync.py => test_sync.py} | 0
.../common/utils/applicationstest.py | 59 +++++++++++++++++--
tests/functional-tests/common/utils/helpers.py | 14 +++++
5 files changed, 66 insertions(+), 10 deletions(-)
---
diff --git a/tests/functional-tests/apps/600-applications-camera.py
b/tests/functional-tests/apps/test_camera.py
similarity index 100%
rename from tests/functional-tests/apps/600-applications-camera.py
rename to 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
similarity index 100%
rename from tests/functional-tests/apps/601-applications-sync.py
rename to 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 5f304fb..708ee36 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 cf0d3ee..a4e1c10 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)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]