source: sasview/src/sas/qtgui/UnitTesting/SasviewLoggerTest.py @ 0cd8612

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 0cd8612 was 0cd8612, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

output console + logging

  • Property mode set to 100755
File size: 1.6 KB
Line 
1import sys
2import unittest
3import logging
4
5from PyQt4.QtGui import *
6from PyQt4.QtTest import QTest
7from PyQt4.QtCore import *
8
9# Local
10from SasviewLogger import XStream
11from SasviewLogger import QtHandler
12
13app = QApplication(sys.argv)
14
15class SasviewLoggerTest(unittest.TestCase):
16    def setUp(self):
17        """
18        Prepare the logger
19        """
20        self.logger = logging.getLogger(__name__)
21        handler = QtHandler()
22        handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
23        self.logger.addHandler(handler)
24        self.logger.setLevel(logging.DEBUG)
25
26        self.outHandlerGui=QTextBrowser()
27
28
29    def test_stdout(self):
30        """
31        Test redirection of all levels of logging
32        """
33        # Attach the listeners
34        XStream.stderr().messageWritten.connect( self.outHandlerGui.insertPlainText )
35        XStream.stdout().messageWritten.connect( self.outHandlerGui.insertPlainText )
36
37        # Send the signals
38        self.logger.debug('debug message')
39        self.logger.info('info message')
40        self.logger.warning('warning message')
41        self.logger.error('error message')
42        sys.stdout.write('with stdout')
43        sys.stderr.write('with stderr')
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        self.assertIn('with stdout', out)
53        self.assertIn('with stderr', out)
54
55if __name__ == "__main__":
56    unittest.main()
Note: See TracBrowser for help on using the repository browser.