summaryrefslogtreecommitdiffstats
path: root/tests/expat/parser.py
blob: fbac060f2349c771272475cd31fe9442f2418396 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#
# this is a parser function specially designed for the 'expat.log'
#
import re

def log_parse(log_file):
    # define prefix as a global var
    # but we set default to "runtests_"
    prefix = "runtests_"

    # there is one repeat test, which is named 'test_return_ns_triplet'
    # we figured out the cause, the second time it showed up was for it
    # was triggered by test 'test_ns_parser_reset', so the suffix goes like:
    suffix = "_triggered_by_test_ns_parser_reset"

    # set up rule for regex
    reObj = re.compile('^(FAIL|PASS|SKIP+?): (test+?.+)', re.MULTILINE)

    # init a dictionary, it stores the return result
    case_list = dict()

    # open file
    test_log = open(log_file, 'r')

    # start to read the new line
    line = test_log.readline()

    while line:
        if ("runtestspp" in line):
            # if detected runtestspp in line, set prefix to ---> runtestspp_
            prefix = "runtestspp_"

        # checking regex status in line
        matchs = reObj.search(line)

        # if the line fits the regex rule
        if matchs:
            # spliting elements into a tuple
            # it looks like ('PASS', '<CASE NAME>')
            groups = matchs.groups()

            # rename the case, add a prefix
            case_name = prefix + groups[1]

            # if the case is not stored in the result dictionary
            if case_name not in case_list:
                    # then just add a new key naming after case_name, along with its values
                    case_list[case_name] = [case_name, groups[0], ""]

            # if the test case has already been in the result list
            else:
                # add a suffix for the repeat test case name
                case_name = prefix + groups[1] + suffix
                # add it to the result dictionary
                case_list[case_name] = [case_name, groups[0], ""]

        # jump out if-else, read next line
        line = test_log.readline()

    test_log.close()

    return case_list