Skip to content

Commit a4e075f

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 <[email protected]> Reviewed-By: Christian Clauss <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 425357a commit a4e075f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

test/testpy/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import os
3030
import re
3131
from functools import reduce
32+
from io import open
3233

3334

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

5758
def GetCommand(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
if flags_match:
6263
flags = flags_match.group(1).strip().split()

tools/test.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import errno
4646
import copy
4747

48+
from io import open
4849
from os.path import join, dirname, abspath, basename, isdir, exists
4950
from datetime import datetime
5051
try:
@@ -733,8 +734,8 @@ def disableCoreFiles():
733734
)
734735
os.close(fd_out)
735736
os.close(fd_err)
736-
output = open(outname).read()
737-
errors = open(errname).read()
737+
output = open(outname, encoding='utf8').read()
738+
errors = open(errname, encoding='utf8').read()
738739
CheckedUnlink(outname)
739740
CheckedUnlink(errname)
740741

0 commit comments

Comments
 (0)