From 83467ee0004c4169c12cadbe05c24d24d172a89f Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Sat, 20 Feb 2021 19:15:34 +0200 Subject: [PATCH 1/2] A test for playSound(): raises an exception if there is no plugin --- src/bitmessageqt/tests/main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bitmessageqt/tests/main.py b/src/bitmessageqt/tests/main.py index b3aa67fa..5e6b3a07 100644 --- a/src/bitmessageqt/tests/main.py +++ b/src/bitmessageqt/tests/main.py @@ -34,7 +34,7 @@ class TestBase(unittest.TestCase): self.fail('Exception in the main thread: %s' % exc) -class TestMain(unittest.TestCase): +class TestMain(TestBase): """Test case for main window - basic features""" def test_translate(self): @@ -44,6 +44,11 @@ class TestMain(unittest.TestCase): QtCore.QString ) + @unittest.skipIf(bitmessageqt.get_plugins, 'skip plugin absence test') + def test_sound(self): + """Check if playing sound raises an exception if there is no plugin""" + self.window.playSound(bitmessageqt.sound.SOUND_CONNECTED, None) + class TestUISignaler(TestBase): """Test case for UISignalQueue""" From 7d4977364d9dbab122171f4112ac845683ccba92 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Sat, 20 Feb 2021 22:48:55 +0200 Subject: [PATCH 2/2] Minimal test for plugins checking pkg_resources --- src/plugins/tests.py | 16 ++++++++++++++++ src/tests/core.py | 3 +++ 2 files changed, 19 insertions(+) create mode 100644 src/plugins/tests.py diff --git a/src/plugins/tests.py b/src/plugins/tests.py new file mode 100644 index 00000000..5de96e9a --- /dev/null +++ b/src/plugins/tests.py @@ -0,0 +1,16 @@ +import unittest +from importlib import import_module + +try: + import pkg_resources +except ImportError: + pkg_resources = None + + +class TestPlugins(unittest.TestCase): + """Test case for plugins package""" + def test_get_plugin(self): + """Import from plugin raises ImportError without pkg_resources""" + if pkg_resources is None: + with self.assertRaises(ImportError): + import_module('plugin') diff --git a/src/tests/core.py b/src/tests/core.py index 52cea234..2085c0ef 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -424,6 +424,9 @@ def run(): qt_tests = loader.loadTestsFromModule(bitmessageqt.tests) suite.addTests(qt_tests) + import plugins.tests + suite.addTests(loader.loadTestsFromModule(plugins.tests)) + def keep_exc(ex_cls, exc, tb): # pylint: disable=unused-argument """Own exception hook for test cases""" excQueue.put(('tests', exc))