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 fb560d2 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 | |
---|
1 | import sys |
---|
2 | import unittest |
---|
3 | import logging |
---|
4 | |
---|
5 | from PyQt5.QtGui import * |
---|
6 | from PyQt5.QtCore import * |
---|
7 | from PyQt5.QtWidgets import * |
---|
8 | |
---|
9 | # set up import paths |
---|
10 | import sas.qtgui.path_prepare |
---|
11 | |
---|
12 | # Local |
---|
13 | from sas.qtgui.Utilities.SasviewLogger import QtHandler |
---|
14 | |
---|
15 | if not QApplication.instance(): |
---|
16 | app = QApplication(sys.argv) |
---|
17 | |
---|
18 | class 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 | |
---|
53 | if __name__ == "__main__": |
---|
54 | unittest.main() |
---|
Note: See
TracBrowser
for help on using the repository browser.