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

ESS_GUIESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_sync_sascalc
Last change on this file since 58478a5 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
RevLine 
[0cd8612]1import sys
2import unittest
3import logging
4
[53c771e]5from PyQt5.QtGui import *
6from PyQt5.QtCore import *
7from PyQt5.QtWidgets import *
[0cd8612]8
[31c5b58]9# set up import paths
[83eb5208]10import sas.qtgui.path_prepare
[31c5b58]11
[0cd8612]12# Local
[83eb5208]13from sas.qtgui.Utilities.SasviewLogger import QtHandler
[0cd8612]14
[464cd07]15if not QApplication.instance():
16    app = QApplication(sys.argv)
[0cd8612]17
[a95260d]18class SasviewLoggerTest(unittest.TestCase):
19    def setUp(self):
20        """
21        Prepare the logger
22        """
23        self.logger = logging.getLogger(__name__)
[e4335ae]24        self.handler = QtHandler()
25        self.handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
26        self.logger.addHandler(self.handler)
[a95260d]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        """
[e4335ae]36        # Attach the listener
37        self.handler.messageWritten.connect(self.outHandlerGui.insertPlainText)
[a95260d]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)
[0cd8612]52
53if __name__ == "__main__":
54    unittest.main()
Note: See TracBrowser for help on using the repository browser.