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

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since ee7e423 was e4335ae, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 6 years ago

SASVIEW-957 logging changes (#158)

  • rework XStream to continue to write to stdout/stderr alongside redirection; make logging level setting consistent; make log configuration more consistent
  • rm XStream; QT signal in QtHandler? logging handler; only logs in Log Explorer (no stdout/stderr)
  • no need to change handler level
  • use QTextBrowser.append to facilitate auto-scrolling in the Log Explorer
  • 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.