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

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

Converted unit tests

  • Property mode set to 100644
File size: 1.7 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 XStream
14from sas.qtgui.Utilities.SasviewLogger import QtHandler
[0cd8612]15
[464cd07]16if not QApplication.instance():
17    app = QApplication(sys.argv)
[0cd8612]18
[a95260d]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)
[0cd8612]58
59if __name__ == "__main__":
60    unittest.main()
Note: See TracBrowser for help on using the repository browser.