Exemple #1
0
def main():
    parser = ArgumentParser()
    parser.add_argument("dst_xunit_file")
    parser.add_argument("src_trace_log")

    args = parser.parse_args()

    destination = XunitDestination(
        os.path.dirname(os.path.abspath(args.dst_xunit_file)))
    xml_filepath = os.path.splitext(os.path.basename(args.dst_xunit_file))[0]
    with open(args.src_trace_log) as file:

        def parse_line(line_i, line):
            try:
                return parse_trace(line)
            except Exception as e:
                raise Exception('%s:%d: error: %r' %
                                (args.src_trace_log, i, e))

        test_results = gather_test_results(
            [parse_line(i, line) for i, line in enumerate(file.readlines())])

    destination.write_reports(xml_filepath, 'testsuite', test_results)
 def setUp(self):
     self.root_dir = mkdtemp()
     self.destination = XunitDestination(self.root_dir)
"""
Parses the `unit_test.log` created by the `run_unit_tests` rule in the
Makefile to determine whether the unit tests passed or failed and return an
appropriate exit code.
"""
import sys, subprocess, time, re, string
from datetime import datetime
from xunitgen import XunitDestination, EventReceiver, toxml

destination = XunitDestination('./test_results')
receiver = None
test_time = 0
TEST_CASE_REGEX = re.compile(r".*\|.* (\d+-\d+-\d+ \d+:\d+:\d+,\d+).*: ([a-zA-Z0-9_]+) \(([a-zA-Z0-9\._]+)\)")
TEST_END_REGEX = re.compile(r".*\|.* (\d+-\d+-\d+ \d+:\d+:\d+,\d+).* (.+): Ran (\d+) test(s)? in ([0-9\.]+)")
TEST_FAIL_REGEX = re.compile(r".*\|.* (\d+-\d+-\d+ \d+:\d+:\d+,\d+).*([a-zA-Z0-9_]+): FAIL")
failing_tests = []


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])