From 78e16e61a086d60611269834c7aaeb3657f565b8 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Thu, 28 Jul 2022 01:35:48 +0300 Subject: [PATCH] Build tests into the windows bundle if DEBUG=True is set in pyinstaller spec --- packages/pyinstaller/bitmessagemain.spec | 11 ++++++++--- src/bitmessagemain.py | 7 +++++-- src/pyelliptic/tests/__init__.py | 8 ++++++++ src/tests/__init__.py | 13 +++++++++++++ src/tests/core.py | 16 +++++++++++++++- 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/packages/pyinstaller/bitmessagemain.spec b/packages/pyinstaller/bitmessagemain.spec index 103d1ebb..fb2b572d 100644 --- a/packages/pyinstaller/bitmessagemain.spec +++ b/packages/pyinstaller/bitmessagemain.spec @@ -7,6 +7,7 @@ import time from PyInstaller.utils.hooks import copy_metadata +DEBUG = False site_root = os.path.abspath(HOMEPATH) spec_root = os.path.abspath(SPECPATH) arch = 32 if ctypes.sizeof(ctypes.c_voidp) == 4 else 64 @@ -25,6 +26,10 @@ snapshot = False hookspath = os.path.join(spec_root, 'hooks') +excludes = ['bsddb', 'bz2', 'tcl', 'tk', 'Tkinter', 'tests'] +if not DEBUG: + excludes += ['pybitmessage.tests', 'pyelliptic.tests'] + a = Analysis( [os.path.join(srcPath, 'bitmessagemain.py')], datas=[ @@ -39,7 +44,7 @@ a = Analysis( 'plugins.menu_qrcode', 'plugins.proxyconfig_stem' ], runtime_hooks=[os.path.join(hookspath, 'pyinstaller_rthook_plugins.py')], - excludes=['bsddb', 'bz2', 'tcl', 'tk', 'Tkinter', 'tests'] + excludes=excludes ) @@ -122,10 +127,10 @@ exe = EXE( a.zipfiles, a.datas, name=fname, - debug=False, + debug=DEBUG, strip=None, upx=False, - console=False, icon=os.path.join(srcPath, 'images', 'can-icon.ico') + console=DEBUG, icon=os.path.join(srcPath, 'images', 'can-icon.ico') ) coll = COLLECT( diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 4118926b..a0a074fe 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -313,8 +313,11 @@ class Main(object): # pylint: disable=relative-import from tests import core as test_core except ImportError: - self.stop() - return + try: + from pybitmessage.tests import core as test_core + except ImportError: + self.stop() + return test_core_result = test_core.run() self.stop() diff --git a/src/pyelliptic/tests/__init__.py b/src/pyelliptic/tests/__init__.py index e69de29b..62bffa9a 100644 --- a/src/pyelliptic/tests/__init__.py +++ b/src/pyelliptic/tests/__init__.py @@ -0,0 +1,8 @@ +import sys + +if getattr(sys, 'frozen', None): + from test_arithmetic import TestArithmetic + from test_blindsig import TestBlindSig + from test_openssl import TestOpenSSL + + __all__ = ["TestArithmetic", "TestBlindSig", "TestOpenSSL"] diff --git a/src/tests/__init__.py b/src/tests/__init__.py index e69de29b..1e5fb7b6 100644 --- a/src/tests/__init__.py +++ b/src/tests/__init__.py @@ -0,0 +1,13 @@ +import sys + +if getattr(sys, 'frozen', None): + from test_addresses import TestAddresses + from test_crypto import TestHighlevelcrypto + from test_l10n import TestL10n + from test_packets import TestSerialize + from test_protocol import TestProtocol + + __all__ = [ + "TestAddresses", "TestHighlevelcrypto", "TestL10n", + "TestProtocol", "TestSerialize" + ] diff --git a/src/tests/core.py b/src/tests/core.py index 1dca92c0..a7247971 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -40,6 +40,7 @@ try: except (OSError, socket.error): tor_port_free = False +frozen = getattr(sys, 'frozen', None) knownnodes_file = os.path.join(state.appdata, 'knownnodes.dat') @@ -298,6 +299,7 @@ class TestCore(unittest.TestCase): return self.fail('Failed to find at least 3 nodes to connect within 360 sec') + @unittest.skipIf(frozen, 'skip fragile test') def test_udp(self): """check default udp setting and presence of Announcer thread""" self.assertTrue( @@ -370,6 +372,7 @@ class TestCore(unittest.TestCase): '''select typeof(msgid) from sent where ackdata=?''', result) self.assertEqual(column_type[0][0] if column_type else '', 'text') + @unittest.skipIf(frozen, 'not packed test_pattern into the bundle') def test_old_knownnodes_pickle(self): """Testing old (v0.6.2) version knownnodes.dat file""" try: @@ -411,10 +414,21 @@ class TestCore(unittest.TestCase): def run(): - """Starts all tests defined in this module""" + """Starts all tests intended for core run""" loader = unittest.defaultTestLoader loader.sortTestMethodsUsing = None suite = loader.loadTestsFromTestCase(TestCore) + if frozen: + try: + from pybitmessage import tests + suite.addTests(loader.loadTestsFromModule(tests)) + except ImportError: + pass + try: + from pyelliptic import tests + suite.addTests(loader.loadTestsFromModule(tests)) + except ImportError: + pass try: import bitmessageqt.tests from xvfbwrapper import Xvfb