55except ImportError :
66 # html not standard module in Python 2.
77 from cgi import escape
8- import sys , subprocess , os
8+ import sys , subprocess , os
9+ from vcast_utils import dump , getVectorCASTEncoding
10+
911global saved_compiler , saved_testsuite , saved_envname
1012
1113saved_compiler = ""
@@ -18,32 +20,30 @@ def get_timestamp():
1820 if hour > 12 :
1921 hour -= 12
2022 return dt .strftime ('%d %b %Y @HR@:%M:%S %p' ).upper ().replace ('@HR@' , str (hour ))
21-
23+
2224def writeJunitHeader (currentEnv , junitfile , failed , total , unit_report_name , encoding = 'UTF-8' ):
23-
24- junitfile .write ("<?xml version=\" 1.0\" encoding=\" " + encoding .upper () + "\" ?>\n " )
25+
26+ data = "<?xml version=\" 1.0\" encoding=\" {}\" ?>\n " .format (encoding )
27+ data += "<testsuites>\n <!-- {} -->\n " .format (unit_report_name )
28+ data += " <testsuite errors=\" {}\" tests=\" {}\" failures=\" {}\" name=\" {}\" id=\" 1\" >\n " .format (0 , total , failed , currentEnv )
2529
26- junitfile .write ("<testsuites>\n <!--" + unit_report_name + "-->\n " )
27-
28- junitfile .write (" <testsuite errors=\" %d\" tests=\" %d\" failures=\" %d\" name=\" %s\" id=\" 1\" >\n " %
29- (0 , total , failed , currentEnv ))
30+ junitfile .write (data .encode (encoding , "replace" ))
3031
31- def writeJunitData (junitfile ,all_tc_data ):
32- junitfile .write (all_tc_data )
32+ def writeJunitData (junitfile ,all_tc_data , encoding ):
33+ junitfile .write (all_tc_data . encode ( encoding , "replace" ) )
3334
34- def writeJunitFooter (junitfile ):
35- junitfile .write (" </testsuite>\n " )
36- junitfile .write ("</testsuites>\n " )
35+ def writeJunitFooter (junitfile , encoding ):
36+ junitfile .write (" </testsuite>\n " . encode ( encoding , "replace" ) )
37+ junitfile .write ("</testsuites>\n " . encode ( encoding , "replace" ) )
3738
3839def write_tc_data (currentEnv , unit_report_name , jobNameDotted , passed , failed , error , testcase_data , encoding = 'utf-8' , xml_data_dir = "xml_data" ):
3940
40- fh = open (os .path .join (xml_data_dir ,unit_report_name ), "w" )
41-
42- writeJunitHeader (currentEnv , fh , failed , failed + passed , unit_report_name , encoding )
43- writeJunitData (fh , testcase_data )
44- writeJunitFooter (fh )
45- fh .close ()
46-
41+ with open (os .path .join (xml_data_dir ,unit_report_name ), "wb" ) as fh :
42+ encoding = getVectorCASTEncoding ()
43+ writeJunitHeader (currentEnv , fh , failed , failed + passed , unit_report_name , encoding )
44+ writeJunitData (fh , testcase_data , encoding )
45+ writeJunitFooter (fh , encoding )
46+
4747def generateJunitTestCase (jobname , tc_name , passFail ):
4848 testCasePassString = " <testcase name=\" %s\" classname=\" %s\" time=\" 0\" />\n "
4949 testCaseFailString = """ <testcase name="%s" classname="%s" time="0">
0 commit comments