Skip to content

Commit

Permalink
test: fix test runner for Python 3 on Windows
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
targos authored and MylesBorins committed Oct 23, 2019
1 parent 0299767 commit e110d81
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion test/testpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import os
import re
from functools import reduce
from io import open


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

def GetCommand(self):
result = [self.config.context.GetVm(self.arch, self.mode)]
source = open(self.file).read()
source = open(self.file, encoding='utf8').read()
flags_match = FLAGS_PATTERN.search(source)
if flags_match:
flags = flags_match.group(1).strip().split()
Expand Down
5 changes: 3 additions & 2 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import errno
import copy

from io import open
from os.path import join, dirname, abspath, basename, isdir, exists
from datetime import datetime
try:
Expand Down Expand Up @@ -733,8 +734,8 @@ def disableCoreFiles():
)
os.close(fd_out)
os.close(fd_err)
output = open(outname).read()
errors = open(errname).read()
output = open(outname, encoding='utf8').read()
errors = open(errname, encoding='utf8').read()
CheckedUnlink(outname)
CheckedUnlink(errname)

Expand Down

0 comments on commit e110d81

Please sign in to comment.