Пример #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)
Пример #2
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)
class TestXunitDestination(TestCase):
    def setUp(self):
        self.root_dir = mkdtemp()
        self.destination = XunitDestination(self.root_dir)

    def tearDown(self):
        shutil.rmtree(self.root_dir)

    def test_reserve_file(self):
        path = self.destination.reserve_file('a-file')
        self.assertEquals(os.path.join(self.root_dir, 'a-file.xml'), path)
        assert not os.path.exists(path)

    def test_reserve_file_with_subdir(self):
        self.destination.reserve_file(os.path.join('a', 'b', 'c'))
        assert os.path.isdir(os.path.join(self.root_dir, 'a', 'b'))
        assert not os.path.exists(
            os.path.join(self.root_dir, 'a', 'b', 'c.xml'))

    def test_reserve_file_is_xml(self):
        path = self.destination.reserve_file(os.path.join('a', 'b', 'c'))
        assert path.endswith('xml')

    def test_a_reserved_file_duely_filled(self):
        path = self.destination.reserve_file('a-file')
        with open(path, 'w') as outf:
            outf.write('garbage')

        self.destination.check()

    def test_cannot_reserve_twice_the_same(self):
        self.destination.reserve_file('a-file')
        self.assertRaises(ValueError, self.destination.reserve_file, 'a-file')

    def test_cannot_reserve_existing(self):
        with open(os.path.join(self.root_dir, 'hello.xml'), 'w') as outf:
            outf.write('garbage')
        self.assertRaises(ValueError, self.destination.reserve_file, 'hello')

    def test_can_reserve_many(self):
        self.destination.reserve_file('a-file')
        self.destination.reserve_file('b-file')

    def test_write_reports(self):
        path = self.destination.write_reports(
            'hello', 'a-suite', [Report('a-case', start_ts=0, end_ts=0)])
        assert os.path.isfile(path)
        self.destination.check()
        self.assertRaises(ValueError, self.destination.reserve_file, 'hello')
 def setUp(self):
     self.root_dir = mkdtemp()
     self.destination = XunitDestination(self.root_dir)
 def setUp(self):
     self.root_dir = mkdtemp()
     self.destination = XunitDestination(self.root_dir)
class TestXunitDestination(TestCase):
    def setUp(self):
        self.root_dir = mkdtemp()
        self.destination = XunitDestination(self.root_dir)


    def tearDown(self):
        shutil.rmtree(self.root_dir)


    def test_reserve_file(self):
        path = self.destination.reserve_file('a-file')
        self.assertEquals(os.path.join(self.root_dir, 'a-file.xml'), path)
        assert not os.path.exists(path)


    def test_reserve_file_with_subdir(self):
        self.destination.reserve_file(os.path.join('a', 'b', 'c'))
        assert os.path.isdir(os.path.join(self.root_dir, 'a', 'b'))
        assert not os.path.exists(os.path.join(self.root_dir, 'a', 'b', 'c.xml'))


    def test_reserve_file_is_xml(self):
        path = self.destination.reserve_file(os.path.join('a', 'b', 'c'))
        assert path.endswith('xml')


    def test_a_reserved_file_duely_filled(self):
        path = self.destination.reserve_file('a-file')
        with open(path, 'w') as outf:
            outf.write('garbage')

        self.destination.check()


    def test_cannot_reserve_twice_the_same(self):
        self.destination.reserve_file('a-file')
        self.assertRaises(ValueError, self.destination.reserve_file, 'a-file')


    def test_cannot_reserve_existing(self):
        with open(os.path.join(self.root_dir, 'hello.xml'), 'w') as outf:
            outf.write('garbage')
        self.assertRaises(ValueError, self.destination.reserve_file, 'hello')


    def test_can_reserve_many(self):
        self.destination.reserve_file('a-file')
        self.destination.reserve_file('b-file')


    def test_write_reports(self):
        path = self.destination.write_reports('hello', 'a-suite', [Report('a-case', start_ts=0, end_ts=0)])
        assert os.path.isfile(path)
        self.destination.check()
        self.assertRaises(ValueError, self.destination.reserve_file, 'hello')
"""
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])