Skip to content

Commit 2ebd1a0

Browse files
committed
test: fix test runner for Python 3 on Windows
Explicitly open files with utf8 encoding, otherwise the system could use another encoding such as latin1 by default. PR-URL: #30023 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Christian Clauss <cclauss@me.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 8df5bdb commit 2ebd1a0

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

‎test/testpy/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
importos
3030
importre
3131
fromfunctoolsimportreduce
32+
fromioimportopen
3233

3334

3435
FLAGS_PATTERN=re.compile(r"//\s+Flags:(.*)")
@@ -56,7 +57,7 @@ def GetName(self):
5657

5758
defGetCommand(self):
5859
result= [self.config.context.GetVm(self.arch, self.mode)]
59-
source=open(self.file).read()
60+
source=open(self.file, encoding='utf8').read()
6061
flags_match=FLAGS_PATTERN.search(source)
6162
ifflags_match:
6263
flags=flags_match.group(1).strip().split()

‎tools/test.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
importerrno
4646
importcopy
4747

48+
fromioimportopen
4849
fromos.pathimportjoin, dirname, abspath, basename, isdir, exists
4950
fromdatetimeimportdatetime
5051
try:
@@ -728,8 +729,8 @@ def disableCoreFiles():
728729
)
729730
os.close(fd_out)
730731
os.close(fd_err)
731-
output=open(outname).read()
732-
errors=open(errname).read()
732+
output=open(outname, encoding='utf8').read()
733+
errors=open(errname, encoding='utf8').read()
733734
CheckedUnlink(outname)
734735
CheckedUnlink(errname)
735736

0 commit comments

Comments
 (0)