From ea109bc21ee847936b150ac877777ec263472c86 Mon Sep 17 00:00:00 2001 From: coolguy-cell Date: Wed, 3 Jun 2020 15:36:23 +0530 Subject: [PATCH 1/5] fixed CQ for bitmessageqt.dialogs module --- src/bitmessageqt/dialogs.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bitmessageqt/dialogs.py b/src/bitmessageqt/dialogs.py index 10701500..e76dd84e 100644 --- a/src/bitmessageqt/dialogs.py +++ b/src/bitmessageqt/dialogs.py @@ -1,8 +1,7 @@ """ -src/bitmessageqt/dialogs.py -=========================== +Custom dialog classes """ - +# pylint: disable=too-few-public-methods from PyQt4 import QtGui import paths 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 2/5] 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) From 731f75687e48a103ecd73a343a89b40b1821406f Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 9 Jun 2020 17:43:24 +0300 Subject: [PATCH 3/5] Install needed packages and try to run Qt tests --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d7141188..274d14c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,12 +6,14 @@ addons: packages: - build-essential - libcap-dev + - python-qt4 - tor + - xvfb install: - pip install -r requirements.txt - ln -s src pybitmessage # tests environment - python setup.py install script: - python checkdeps.py - - src/bitmessagemain.py -t + - xvfb-run src/bitmessagemain.py -t - python setup.py test From f03bdfb3291b19ca3cc11f1e3024cc0e1ed9ef1f Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 9 Jun 2020 18:33:03 +0300 Subject: [PATCH 4/5] Dirty quickfix for #1633 --- src/bitmessageqt/support.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitmessageqt/support.py b/src/bitmessageqt/support.py index 4970beba..ac02e2ca 100644 --- a/src/bitmessageqt/support.py +++ b/src/bitmessageqt/support.py @@ -88,7 +88,7 @@ def createAddressIfNeeded(myapp): if not checkHasNormalAddress(): queues.addressGeneratorQueue.put(( 'createRandomAddress', 4, 1, - SUPPORT_MY_LABEL.toUtf8(), + str(SUPPORT_MY_LABEL.toUtf8()), 1, "", False, defaults.networkDefaultProofOfWorkNonceTrialsPerByte, defaults.networkDefaultPayloadLengthExtraBytes From 277549cff1ccd5b2f6a9bcea62e374f5e42f9fb9 Mon Sep 17 00:00:00 2001 From: coolguy-cell Date: Tue, 9 Jun 2020 15:53:18 +0530 Subject: [PATCH 5/5] fixed CQ for bitmessageqt.sound module --- src/bitmessageqt/sound.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bitmessageqt/sound.py b/src/bitmessageqt/sound.py index 9c86a9a4..33b4c500 100644 --- a/src/bitmessageqt/sound.py +++ b/src/bitmessageqt/sound.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +"""Sound Module""" # sound type constants SOUND_NONE = 0 @@ -12,10 +13,12 @@ SOUND_CONNECTION_GREEN = 5 # returns true if the given sound category is a connection sound # rather than a received message sound def is_connection_sound(category): + """Check if sound type is related to connectivity""" return category in ( SOUND_CONNECTED, SOUND_DISCONNECTED, SOUND_CONNECTION_GREEN ) + extensions = ('wav', 'mp3', 'oga')