5
5
# Requirement of python 3.4 to execute this script and required result log file(s)
6
6
# are in the same location
7
7
# Run with command line without options required. Example: py output.py
8
- # This script parse output of PHP Native Test
8
+ # This script parse output of PHP Test logs
9
9
#
10
10
#############################################################################################
11
11
12
12
import os
13
13
import stat
14
14
import re
15
+ import argparse
15
16
16
17
# This module appends an entry to the tests list, may include the test title.
17
18
# Input: search_pattern - pattern to look for in the line of the log file
@@ -46,12 +47,14 @@ def get_test_entry(search_pattern, line, index, tests_list, get_title = False):
46
47
tests_list .append (entry )
47
48
48
49
# Extract individual test results from the log file and
49
- # enter it in the nativeresult.xml file.
50
- # Input: logfile - the log file
51
- # number - the number for this xml file
52
- def gen_XML (logfile , number ):
50
+ # enter it in the xml report file.
51
+ # Input: logfile - the test log file
52
+ # number - the number for this xml file (applicable if using the default report name)
53
+ # logfilename - use the log file name for the xml output file Instead
54
+ def gen_XML (logfile , number , logfilename ):
53
55
print ('================================================' )
54
- print ("\n " + os .path .splitext (logfile )[0 ] + "\n " )
56
+ filename = os .path .splitext (logfile )[0 ]
57
+ print ("\n " + filename + "\n " )
55
58
56
59
tests_list = []
57
60
with open (os .path .dirname (os .path .realpath (__file__ )) + os .sep + logfile ) as f :
@@ -70,8 +73,12 @@ def gen_XML(logfile, number):
70
73
print (line )
71
74
print ('================================================' )
72
75
73
- # Generating the nativeresult.xml file.
74
- file = open ('nativeresult' + str (number ) + '.xml' , 'w' )
76
+ # Generating the xml report.
77
+ if logfilename is True :
78
+ file = open (filename + '.xml' , 'w' )
79
+ else :
80
+ file = open ('nativeresult' + str (number ) + '.xml' , 'w' )
81
+
75
82
file .write ('<?xml version="1.0" encoding="UTF-8" ?>' + os .linesep )
76
83
file .write ('<testsuite tests="' + str (num - 1 ) + '" failures="' + str (failnum ) + '" name="Native Tests" >' + os .linesep )
77
84
@@ -83,12 +90,18 @@ def gen_XML(logfile, number):
83
90
84
91
# ----------------------- Main Function -----------------------
85
92
86
- # Display results on screen from result log file .
93
+ # Generate XML reports from test result log files .
87
94
if __name__ == '__main__' :
95
+ parser = argparse .ArgumentParser ()
96
+ parser .add_argument ('--LOGFILENAME' , action = 'store_true' , help = "Generate XML files using log file names (default: False)" )
97
+
98
+ args = parser .parse_args ()
99
+ logfilename = args .LOGFILENAME
100
+
88
101
num = 1
89
102
for f in os .listdir (os .path .dirname (os .path .realpath (__file__ ))):
90
103
if f .endswith ("log" ):
91
104
logfile = f
92
- gen_XML (logfile , num )
105
+ gen_XML (logfile , num , logfilename )
93
106
num = num + 1
94
107
0 commit comments