From e110d81b17756f6f06ad41bfc026e3ece9f839d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Fri, 18 Oct 2019 11:56:21 +0200 Subject: [PATCH] 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 Reviewed-By: Christian Clauss Reviewed-By: Luigi Pinca --- test/testpy/__init__.py | 3 ++- tools/test.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/testpy/__init__.py b/test/testpy/__init__.py index 9c70e18d6a1291..c89ab6e8b576f4 100644 --- a/test/testpy/__init__.py +++ b/test/testpy/__init__.py @@ -29,6 +29,7 @@ import os import re from functools import reduce +from io import open FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") @@ -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() diff --git a/tools/test.py b/tools/test.py index 878e2bef35da46..04babded24b590 100755 --- a/tools/test.py +++ b/tools/test.py @@ -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: @@ -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)