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: https://github.com/nodejs/node/pull/30023
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Christian Clauss <cclauss@me.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
pull/29996/head
Michaël Zasso 2019-10-18 11:56:21 +02:00
parent 425357a11c
commit a4e075f668
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
2 changed files with 5 additions and 3 deletions

View File

@ -29,6 +29,7 @@ import test
import os import os
import re import re
from functools import reduce from functools import reduce
from io import open
FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
@ -56,7 +57,7 @@ class SimpleTestCase(test.TestCase):
def GetCommand(self): def GetCommand(self):
result = [self.config.context.GetVm(self.arch, self.mode)] 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) flags_match = FLAGS_PATTERN.search(source)
if flags_match: if flags_match:
flags = flags_match.group(1).strip().split() flags = flags_match.group(1).strip().split()

View File

@ -45,6 +45,7 @@ import multiprocessing
import errno import errno
import copy import copy
from io import open
from os.path import join, dirname, abspath, basename, isdir, exists from os.path import join, dirname, abspath, basename, isdir, exists
from datetime import datetime from datetime import datetime
try: try:
@ -733,8 +734,8 @@ def Execute(args, context, timeout=None, env=None, disable_core_files=False, std
) )
os.close(fd_out) os.close(fd_out)
os.close(fd_err) os.close(fd_err)
output = open(outname).read() output = open(outname, encoding='utf8').read()
errors = open(errname).read() errors = open(errname, encoding='utf8').read()
CheckedUnlink(outname) CheckedUnlink(outname)
CheckedUnlink(errname) CheckedUnlink(errname)