diff options
author | Simon McVittie <smcv@collabora.com> | 2020-01-11 11:49:17 +0000 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2020-01-11 11:49:17 +0000 |
commit | da98d6fce4952205a136b14c7ac7b8414c680ef5 (patch) | |
tree | 6f3a2746c23a824f7daccfd6554f7ffa4800a406 | |
parent | e22dee8fdbf2df0f2c18d53a239931732d134c0a (diff) | |
download | dbus-python-da98d6fce4952205a136b14c7ac7b8414c680ef5.tar.gz |
Add support for testing without tappy
The latest version of tappy dropped Python 2 support, but I want to be
able to continue to run dbus-python tests on Python 2 for now.
Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | test/dbus_test_utils.py | 53 | ||||
-rwxr-xr-x | test/test-client.py | 11 | ||||
-rwxr-xr-x | test/test-exception-py2.py | 11 | ||||
-rwxr-xr-x | test/test-exception-py3.py | 11 | ||||
-rwxr-xr-x | test/test-p2p.py | 11 | ||||
-rwxr-xr-x | test/test-signals.py | 11 | ||||
-rwxr-xr-x | test/test-standalone.py | 11 | ||||
-rwxr-xr-x | test/test-unusable-main-loop.py | 11 |
9 files changed, 68 insertions, 63 deletions
diff --git a/Makefile.am b/Makefile.am index 21149b5..5780cce 100644 --- a/Makefile.am +++ b/Makefile.am @@ -248,6 +248,7 @@ dist_test_py = \ dist_test_extra_python = \ test/crosstest.py \ + test/dbus_test_utils.py \ $(NULL) dist_test_extra_scripts = \ diff --git a/test/dbus_test_utils.py b/test/dbus_test_utils.py new file mode 100644 index 0000000..a7a6619 --- /dev/null +++ b/test/dbus_test_utils.py @@ -0,0 +1,53 @@ +# Copyright 2020 Simon McVittie +# +# SPDX-License-Identifier: MIT +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, copy, +# modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. + +from __future__ import print_function + +import unittest + +try: + from tap.runner import TAPTestRunner +except ImportError: + TAPTestRunner = None # type: ignore + +def main(): + # type: (...) -> None + if TAPTestRunner is not None: + runner = TAPTestRunner() + runner.set_stream(True) + unittest.main(testRunner=runner) + else: + # You thought pycotap was a minimal TAP implementation? + print('1..1') + program = unittest.main(exit=False) + if program.result.wasSuccessful(): + print( + 'ok 1 - %r (tap module not available)' + % program.result + ) + else: + print( + 'not ok 1 - %r (tap module not available)' + % program.result + ) diff --git a/test/test-client.py b/test/test-client.py index f028ced..bc6a900 100755 --- a/test/test-client.py +++ b/test/test-client.py @@ -32,17 +32,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 import dbus.lowlevel import dbus.service +import dbus_test_utils from dbus._compat import is_py2, is_py3 @@ -693,6 +688,4 @@ if __name__ == '__main__': gobject.threads_init() dbus.glib.init_threads() - runner = TAPTestRunner() - runner.set_stream(True) - unittest.main(testRunner=runner) + dbus_test_utils.main() diff --git a/test/test-exception-py2.py b/test/test-exception-py2.py index 327536d..a8427c6 100755 --- a/test/test-exception-py2.py +++ b/test/test-exception-py2.py @@ -6,13 +6,8 @@ import sys import unittest -try: - from tap.runner import TAPTestRunner -except ImportError: - print('1..0 # SKIP cannot import TAPTestRunner') - raise SystemExit(0) - import dbus +import dbus_test_utils # from test-service.py class ServiceError(dbus.DBusException): @@ -67,6 +62,4 @@ class DBusExceptionTestCase(unittest.TestCase): if __name__ == "__main__": - runner = TAPTestRunner() - runner.set_stream(True) - unittest.main(testRunner=runner) + dbus_test_utils.main() diff --git a/test/test-exception-py3.py b/test/test-exception-py3.py index 8f1541c..ee8212f 100755 --- a/test/test-exception-py3.py +++ b/test/test-exception-py3.py @@ -5,13 +5,8 @@ import unittest -try: - from tap.runner import TAPTestRunner -except ImportError: - print('1..0 # SKIP cannot import TAPTestRunner') - raise SystemExit(0) - import dbus +import dbus_test_utils # from test-service.py class ServiceError(dbus.DBusException): @@ -36,6 +31,4 @@ class DBusExceptionTestCase(unittest.TestCase): if __name__ == "__main__": - runner = TAPTestRunner() - runner.set_stream(True) - unittest.main(testRunner=runner) + dbus_test_utils.main() diff --git a/test/test-p2p.py b/test/test-p2p.py index d895eff..b0d7ac0 100755 --- a/test/test-p2p.py +++ b/test/test-p2p.py @@ -35,16 +35,11 @@ import dbus import dbus.glib import dbus.service import dbus.types +import dbus_test_utils 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: print('1..0 # SKIP cannot import GObject') @@ -131,6 +126,4 @@ if __name__ == '__main__': gobject.threads_init() dbus.glib.init_threads() - runner = TAPTestRunner() - runner.set_stream(True) - unittest.main(testRunner=runner) + dbus_test_utils.main() diff --git a/test/test-signals.py b/test/test-signals.py index 7d395a9..1e55f78 100755 --- a/test/test-signals.py +++ b/test/test-signals.py @@ -35,12 +35,7 @@ import dbus import _dbus_bindings import dbus.glib import dbus.service - -try: - from tap.runner import TAPTestRunner -except ImportError: - print('1..0 # SKIP cannot import TAPTestRunner') - raise SystemExit(0) +import dbus_test_utils try: from gi.repository import GObject as gobject @@ -170,6 +165,4 @@ if __name__ == '__main__': dbus.glib.init_threads() logger.info('Starting unit test') - runner = TAPTestRunner() - runner.set_stream(True) - unittest.main(testRunner=runner) + dbus_test_utils.main() diff --git a/test/test-standalone.py b/test/test-standalone.py index 21d4b62..cd967a6 100755 --- a/test/test-standalone.py +++ b/test/test-standalone.py @@ -35,16 +35,11 @@ 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 import dbus.types as types +import dbus_test_utils from dbus._compat import is_py2, is_py3 if is_py3: @@ -653,6 +648,4 @@ class TestVersion(unittest.TestCase): self.assertLess(dbus.__version__, '9') if __name__ == '__main__': - runner = TAPTestRunner() - runner.set_stream(True) - unittest.main(testRunner=runner, verbosity=2) + dbus_test_utils.main() diff --git a/test/test-unusable-main-loop.py b/test/test-unusable-main-loop.py index c3a6930..54d2a16 100755 --- a/test/test-unusable-main-loop.py +++ b/test/test-unusable-main-loop.py @@ -28,13 +28,8 @@ 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 +import dbus_test_utils from dbus_py_test import UnusableMainLoop @@ -44,6 +39,4 @@ class Test(unittest.TestCase): self.assertRaises(ValueError, lambda: dbus.SessionBus()) if __name__ == '__main__': - runner = TAPTestRunner() - runner.set_stream(True) - unittest.main(testRunner=runner) + dbus_test_utils.main() |