source: sasview/src/sas/qtgui/UnitTesting/SasviewLoggerTest.py @ 9a05a8d5

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 9a05a8d5 was 31c5b58, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Refactored to allow running with run.py.
Minor fixes to plotting.

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