1
0

Merge pull request #8897 from accumulator/move_tests_to_root

tests: move /electrum/tests to /tests
This commit is contained in:
accumulator
2024-02-19 10:51:42 +01:00
committed by GitHub
104 changed files with 32 additions and 27 deletions

View File

@@ -110,12 +110,12 @@ task:
- tar -xaf $BITCOIND_PATH || (rm -f /tmp/bitcoind/* && curl --output $BITCOIND_PATH $BITCOIND_URL && tar -xaf $BITCOIND_PATH)
- cp -a bitcoin-$BITCOIND_VERSION/* /usr/
bitcoind_service_background_script:
- electrum/tests/regtest/run_bitcoind.sh
- tests/regtest/run_bitcoind.sh
electrumx_service_background_script:
- electrum/tests/regtest/run_electrumx.sh
- tests/regtest/run_electrumx.sh
regtest_script:
- sleep 10s
- python3 -m unittest electrum/tests/regtest.py
- python3 -m unittest tests/regtest.py
env:
ELECTRUM_REQUIREMENTS: contrib/requirements/requirements.txt
# ElectrumX exits with an error without this:

View File

@@ -4,7 +4,7 @@ import unittest
from functools import wraps, partial
from unittest import SkipTest
from PyQt6.QtCore import QCoreApplication, QTimer, QMetaObject, Qt, pyqtSlot, QObject
from PyQt6.QtCore import QCoreApplication, QMetaObject, Qt, pyqtSlot, QObject
class TestQCoreApplication(QCoreApplication):
@@ -33,42 +33,48 @@ class QEventReceiver(QObject):
self.received.clear()
class QETestCase(unittest.IsolatedAsyncioTestCase):
class QETestCase(unittest.TestCase):
def setUp(self):
super().setUp()
self.app = None
self._e = None
self._event = threading.Event()
self._testcase_event = threading.Event()
self._app_ready_event = threading.Event()
def start_qt_task():
self.app = TestQCoreApplication([])
try:
assert self.app is None
self.app = TestQCoreApplication([])
self._app_ready_event.set()
self.app.exec()
self.app = None
except Exception as e:
print(f'Problem starting QCoreApplication: {str(e)}')
# self.timer = QTimer(self.app)
# self.timer.setSingleShot(False)
# self.timer.setInterval(500) # msec
# self.timer.timeout.connect(lambda: None) # periodically enter python scope
self.app.exec()
self.app = None
self.qt_thread = threading.Thread(target=start_qt_task)
self.qt_thread.start()
self._qt_thread = threading.Thread(target=start_qt_task)
self._qt_thread.start()
def tearDown(self):
self.app.exit()
if self.qt_thread.is_alive():
self.qt_thread.join()
if self._qt_thread.is_alive():
self._qt_thread.join()
def qt_test(func):
@wraps(func)
def decorator(self, *args):
if threading.current_thread().name == 'MainThread':
res = self._app_ready_event.wait(3)
if not res:
raise Exception('app not ready in time')
self._testcase_event.clear()
self.app._instance = self
self.app._method = func.__name__
QMetaObject.invokeMethod(self.app, 'doInvoke', Qt.ConnectionType.QueuedConnection)
self._event.wait(15)
res = self._testcase_event.wait(15)
if not res:
self._e = Exception('testcase timed out')
if self._e:
print("".join(traceback.format_exception(self._e)))
# deallocate stored exception from qt thread otherwise we SEGV garbage collector
@@ -88,6 +94,5 @@ def qt_test(func):
except Exception as e:
self._e = e
finally:
self._event.set()
self._event.clear()
self._testcase_event.set()
return decorator

View File

@@ -7,7 +7,7 @@ class TestLightning(unittest.TestCase):
@staticmethod
def run_shell(args, timeout=30):
process = subprocess.Popen(['electrum/tests/regtest/regtest.sh'] + args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, universal_newlines=True)
process = subprocess.Popen(['tests/regtest/regtest.sh'] + args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, universal_newlines=True)
for line in iter(process.stdout.readline, ''):
sys.stdout.write(line)
sys.stdout.flush()

View File

@@ -3,7 +3,7 @@ from electrum.payment_identifier import (maybe_extract_lightning_payment_identif
PaymentIdentifierType)
from . import ElectrumTestCase
from ..transaction import PartialTxOutput
from electrum.transaction import PartialTxOutput
class WalletMock:

View File

@@ -4,7 +4,7 @@ import tempfile
from electrum import SimpleConfig
from electrum.gui.qml.qetypes import QEAmount
from electrum.invoices import Invoice, LN_EXPIRY_NEVER
from electrum.tests.qt_util import QETestCase, QEventReceiver, qt_test
from tests.qt_util import QETestCase, QEventReceiver, qt_test
from electrum.transaction import PartialTxOutput

Some files were not shown because too many files have changed in this diff Show More