IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 15, 2010, 2:51:13 PM (16 years ago)
Author:
Serge CHASTEL
Message:

Test report now in xml

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/sc_branches/psps_testing/utilities/test_report.py

    r29235 r29438  
    22import datetime
    33from utilities.configuration import Configuration
     4from utilities.abstract_test_report import AbstractTestReport
    45
    5 class TestReportClass(logging.Logger):
    6     datefmt = '%H:%M:%S'
    7     fmt = '[%(asctime)8s] | %(requirement)65s | %(message)s'
    8     class __impl(logging.Logger):
     6class TestReportClass(AbstractTestReport):
     7    """
     8    An implementation of AbstractTestReport for PSPS testing test
     9    reports.
     10    """
     11    class __impl(AbstractTestReport):
    912        """ Implementation of the singleton interface """
    1013        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)
    1916        def id(self):
    2017            """ Test method, return singleton id """
     
    2320    __instance = None
    2421
    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)
    3027
    3128    def __init__(self):
     
    4441        # Store instance reference as the only member in the handle
    4542        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"'})
    4946        self.info(str(Configuration()))
    5047
     
    5754        return setattr(self.__instance, attr, value)
    5855
    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()
    7463
    7564TestReport = TestReportClass()
    7665
    77 if __name__ == '__main__':
     66if __name__ == '__main__': # pragma: no cover
    7867    import logging
    7968    import sys
    8069    current_argument_position = 1
    8170    while current_argument_position < len(sys.argv):
    82         if sys.argv[current_argument_position] == '-debug': # pragma: no cover
     71        if sys.argv[current_argument_position] == '-debug':
    8372            PsPsLogger.setLevel(logging.DEBUG)
    8473            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':
    8875            import doctest
    8976            doctest.testmod()
    9077            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.