Example #1
0
    def test_failure_event(self):
        receiver = EventReceiver()
        receiver.begin_case('a-test', 0, 'foo')
        receiver.failure('because', 4)
        receiver.end_case('a-test', 9)

        self.assertEquals(1, len(receiver.results()[0].failures))
Example #2
0
def gather_test_results(traces):
    MICROS_TO_S = 1000000.0
    receiver = EventReceiver()

    for trace in traces:
        ts_seconds = trace['ts'] / MICROS_TO_S
        if trace['cat'] == 'test':
            if trace['ph'] == 'E' and receiver.current_case.name == trace[
                    'name']:
                receiver.end_case(trace['name'], ts_seconds)
            elif trace['ph'] == 'B' and receiver.current_case is None:
                receiver.begin_case(
                    trace['name'], ts_seconds,
                    os.path.splitext(trace['args']['filename'])[0].replace(
                        os.sep, '.'))
            elif trace['ph'] == 'I' and trace['name'] == 'failure':
                receiver.failure(trace['args']['reason'],
                                 trace['args']['lineno'])

    return receiver.results()
Example #3
0
    def test_dangling_case(self):
        receiver = EventReceiver()
        receiver.begin_case('a-test', 0, src_location='foo')

        self.assertEquals(1, len(receiver.results()[0].errors))
Example #4
0
 def test_trivial(self):
     self.assertEquals([], EventReceiver().results())
def get_timestamp(date_string):
    """
    Get the seconds since unix epoch from the date_string

    :param date_string: Date in %Y-%m-%d %H:%M:%S,%f format from the log
    """
    return float(datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S,%f').strftime('%S'))


with open('unit_test.log', 'rb') as log_file:
    for line in log_file:
        all_bytes = string.maketrans('', '')
        line = line.translate(all_bytes, all_bytes[:32])
        if 'running tests' in line:
            receiver = EventReceiver()
        if 'test_' in line and '(openerp.addons.' in line:
            line_match = TEST_CASE_REGEX.match(line).groups()
            test_time = get_timestamp(line_match[0])
            test_name = line_match[1].replace('openerp.addons.', '')
            test_location = line_match[2].replace('openerp.addons.', '')
            if receiver.current_case:
                receiver.end_case(receiver.current_case.name, test_time)
            receiver.begin_case(test_name, test_time, test_location)
        if ': Ran ' in line and 'test' in line and ' in ' in line:
            print line
            line_match = TEST_END_REGEX.match(line).groups()
            if receiver.current_case:
                test_time = get_timestamp(line_match[0])
                receiver.end_case(receiver.current_case.name, test_time)
            test_name = line_match[1]