1- import re
2- from junit_xml import TestSuite , TestCase
3- import itertools
41import os
52import argparse
6- import os
3+ from converter import create_junit_test_file , write_junit_file
74
85parser = argparse .ArgumentParser (description = 'Test File' )
96parser .add_argument ('test_suite_name' , type = str , help = 'Class of tests to parse' )
107args = parser .parse_args ()
8+ OUTPUT_FILE = 'output.xml'
119TESTS_FILE = os .environ ['TEST_RESULTS' ]
1210
13- tests = []
14-
15- def file_log_parser (file :str ) -> dict :
16- with open (file ) as file_log :
17- config = file_log .read ()
18- test_logs_results = {}
19- index = ""
20- for line in config .split ("\n " ):
21- if "++++Starting test" in line :
22- index = line .split (" " )[- 1 ][:- 4 ]
23- test_logs_results [index ] = ""
24- elif "++++TEST" in line :
25- index = ""
26- elif index :
27- test_logs_results [index ] += line + "\n "
28- return test_logs_results
29-
30- # For each test we generate a testCase parsing the output file
31- for file in TESTS_FILE .split ("\n " ):
32- file_log = "test_log_" + "_" .join (file .split ("_" )[2 :])
33- test = file_log_parser (file_log )
34- with open (file ) as file_buffer : # Use file to refer to the file object
35- config = file_buffer .read ()
36- current_section = {}
37- lines = config .split ()
38- date = lines [1 ]
39- is_relaunch = lines [2 ]
40- debug = lines [3 ]
41- for _ ,test_name ,status ,_ ,_ ,duration in zip (* [iter (lines [6 :])]* 6 ):
42- if duration == "false" :
43- continue
44- else :
45- duration = duration [:- 1 ]
46- if test_name in test :
47- tc = TestCase (name = test_name , elapsed_sec = int (duration ),status = status , stdout = test [test_name ])
48- else :
49- tc = TestCase (name = test_name , elapsed_sec = int (duration ),status = status )
50- tests .append (tc )
51-
52- # We create a TestSUite and we write them in a XML File
53- t = TestSuite (name = args .test_suite_name ,test_cases = tests )
54- with open ('output.xml' , 'w' ) as f :
55- TestSuite .to_file (f , [t ], prettyprint = False )
11+ if __name__ == "__main__" :
12+ tests = create_junit_test_file (TESTS_FILE )
13+ write_junit_file (OUTPUT_FILE ,tests ,args .test_suite_name )
0 commit comments