validate: Properly use errors = 'replace'
for handling invalid utf8 characters
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7453>
This commit is contained in:
parent
63dc54906b
commit
ec11c337c3
@ -282,11 +282,8 @@ class Test(Loggable):
|
|||||||
self.out = None
|
self.out = None
|
||||||
|
|
||||||
def _get_file_content(self, file_name):
|
def _get_file_content(self, file_name):
|
||||||
f = open(file_name, 'r+')
|
with open(file_name, 'r', encoding='utf-8', errors='replace') as f:
|
||||||
value = f.read()
|
return f.read()
|
||||||
f.close()
|
|
||||||
|
|
||||||
return value
|
|
||||||
|
|
||||||
def get_log_content(self):
|
def get_log_content(self):
|
||||||
return self._get_file_content(self.logfile)
|
return self._get_file_content(self.logfile)
|
||||||
|
@ -180,7 +180,7 @@ class XunitReporter(Reporter):
|
|||||||
"""
|
"""
|
||||||
self.debug("Writing XML file to: %s", self.options.xunit_file)
|
self.debug("Writing XML file to: %s", self.options.xunit_file)
|
||||||
xml_file = codecs.open(self.options.xunit_file, 'w',
|
xml_file = codecs.open(self.options.xunit_file, 'w',
|
||||||
self.encoding, 'replace')
|
self.encoding, errors = 'replace')
|
||||||
|
|
||||||
self.stats['encoding'] = self.encoding
|
self.stats['encoding'] = self.encoding
|
||||||
self.stats['total'] = (self.stats['timeout'] + self.stats['failures']
|
self.stats['total'] = (self.stats['timeout'] + self.stats['failures']
|
||||||
@ -192,7 +192,7 @@ class XunitReporter(Reporter):
|
|||||||
'skipped="%(skipped)d">' % self.stats)
|
'skipped="%(skipped)d">' % self.stats)
|
||||||
|
|
||||||
tmp_xml_file = codecs.open(self.tmp_xml_file.name, 'r',
|
tmp_xml_file = codecs.open(self.tmp_xml_file.name, 'r',
|
||||||
self.encoding, 'replace')
|
self.encoding, errors = 'replace')
|
||||||
|
|
||||||
for l in tmp_xml_file:
|
for l in tmp_xml_file:
|
||||||
xml_file.write(l)
|
xml_file.write(l)
|
||||||
@ -214,7 +214,7 @@ class XunitReporter(Reporter):
|
|||||||
super().set_failed(test)
|
super().set_failed(test)
|
||||||
|
|
||||||
xml_file = codecs.open(self.tmp_xml_file.name, 'a',
|
xml_file = codecs.open(self.tmp_xml_file.name, 'a',
|
||||||
self.encoding, 'replace')
|
self.encoding, errors = 'replace')
|
||||||
xml_file.write(self._forceUnicode(
|
xml_file.write(self._forceUnicode(
|
||||||
'<testcase name=%(name)s time="%(taken).3f">%(systemout)s'
|
'<testcase name=%(name)s time="%(taken).3f">%(systemout)s'
|
||||||
'<failure type=%(errtype)s message=%(message)s>'
|
'<failure type=%(errtype)s message=%(message)s>'
|
||||||
@ -233,7 +233,7 @@ class XunitReporter(Reporter):
|
|||||||
self.stats['passed'] += 1
|
self.stats['passed'] += 1
|
||||||
|
|
||||||
xml_file = codecs.open(self.tmp_xml_file.name, 'a',
|
xml_file = codecs.open(self.tmp_xml_file.name, 'a',
|
||||||
self.encoding, 'replace')
|
self.encoding, errors = 'replace')
|
||||||
xml_file.write(self._forceUnicode(
|
xml_file.write(self._forceUnicode(
|
||||||
'<testcase name=%(name)s '
|
'<testcase name=%(name)s '
|
||||||
'time="%(taken).3f">%(systemout)s</testcase>' %
|
'time="%(taken).3f">%(systemout)s</testcase>' %
|
||||||
@ -246,5 +246,5 @@ class XunitReporter(Reporter):
|
|||||||
def _forceUnicode(self, s):
|
def _forceUnicode(self, s):
|
||||||
if not UNICODE_STRINGS:
|
if not UNICODE_STRINGS:
|
||||||
if isinstance(s, str):
|
if isinstance(s, str):
|
||||||
s = s.decode(self.encoding, 'replace')
|
s = s.decode(self.encoding, errors = 'replace')
|
||||||
return s
|
return s
|
||||||
|
Loading…
x
Reference in New Issue
Block a user