[pygobject] tests: move dbus session bus handling into runtests.py
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] tests: move dbus session bus handling into runtests.py
- Date: Thu, 8 Feb 2018 16:28:36 +0000 (UTC)
commit 1e28b03b1562c030a956ed82337eaacfa38c304e
Author: Christoph Reiter <reiter christoph gmail com>
Date: Thu Feb 8 17:10:21 2018 +0100
tests: move dbus session bus handling into runtests.py
This allows us to remove code duplication in autotools/distutils.
This also fixes the noisy dbus output during tests because dbus-run-session
forwarded dbus logging output to stderr.
.gitlab-ci/Dockerfile | 1 -
.gitlab-ci/run-docker.sh | 0
setup.py | 14 ++------------
tests/Makefile.am | 10 +++-------
tests/runtests.py | 27 +++++++++++++++++++++++++--
5 files changed, 30 insertions(+), 22 deletions(-)
---
diff --git a/.gitlab-ci/Dockerfile b/.gitlab-ci/Dockerfile
index 8f83e3b5..4ce8927e 100644
--- a/.gitlab-ci/Dockerfile
+++ b/.gitlab-ci/Dockerfile
@@ -5,7 +5,6 @@ RUN apt-get update && apt-get install -y \
build-essential \
curl \
dbus \
- dbus-x11 \
gir1.2-gtk-3.0 \
git \
gobject-introspection \
diff --git a/.gitlab-ci/run-docker.sh b/.gitlab-ci/run-docker.sh
old mode 100644
new mode 100755
diff --git a/setup.py b/setup.py
index b1563868..c76bc9f2 100755
--- a/setup.py
+++ b/setup.py
@@ -452,25 +452,15 @@ class test(Command):
env = os.environ.copy()
env.pop("MSYSTEM", None)
- pre_args = []
- try:
- subprocess.check_call(["dbus-run-session", "--", "true"])
- except (EnvironmentError, subprocess.CalledProcessError):
- # Spawning a bus failed, disable dbus instead of inheriting
- # the user one
- env["DBUS_SESSION_BUS_ADDRESS"] = ""
- else:
- pre_args = ["dbus-run-session", "--"]
-
tests_dir = os.path.join(get_script_dir(), "tests")
- subprocess.check_call(pre_args + [
+ subprocess.check_call([
sys.executable,
os.path.join(tests_dir, "runtests.py"),
], env=env)
if not env.get("TEST_NAMES"):
env["TEST_NAMES"] = "compat_test_pygtk"
- subprocess.check_call(pre_args + [
+ subprocess.check_call([
sys.executable,
os.path.join(tests_dir, "runtests.py"),
], env=env)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index abb151d2..1e0af4d3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -164,15 +164,11 @@ RUN_TESTS_ENV_VARS= \
MSYSTEM= \
TESTS_BUILDDIR=$(builddir)
-# if dbus-run-session is available, use it, otherwise disable DBUS
-check-local:
- DBUS_ENV=$$(dbus-run-session true && echo "dbus-run-session --" || echo "DBUS_SESSION_BUS_ADDRESS=.")
$(MAKE) check.real
-
# pygtkcompat tests need to be run in a separate process as they
# clobber global name space
-check.real: $(target_libraries) $(test_typelibs) gschemas.compiled
- $(RUN_TESTS_ENV_VARS) $(EXTRA_ENV) $(DBUS_ENV) $(EXEC_NAME) $(PYTHON) -Wd $(srcdir)/runtests.py;
rc=$$?; \
- [ "$$rc" -ne 0 ] || [ -n "$$TEST_NAMES" ] || { TEST_NAMES=compat_test_pygtk $(RUN_TESTS_ENV_VARS)
$(EXTRA_ENV) $(DBUS_ENV) $(EXEC_NAME) $(PYTHON) -Wd -Werror::PendingDeprecationWarning
-Werror::DeprecationWarning -Werror::RuntimeWarning $(srcdir)/runtests.py; rc=$$?; }; \
+check-local: $(target_libraries) $(test_typelibs) gschemas.compiled
+ $(RUN_TESTS_ENV_VARS) $(EXTRA_ENV) $(EXEC_NAME) $(PYTHON) -Wd $(srcdir)/runtests.py; rc=$$?; \
+ [ "$$rc" -ne 0 ] || [ -n "$$TEST_NAMES" ] || { TEST_NAMES=compat_test_pygtk $(RUN_TESTS_ENV_VARS)
$(EXTRA_ENV) $(EXEC_NAME) $(PYTHON) -Wd -Werror::PendingDeprecationWarning -Werror::DeprecationWarning
-Werror::RuntimeWarning $(srcdir)/runtests.py; rc=$$?; }; \
exit $$rc
check.gdb:
diff --git a/tests/runtests.py b/tests/runtests.py
index 79297d0f..0cab43de 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -4,8 +4,10 @@
import os
import glob
import sys
-
+import signal
import unittest
+import subprocess
+import atexit
# this was renamed in Python 3, provide backwards compatible name
if sys.version_info[:2] == (2, 7):
@@ -15,11 +17,32 @@ if sys.version_info[0] == 3:
unittest.TestCase.assertRegexpMatches = unittest.TestCase.assertRegex
unittest.TestCase.assertRaisesRegexp = unittest.TestCase.assertRaisesRegex
-
if '--help' in sys.argv:
print("Usage: ./runtests.py <testfiles>")
sys.exit(0)
+
+def dbus_launch_session():
+ try:
+ out = subprocess.check_output([
+ "dbus-daemon", "--session", "--fork", "--print-address=1",
+ "--print-pid=1"])
+ except (subprocess.CalledProcessError, OSError):
+ return (-1, "")
+ else:
+ if sys.version_info[0] == 3:
+ out = out.decode("utf-8")
+ addr, pid = out.splitlines()
+ return int(pid), addr
+
+
+pid, addr = dbus_launch_session()
+if pid >= 0:
+ os.environ["DBUS_SESSION_BUS_ADDRESS"] = addr
+ atexit.register(os.kill, pid, signal.SIGKILL)
+else:
+ os.environ["DBUS_SESSION_BUS_ADDRESS"] = ""
+
mydir = os.path.dirname(os.path.abspath(__file__))
tests_builddir = os.path.abspath(os.environ.get('TESTS_BUILDDIR', os.path.dirname(__file__)))
builddir = os.path.dirname(tests_builddir)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]