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

Last change on this file since 1309205b was 1309205b, checked in by Torin Cooper-Bennun <torin.cooper-bennun@…>, 6 years ago

modify logger unit test to reflect changes (passes)

  • Property mode set to 100644
File size: 1.4 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 QtHandler
14
15if not QApplication.instance():
16    app = QApplication(sys.argv)
17
18class SasviewLoggerTest(unittest.TestCase):
19    def setUp(self):
20        """
21        Prepare the logger
22        """
23        self.logger = logging.getLogger(__name__)
24        self.handler = QtHandler()
25        self.handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
26        self.logger.addHandler(self.handler)
27        self.logger.setLevel(logging.DEBUG)
28
29        self.outHandlerGui=QTextBrowser()
30
31
32    def testQtHandler(self):
33        """
34        Test redirection of all levels of logging
35        """
36        # Attach the listener
37        self.handler.messageWritten.connect(self.outHandlerGui.insertPlainText)
38
39        # Send the signals
40        self.logger.debug('debug message')
41        self.logger.info('info message')
42        self.logger.warning('warning message')
43        self.logger.error('error message')
44
45        out=self.outHandlerGui.toPlainText()
46
47        # Assure everything got logged
48        self.assertIn('DEBUG: debug message', out)
49        self.assertIn('INFO: info message', out)
50        self.assertIn('WARNING: warning message', out)
51        self.assertIn('ERROR: error message', out)
52
53if __name__ == "__main__":
54    unittest.main()
Note: See TracBrowser for help on using the repository browser.