/ src / bitmessageqt / tests / main.py
main.py
 1  """Common definitions for bitmessageqt tests"""
 2  
 3  import sys
 4  import unittest
 5  
 6  from PyQt4 import QtCore, QtGui
 7  from six.moves import queue
 8  
 9  import bitmessageqt
10  from bitmessageqt import _translate, config, queues
11  
12  
13  class TestBase(unittest.TestCase):
14      """Base class for bitmessageqt test case"""
15  
16      @classmethod
17      def setUpClass(cls):
18          """Provide the UI test cases with common settings"""
19          cls.config = config
20  
21      def setUp(self):
22          self.app = (
23              QtGui.QApplication.instance()
24              or bitmessageqt.BitmessageQtApplication(sys.argv))
25          self.window = self.app.activeWindow()
26          if not self.window:
27              self.window = bitmessageqt.MyForm()
28              self.window.appIndicatorInit(self.app)
29  
30      def tearDown(self):
31          """Search for exceptions in closures called by timer and fail if any"""
32          # self.app.deleteLater()
33          concerning = []
34          while True:
35              try:
36                  thread, exc = queues.excQueue.get(block=False)
37              except queue.Empty:
38                  break
39              if thread == 'tests':
40                  concerning.append(exc)
41          if concerning:
42              self.fail(
43                  'Exceptions found in the main thread:\n%s' % '\n'.join((
44                      str(e) for e in concerning
45                  )))
46  
47  
48  class TestMain(unittest.TestCase):
49      """Test case for main window - basic features"""
50  
51      def test_translate(self):
52          """Check the results of _translate() with various args"""
53          self.assertIsInstance(
54              _translate("MainWindow", "Test"),
55              QtCore.QString
56          )
57  
58  
59  class TestUISignaler(TestBase):
60      """Test case for UISignalQueue"""
61  
62      def test_updateStatusBar(self):
63          """Check arguments order of updateStatusBar command"""
64          queues.UISignalQueue.put((
65              'updateStatusBar', (
66                  _translate("test", "Testing updateStatusBar..."), 1)
67          ))
68  
69          QtCore.QTimer.singleShot(60, self.app.quit)
70          self.app.exec_()
71          # self.app.processEvents(QtCore.QEventLoop.AllEvents, 60)