Skip to content

Commit 276934d

Browse files
committed
Updates from testing
1 parent d296eb8 commit 276934d

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

generate_pclp_reports.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def generate_source():
280280
if os.path.isfile(fname + ".vcast.bak"):
281281
fname = fname + ".vcast.bak"
282282

283-
with open(fname, 'rb') as fh:
283+
with open(fname, "rb") as fh:
284284
# read and replace the line ending for consistency
285285
contents = fh.read().encode(encFmnt, "replace")
286286
contents = contents.replace("\r\n", "\n").replace("\r","\n")
@@ -487,7 +487,7 @@ def emit_gitlab(msgs):
487487
# Driver
488488

489489
def write_output(output, filename):
490-
with open(filename, 'wb') as file:
490+
with open(filename, "wb") as file:
491491
file.write(output.encode(encFmt, "replace"))
492492

493493
def generate_reports(input_xml, output_text = None, output_html = None, output_json = None, output_gitlab = None, full_mp_name = None):

generate_results.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
pass
4949
from vector.enums import ENVIRONMENT_STATUS_TYPE_T
5050

51+
from vcast_utils import dump, getVectorCASTEncoding
52+
53+
encFmt = getVectorCASTEncoding()
54+
5155
#global variables
5256
global verbose
5357
global print_exc
@@ -114,14 +118,39 @@ def readManageVersion(ManageFile):
114118
version = 14
115119
if os.path.isfile(ManageFile + ".vcm"):
116120
ManageFile = ManageFile + '.vcm'
117-
with open(ManageFile, 'r') as projFile:
118-
for line in projFile:
119-
if 'version' in line and 'project' in line:
120-
version = int(re.findall(r'\d+', line)[0])
121-
break
121+
122+
py2 = sys.version_info[0] < 3
123+
124+
with open(ManageFile, "rb") as projFile:
125+
for raw_line in projFile:
126+
# --- Normalize line to text (unicode in Py3, unicode or str in Py2) ---
127+
if py2:
128+
# In Py2, raw_line is a str (byte string)
129+
try:
130+
line = raw_line.decode(encFmt, "replace")
131+
except Exception:
132+
line = raw_line.decode("utf-8", "replace")
133+
else:
134+
# In Py3, raw_line is bytes
135+
if isinstance(raw_line, bytes):
136+
try:
137+
line = raw_line.decode(encFmt, "replace")
138+
except Exception:
139+
line = raw_line.decode("utf-8", "replace")
140+
else:
141+
line = raw_line
142+
143+
# --- Look for version/project keywords ---
144+
if "version" in line and "project" in line:
145+
match = re.search(r"\d+", line)
146+
if match:
147+
version = int(match.group())
148+
break
149+
122150
if verbose:
123151
print("Version of Manage project file = %d" % version)
124152
print("(Levels change in version 17 (*maybe) and above)")
153+
125154
return version
126155

127156
# Call manage to get the mapping of Envs to Directory etc.
@@ -324,9 +353,8 @@ def useNewAPI(FullManageProjectName, manageEnvs, level, envName, use_ci, xml_dat
324353
passed_count += pc
325354
generateIndividualReports(manageEnvs[currentEnv], envName)
326355

327-
f = open("unit_test_fail_count.txt","w")
328-
f.write(str(failed_count))
329-
f.close()
356+
with open("unit_test_fail_count.txt","wb") as fd:
357+
f.write(str(failed_count).encode(encFmt,'replace'))
330358

331359
return failed_count, passed_count
332360

generate_xml.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ def __init__(self, FullManageProjectName, build_dir, env, compiler, testsuite, c
502502
self.passed_count = 0
503503
self.useStartLine = False
504504
self.noResults = False
505+
self.report_failed_only = False
505506

506507
if os.path.exists(cov_path) and os.path.exists(cov_path[:-4]):
507508
self.using_cover = True
@@ -650,7 +651,7 @@ def start_system_test_file(self):
650651
if self.verbose:
651652
print(" Writing testcase xml file: {}".format(self.unit_report_name))
652653

653-
self.fh = open(self.unit_report_name, "w")
654+
self.fh = open(self.unit_report_name, "wb")
654655
errors = 0
655656
failed = 0
656657
success = 0
@@ -670,7 +671,7 @@ def start_system_test_file(self):
670671
self.failed_count += 1
671672
api.close()
672673

673-
data = "<?xml version=\"1.0\" encoding=\{}\"?>\n".format(self.encFtm)
674+
data = "<?xml version=\"1.0\" encoding=\{}\"?>\n".format(self.encFmt)
674675
data += "<testsuites>\n"
675676
data += " <testsuite errors=\"{}\" tests=\"{}\" failures=\"{}\" name=\"{}\" id=\"1\">\n".format(errors, success+failed+errors, failed, escape(self.env, quote=False))
676677

@@ -680,7 +681,7 @@ def start_unit_test_file(self):
680681
if self.verbose:
681682
print(" Writing testcase xml file: {}".format(self.unit_report_name))
682683

683-
self.fh = open(self.unit_report_name, "w")
684+
self.fh = open(self.unit_report_name, "wb")
684685
errors = 0
685686
failed = 0
686687
success = 0

0 commit comments

Comments
 (0)