source: sasview/src/sas/qtgui/Utilities/UnitTesting/SasviewLoggerTest.py @ e4c45887

ESS_GUIESS_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 e4c45887 was 53c771e, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Converted unit tests

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