aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/agl_test_log.py
blob: e064047c37aa6955505ebdc4be8fc7554c825427 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import pytest
import re

'''
Process the log and init test_cases_values_and_status.

log : the path of default log

default log formate :
    -> case_name: TEST-PASS
    -> case_name: TEST-FAIL
    -> case_name: TEST-SKIP
'''
def log_process_default(log):
    pattern = '^ -> (.+?): (.+?)$'
    parse_result = log_parse(log, pattern)
    test_cases_values_and_status = [["test_id","values","status"]]

    if parse_result:
        for item in parse_result:
            item_result = [item[0], item[1], ""]
            test_cases_values_and_status.append(item_result)

    return test_cases_values_and_status

'''
Process the log and init test_cases_values_and_status.

log : the path of default log

default log formate :
    -> case_name: TEST-PASS
    -> case_name: TEST-FAIL
    -> case_name: TEST-SKIP
'''
def log_process(log):
    pattern = '^ -> (.+?): (.+?)$'
    parse_result = log_parse(log, pattern)
    case_list = dict()
    if parse_result:
        for item in parse_result:
            case_list[item[0]] = [item[0], item[1], ""]
    return case_list

'''
Process the log create by gnome_desktop_testing
and init test_cases_values_and_status.

log : the path of gnome_desktop_testing log

gnome_desktop_testing log formate:
    PASS: glib/tls-database.test
    FAIL: glib/markup-escape.test
    SKIP: glib/testname.test
'''
def log_process_gnome_desktop_testing(log):
    pattern = '^(FAIL|PASS|SKIP.+?): (.+test?)'
    parse_result = log_parse(log, pattern)
    test_cases_values_and_status = [["test_id","values","status"]]

    if parse_result:
        for item in parse_result:
            item_result = [item[1], item[0], ""]
            test_cases_values_and_status.append(item_result)

    return test_cases_values_and_status

# parse log file with pattern
def log_parse(log, pattern):
    regex = re.compile(pattern, re.MULTILINE)

    test_log = open(log, 'r')

    parse_result = []
    line = test_log.readline()
    while line:
        matchs = regex.search(line)
        if matchs:
            groups = matchs.groups()
            parse_result.append(groups)
        line=test_log.readline()
    test_log.close()
    return parse_result