diff options
author | Simon McVittie <smcv@debian.org> | 2016-08-11 08:34:01 +0100 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2016-08-11 09:24:22 +0100 |
commit | 56af7b702bfd9fa97c11111d4f832bb95263273f (patch) | |
tree | 1292dc98c8afb6d838d07b963394b3e47d6129a7 /test | |
parent | eff7c820285504d229ef8474c870302abfbe4bc1 (diff) | |
download | dbus-python-56af7b702bfd9fa97c11111d4f832bb95263273f.tar.gz |
Use TAP syntax for all directly-run tests
For now this means that skipped tests will be reported as passed.
This will be corrected in the next commit.
Signed-off-by: Simon McVittie <smcv@debian.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/import-repeatedly.c | 6 | ||||
-rwxr-xr-x | test/run-test.sh | 87 | ||||
-rwxr-xr-x | test/test-client.py | 14 | ||||
-rwxr-xr-x | test/test-exception-py2.py | 10 | ||||
-rwxr-xr-x | test/test-exception-py3.py | 10 | ||||
-rwxr-xr-x | test/test-p2p.py | 13 | ||||
-rwxr-xr-x | test/test-signals.py | 13 | ||||
-rwxr-xr-x | test/test-standalone.py | 10 | ||||
-rwxr-xr-x | test/test-unusable-main-loop.py | 25 |
9 files changed, 130 insertions, 58 deletions
diff --git a/test/import-repeatedly.c b/test/import-repeatedly.c index 4d177ed..a8b8834 100644 --- a/test/import-repeatedly.c +++ b/test/import-repeatedly.c @@ -1,16 +1,22 @@ /* Regression test for https://bugs.freedesktop.org/show_bug.cgi?id=23831 */ +#include <stdio.h> + #include <Python.h> int main(void) { int i; + puts("1..1"); + for (i = 0; i < 100; ++i) { Py_Initialize(); PyRun_SimpleString("import dbus\n"); Py_Finalize(); } + puts("ok 1 - was able to import dbus 100 times"); + return 0; } diff --git a/test/run-test.sh b/test/run-test.sh index ae370a4..da49918 100755 --- a/test/run-test.sh +++ b/test/run-test.sh @@ -26,26 +26,41 @@ set -e failed= -skipped= +test_num=0 -echo "DBUS_TOP_SRCDIR=$DBUS_TOP_SRCDIR" -echo "DBUS_TOP_BUILDDIR=$DBUS_TOP_BUILDDIR" -echo "PYTHONPATH=$PYTHONPATH" -echo "PYTHON=${PYTHON:=python}" +echo "# DBUS_TOP_SRCDIR=$DBUS_TOP_SRCDIR" +echo "# DBUS_TOP_BUILDDIR=$DBUS_TOP_BUILDDIR" +echo "# PYTHONPATH=$PYTHONPATH" +echo "# PYTHON=${PYTHON:=python}" if ! [ -d "$DBUS_TEST_TMPDIR" ]; then DBUS_TEST_TMPDIR="$(mktemp -d)" if ! [ -d "$DBUS_TEST_TMPDIR" ]; then - echo "failed to create temporary directory (install mktemp?)" >&2 + echo "Bail out! Failed to create temporary directory (install mktemp?)" exit 1 fi fi if ! "$PYTHON" -c 'from gi.repository import GLib'; then - echo "could not import python-gi" - exit 77 + echo "1..0 # SKIP could not import python-gi" + exit 0 fi +ok () { + test_num=$(( $test_num + 1 )) + echo "ok $test_num - $*" +} + +not_ok () { + test_num=$(( $test_num + 1 )) + echo "not ok $test_num - $*" +} + +skip () { + test_num=$(( $test_num + 1 )) + echo "ok $test_num # SKIP - $*" +} + dbus-monitor > "$DBUS_TEST_TMPDIR"/monitor.log & #echo "running the examples" @@ -61,73 +76,67 @@ dbus-monitor > "$DBUS_TEST_TMPDIR"/monitor.log & #$PYTHON "$DBUS_TOP_SRCDIR"/examples/example-signal-recipient.py --exit-service || # die "example-signal-recipient failed!" -echo "running cross-test (for better diagnostics use mjj29's dbus-test)" +echo "# running cross-test (for better diagnostics use mjj29's dbus-test)" $PYTHON "$DBUS_TOP_SRCDIR"/test/cross-test-server.py > "$DBUS_TEST_TMPDIR"/cross-server.log & cross_test_server_pid="$!" -$PYTHON "$DBUS_TOP_SRCDIR"/test/wait-for-name.py org.freedesktop.DBus.Binding.TestServer +$PYTHON "$DBUS_TOP_SRCDIR"/test/wait-for-name.py org.freedesktop.DBus.Binding.TestServer >&2 e=0 $PYTHON "$DBUS_TOP_SRCDIR"/test/cross-test-client.py > "$DBUS_TEST_TMPDIR"/cross-client.log || e=$? -echo "test-client exit status: $e" +echo "# test-client exit status: $e" if test "$e" = 77; then - echo "cross-test-client exited $e, marking as skipped" - skipped=yes + skip "cross-test-client exited $e, marking as skipped" elif grep . "$DBUS_TEST_TMPDIR"/cross-client.log >/dev/null; then - echo "OK, cross-test-client produced some output" + ok "cross-test-client produced some output" else - echo "cross-test-client produced no output" >&2 - failed=yes + not_ok "cross-test-client produced no output" fi if test "$e" = 77; then - echo "test-client exited $e, marking as skipped" - skipped=yes + skip "test-client exited $e, marking as skipped" elif grep . "$DBUS_TEST_TMPDIR"/cross-server.log >/dev/null; then - echo "OK, cross-test-server produced some output" + ok "cross-test-server produced some output" else - echo "cross-test-server produced no output" >&2 - failed=yes + not_ok "cross-test-server produced no output" fi -if grep fail "$DBUS_TEST_TMPDIR"/cross-client.log; then - failed=yes +if grep fail "$DBUS_TEST_TMPDIR"/cross-client.log >&2; then + not_ok "cross-client reported failures" else - echo " - cross-test client reported no failures" + ok "cross-test client reported no failures" fi if grep untested "$DBUS_TEST_TMPDIR"/cross-server.log; then - failed=yes + not_ok "cross-server reported untested functions" else - echo " - cross-test server reported no untested functions" + ok "cross-test server reported no untested functions" fi -echo "waiting for cross-test server to exit" +echo "# waiting for cross-test server to exit" if wait "$cross_test_server_pid"; then - echo "cross-test server: exit status 0" + ok "cross-test server: exit status 0" else - echo "cross-test server: exit status $?" - failed=yes + not_ok "cross-test server: exit status $?" fi -echo "==== client log ====" -cat "$DBUS_TEST_TMPDIR"/cross-client.log -echo "==== end ====" +echo "# ==== client log ====" +cat "$DBUS_TEST_TMPDIR"/cross-client.log | sed -e 's/^/# /' +echo "# ==== end ====" -echo "==== server log ====" -cat "$DBUS_TEST_TMPDIR"/cross-server.log -echo "==== end ====" +echo "# ==== server log ====" +cat "$DBUS_TEST_TMPDIR"/cross-server.log | sed -e 's/^/# /' +echo "# ==== end ====" rm -f "$DBUS_TEST_TMPDIR"/test-service.log rm -f "$DBUS_TEST_TMPDIR"/cross-client.log rm -f "$DBUS_TEST_TMPDIR"/cross-server.log rm -f "$DBUS_TEST_TMPDIR"/monitor.log -if test -n "$skipped"; then - exit 77 -fi +echo "1..$test_num" + if test -n "$failed"; then exit 1 fi diff --git a/test/test-client.py b/test/test-client.py index f04b10c..913a851 100755 --- a/test/test-client.py +++ b/test/test-client.py @@ -30,6 +30,12 @@ import time import logging import weakref +try: + from tap.runner import TAPTestRunner +except ImportError: + print('1..0 # SKIP cannot import TAPTestRunner') + raise SystemExit(0) + import dbus import _dbus_bindings import dbus.glib @@ -40,8 +46,8 @@ from dbus._compat import is_py2, is_py3 try: from gi.repository import GObject as gobject except ImportError: - raise SystemExit(77) - + print('1..0 # SKIP cannot import GObject') + raise SystemExit(0) logging.basicConfig() @@ -628,4 +634,6 @@ if __name__ == '__main__': gobject.threads_init() dbus.glib.init_threads() - unittest.main() + runner = TAPTestRunner() + runner.set_stream(True) + unittest.main(testRunner=runner) diff --git a/test/test-exception-py2.py b/test/test-exception-py2.py index 02cf93d..3633ea3 100755 --- a/test/test-exception-py2.py +++ b/test/test-exception-py2.py @@ -4,6 +4,12 @@ import sys import unittest +try: + from tap.runner import TAPTestRunner +except ImportError: + print('1..0 # SKIP cannot import TAPTestRunner') + raise SystemExit(0) + import dbus # from test-service.py @@ -59,4 +65,6 @@ class DBusExceptionTestCase(unittest.TestCase): if __name__ == "__main__": - unittest.main() + runner = TAPTestRunner() + runner.set_stream(True) + unittest.main(testRunner=runner) diff --git a/test/test-exception-py3.py b/test/test-exception-py3.py index eddb45a..a0c981e 100755 --- a/test/test-exception-py3.py +++ b/test/test-exception-py3.py @@ -3,6 +3,12 @@ import unittest +try: + from tap.runner import TAPTestRunner +except ImportError: + print('1..0 # SKIP cannot import TAPTestRunner') + raise SystemExit(0) + import dbus # from test-service.py @@ -28,4 +34,6 @@ class DBusExceptionTestCase(unittest.TestCase): if __name__ == "__main__": - unittest.main() + runner = TAPTestRunner() + runner.set_stream(True) + unittest.main(testRunner=runner) diff --git a/test/test-p2p.py b/test/test-p2p.py index 84443ee..7c7655d 100755 --- a/test/test-p2p.py +++ b/test/test-p2p.py @@ -35,9 +35,16 @@ import dbus.service from dbus._compat import is_py2 try: + from tap.runner import TAPTestRunner +except ImportError: + print('1..0 # SKIP cannot import TAPTestRunner') + raise SystemExit(0) + +try: from gi.repository import GObject as gobject except ImportError: - raise SystemExit(77) + print('1..0 # SKIP cannot import GObject') + raise SystemExit(0) logging.basicConfig() logging.getLogger().setLevel(1) @@ -97,4 +104,6 @@ if __name__ == '__main__': gobject.threads_init() dbus.glib.init_threads() - unittest.main() + runner = TAPTestRunner() + runner.set_stream(True) + unittest.main(testRunner=runner) diff --git a/test/test-signals.py b/test/test-signals.py index 100cb57..3c618c8 100755 --- a/test/test-signals.py +++ b/test/test-signals.py @@ -35,9 +35,16 @@ import dbus.glib import dbus.service try: + from tap.runner import TAPTestRunner +except ImportError: + print('1..0 # SKIP cannot import TAPTestRunner') + raise SystemExit(0) + +try: from gi.repository import GObject as gobject except ImportError: - raise SystemExit(77) + print('1..0 # SKIP cannot import GObject') + raise SystemExit(0) logging.basicConfig() logging.getLogger().setLevel(1) @@ -161,4 +168,6 @@ if __name__ == '__main__': dbus.glib.init_threads() logger.info('Starting unit test') - unittest.main() + runner = TAPTestRunner() + runner.set_stream(True) + unittest.main(testRunner=runner) diff --git a/test/test-standalone.py b/test/test-standalone.py index ea1e894..2f6121e 100755 --- a/test/test-standalone.py +++ b/test/test-standalone.py @@ -33,6 +33,12 @@ import sys import os import unittest +try: + from tap.runner import TAPTestRunner +except ImportError: + print('1..0 # SKIP cannot import TAPTestRunner') + raise SystemExit(0) + import _dbus_bindings import dbus import dbus.lowlevel as lowlevel @@ -555,4 +561,6 @@ if __name__ == '__main__': kwargs = {} if sys.version_info[:2] >= (2, 7): kwargs['verbosity'] = 2 - unittest.main(**kwargs) + runner = TAPTestRunner() + runner.set_stream(True) + unittest.main(testRunner=runner, **kwargs) diff --git a/test/test-unusable-main-loop.py b/test/test-unusable-main-loop.py index cacee91..6e81315 100755 --- a/test/test-unusable-main-loop.py +++ b/test/test-unusable-main-loop.py @@ -23,18 +23,25 @@ # DEALINGS IN THE SOFTWARE. from __future__ import print_function + +import unittest + +try: + from tap.runner import TAPTestRunner +except ImportError: + print('1..0 # SKIP cannot import TAPTestRunner') + raise SystemExit(0) + import dbus from dbus_py_test import UnusableMainLoop -def main(): - UnusableMainLoop(set_as_default=True) - try: - bus = dbus.SessionBus() - except ValueError as e: - print("Correctly got ValueError from UnusableMainLoop") - else: - raise AssertionError("Expected ValueError from UnusableMainLoop") +class Test(unittest.TestCase): + def test_unusable_main_loop(self): + UnusableMainLoop(set_as_default=True) + self.assertRaises(ValueError, lambda: dbus.SessionBus()) if __name__ == '__main__': - main() + runner = TAPTestRunner() + runner.set_stream(True) + unittest.main(testRunner=runner) |