Improve the base class for bitmessageqt test cases

This commit is contained in:
Lee Miller 2024-05-14 17:38:43 +03:00
parent a71b44e95c
commit 21bef1058d
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
2 changed files with 21 additions and 10 deletions

View File

@ -1,9 +1,9 @@
"""bitmessageqt tests""" """bitmessageqt tests"""
from addressbook import TestAddressbook from .addressbook import TestAddressbook
from main import TestMain, TestUISignaler from .main import TestMain, TestUISignaler
from settings import TestSettings from .settings import TestSettings
from support import TestSupport from .support import TestSupport
__all__ = [ __all__ = [
"TestAddressbook", "TestMain", "TestSettings", "TestSupport", "TestAddressbook", "TestMain", "TestSettings", "TestSupport",

View File

@ -1,19 +1,23 @@
"""Common definitions for bitmessageqt tests""" """Common definitions for bitmessageqt tests"""
import Queue
import sys import sys
import unittest import unittest
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from six.moves import queue
import bitmessageqt import bitmessageqt
import queues from bitmessageqt import _translate, config, queues
from tr import _translate
class TestBase(unittest.TestCase): class TestBase(unittest.TestCase):
"""Base class for bitmessageqt test case""" """Base class for bitmessageqt test case"""
@classmethod
def setUpClass(cls):
"""Provide the UI test cases with common settings"""
cls.config = config
def setUp(self): def setUp(self):
self.app = ( self.app = (
QtGui.QApplication.instance() QtGui.QApplication.instance()
@ -24,14 +28,21 @@ class TestBase(unittest.TestCase):
self.window.appIndicatorInit(self.app) self.window.appIndicatorInit(self.app)
def tearDown(self): def tearDown(self):
"""Search for exceptions in closures called by timer and fail if any"""
# self.app.deleteLater() # self.app.deleteLater()
concerning = []
while True: while True:
try: try:
thread, exc = queues.excQueue.get(block=False) thread, exc = queues.excQueue.get(block=False)
except Queue.Empty: except queue.Empty:
return break
if thread == 'tests': if thread == 'tests':
self.fail('Exception in the main thread: %s' % exc) concerning.append(exc)
if concerning:
self.fail(
'Exceptions found in the main thread:\n%s' % '\n'.join((
str(e) for e in concerning
)))
class TestMain(unittest.TestCase): class TestMain(unittest.TestCase):