source: sasview/src/sas/qtgui/UnitTesting/SasviewLoggerTest.py @ 9968d6a

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 9968d6a was a95260d, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

Minor fixes

  • Property mode set to 100755
File size: 1.6 KB
Line 
1import sys
2import unittest
3import logging
4
5from PyQt4.QtGui import *
6from PyQt4.QtCore import *
7
8# Local
9from SasviewLogger import XStream
10from SasviewLogger import QtHandler
11
12app = QApplication(sys.argv)
13
14class SasviewLoggerTest(unittest.TestCase):
15    def setUp(self):
16        """
17        Prepare the logger
18        """
19        self.logger = logging.getLogger(__name__)
20        handler = QtHandler()
21        handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
22        self.logger.addHandler(handler)
23        self.logger.setLevel(logging.DEBUG)
24
25        self.outHandlerGui=QTextBrowser()
26
27
28    def testQtHandler(self):
29        """
30        Test redirection of all levels of logging
31        """
32        # Attach the listeners
33        XStream.stderr().messageWritten.connect( self.outHandlerGui.insertPlainText )
34        XStream.stdout().messageWritten.connect( self.outHandlerGui.insertPlainText )
35
36        # Send the signals
37        self.logger.debug('debug message')
38        self.logger.info('info message')
39        self.logger.warning('warning message')
40        self.logger.error('error message')
41        sys.stdout.write('with stdout')
42        sys.stderr.write('with stderr')
43
44        out=self.outHandlerGui.toPlainText()
45
46        # Assure everything got logged
47        self.assertIn('DEBUG: debug message', out)
48        self.assertIn('INFO: info message', out)
49        self.assertIn('WARNING: warning message', out)
50        self.assertIn('ERROR: error message', out)
51        self.assertIn('with stdout', out)
52        self.assertIn('with stderr', out)
53
54if __name__ == "__main__":
55    unittest.main()
Note: See TracBrowser for help on using the repository browser.