From d6953eb4507f9430e478faa1981152d870a6f557 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 9 Jun 2020 17:14:26 +0300 Subject: [PATCH] New package: bitmessageqt.tests any test cases from it will be added to tests.core test suite if possible, e.g. PyQt is functional. TestSupport - minimal test case for support module to reproduce #1633. --- src/bitmessagemain.py | 5 +++-- src/bitmessageqt/tests/__init__.py | 6 ++++++ src/bitmessageqt/tests/main.py | 30 +++++++++++++++++++++++++++ src/bitmessageqt/tests/support.py | 33 ++++++++++++++++++++++++++++++ src/tests/core.py | 10 +++++++-- 5 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 src/bitmessageqt/tests/__init__.py create mode 100644 src/bitmessageqt/tests/main.py create mode 100644 src/bitmessageqt/tests/support.py diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 2a279aca..9fa9c475 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -363,11 +363,12 @@ class Main(object): while state.shutdown == 0: time.sleep(1) if ( - state.testmode and time.time() - - state.last_api_response >= 30 + state.testmode + and time.time() - state.last_api_response >= 30 ): self.stop() elif not state.enableGUI: + state.enableGUI = True # pylint: disable=relative-import from tests import core as test_core test_core_result = test_core.run() diff --git a/src/bitmessageqt/tests/__init__.py b/src/bitmessageqt/tests/__init__.py new file mode 100644 index 00000000..3955a761 --- /dev/null +++ b/src/bitmessageqt/tests/__init__.py @@ -0,0 +1,6 @@ +"""bitmessageqt tests""" + +from main import TestMain +from support import TestSupport + +__all__ = ["TestMain", "TestSupport"] diff --git a/src/bitmessageqt/tests/main.py b/src/bitmessageqt/tests/main.py new file mode 100644 index 00000000..d2a64f83 --- /dev/null +++ b/src/bitmessageqt/tests/main.py @@ -0,0 +1,30 @@ +"""Common definitions for bitmessageqt tests""" + +import unittest + +from PyQt4 import QtCore, QtGui + +import bitmessageqt +from tr import _translate + + +class TestBase(unittest.TestCase): + """Base class for bitmessageqt test case""" + + def setUp(self): + self.app = QtGui.QApplication([]) + self.window = bitmessageqt.MyForm() + + def tearDown(self): + self.app.deleteLater() + + +class TestMain(unittest.TestCase): + """Test case for main window - basic features""" + + def test_translate(self): + """Check the results of _translate() with various args""" + self.assertIsInstance( + _translate("MainWindow", "Test"), + QtCore.QString + ) diff --git a/src/bitmessageqt/tests/support.py b/src/bitmessageqt/tests/support.py new file mode 100644 index 00000000..ba28b73a --- /dev/null +++ b/src/bitmessageqt/tests/support.py @@ -0,0 +1,33 @@ +# from PyQt4 import QtTest + +import sys + +from shared import isAddressInMyAddressBook + +from main import TestBase + + +class TestSupport(TestBase): + """A test case for support module""" + SUPPORT_ADDRESS = 'BM-2cUdgkDDAahwPAU6oD2A7DnjqZz3hgY832' + SUPPORT_SUBJECT = 'Support request' + + def test(self): + """trigger menu action "Contact Support" and check the result""" + ui = self.window.ui + self.assertEqual(ui.lineEditTo.text(), '') + self.assertEqual(ui.lineEditSubject.text(), '') + + ui.actionSupport.trigger() + + self.assertTrue( + isAddressInMyAddressBook(self.SUPPORT_ADDRESS)) + + self.assertEqual( + ui.tabWidget.currentIndex(), ui.tabWidget.indexOf(ui.send)) + self.assertEqual( + ui.lineEditTo.text(), self.SUPPORT_ADDRESS) + self.assertEqual( + ui.lineEditSubject.text(), self.SUPPORT_SUBJECT) + self.assertIn( + sys.version, ui.textEditMessage.toPlainText()) diff --git a/src/tests/core.py b/src/tests/core.py index 9132e668..d33b2117 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -30,7 +30,6 @@ try: except ImportError: stem_version = None - knownnodes_file = os.path.join(state.appdata, 'knownnodes.dat') @@ -245,7 +244,14 @@ class TestCore(unittest.TestCase): def run(): """Starts all tests defined in this module""" - loader = unittest.TestLoader() + loader = unittest.defaultTestLoader loader.sortTestMethodsUsing = None suite = loader.loadTestsFromTestCase(TestCore) + try: + import bitmessageqt.tests + except ImportError: + pass + else: + qt_tests = loader.loadTestsFromModule(bitmessageqt.tests) + suite.addTests(qt_tests) return unittest.TextTestRunner(verbosity=2).run(suite)