- Timestamp:
- Oct 15, 2010, 2:51:13 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/sc_branches/psps_testing/utilities/test_report.py
r29235 r29438 2 2 import datetime 3 3 from utilities.configuration import Configuration 4 from utilities.abstract_test_report import AbstractTestReport 4 5 5 class TestReportClass(logging.Logger): 6 datefmt = '%H:%M:%S' 7 fmt = '[%(asctime)8s] | %(requirement)65s | %(message)s' 8 class __impl(logging.Logger): 6 class TestReportClass(AbstractTestReport): 7 """ 8 An implementation of AbstractTestReport for PSPS testing test 9 reports. 10 """ 11 class __impl(AbstractTestReport): 9 12 """ Implementation of the singleton interface """ 10 13 def __init__(self): 11 """Sets logging up""" 12 logging.Logger.__init__(self, __name__) 13 logging.basicConfig(level=logging.INFO, 14 format=TestReportClass.fmt) 15 handler = logging.StreamHandler(open('log/test_report.txt', 'w')) 16 handler.setFormatter(logging.Formatter(TestReportClass.fmt, 17 TestReportClass.datefmt)) 18 self.addHandler(handler) 14 """Sets up AbstractTestReport""" 15 AbstractTestReport.__init__(self) 19 16 def id(self): 20 17 """ Test method, return singleton id """ … … 23 20 __instance = None 24 21 25 def info(self, message ):26 for line in message.split('\n'):27 logging.Logger.info(self,28 line,29 extra = {'requirement': 'INFO'})22 def info(self, message, extra=None): 23 self.addTestResult(AbstractTestReport.DEFAULT, 24 'INFO', 25 '', 26 message) 30 27 31 28 def __init__(self): … … 44 41 # Store instance reference as the only member in the handle 45 42 self.__dict__['_TestReportClass__instance'] = TestReportClass.__instance 46 logging.Logger.info(self,47 'Test performed on ' + str(datetime.date.today()),48 extra = {'requirement':'This column usually shows the "Requirement ID"'})43 self.info('Test performed on ' + str(datetime.date.today()), 44 extra = {'requirement': 45 'This column usually shows the "Requirement ID"'}) 49 46 self.info(str(Configuration())) 50 47 … … 57 54 return setattr(self.__instance, attr, value) 58 55 59 # def test_result(self, requirement, message): 60 # self.info(message, 61 # extra = {'requirement': requirement}) 62 def title(self, title): 63 logging.Logger.info(self, 64 title, 65 extra = {'requirement': '--------------------'}) 66 def ok(self, requirement): 67 logging.Logger.info(self, 68 'OK', 69 extra = {'requirement': requirement}) 70 def ko(self, requirement, cause): 71 logging.Logger.info(self, 72 'KO (%s)' % cause, 73 extra = {'requirement': requirement}) 56 def save(self, filename, prettyxml=True): 57 f = open(filename, "w") 58 if prettyxml: 59 f.write(self.toprettyxml()) 60 else: 61 f.write(self.toxml()) 62 f.close() 74 63 75 64 TestReport = TestReportClass() 76 65 77 if __name__ == '__main__': 66 if __name__ == '__main__': # pragma: no cover 78 67 import logging 79 68 import sys 80 69 current_argument_position = 1 81 70 while current_argument_position < len(sys.argv): 82 if sys.argv[current_argument_position] == '-debug': # pragma: no cover71 if sys.argv[current_argument_position] == '-debug': 83 72 PsPsLogger.setLevel(logging.DEBUG) 84 73 PsPsLogger.set_stderr() 85 current_argument_position += 1 86 elif sys.argv[current_argument_position] == 'test': 87 print 'Running unittest for TestReport class' 74 elif sys.argv[current_argument_position] == 'unittest': 88 75 import doctest 89 76 doctest.testmod() 90 77 sys.exit(0) 78 current_argument_position += 1 79 print(' Usage: %s [--debug] unittest' % sys.argv[0])
Note:
See TracChangeset
for help on using the changeset viewer.
