GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — tools: tolerate non-UTF-8 test output · nodejs/node@7f9f5d5

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/tools
    • test_testrunner_output.py
  • tools
    • test.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/tools/test_testrunner_output.py‎

Copy file name to clipboard
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright Node.js contributors. All rights reserved.
2+
# Use of this source code is governed by an MIT-style license that can be
3+
# found in the LICENSE file.
4+
5+
import os
6+
import sys
7+
import tempfile
8+
from types import SimpleNamespace
9+
import unittest
10+
from unittest.mock import patch
11+
12+
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
13+
sys.path.insert(0, os.path.join(ROOT, 'tools'))
14+
import test as runner
15+
16+
17+
class TestRunnerOutputTest(unittest.TestCase):
18+
def test_invalid_utf8(self):
19+
context = SimpleNamespace(verbose=False, suppress_dialogs=False,
20+
abort_on_timeout=False)
21+
with tempfile.TemporaryDirectory() as directory:
22+
with patch.object(runner.tempfile, 'tempdir', directory):
23+
for stream, fd in [('stdout', 1), ('stderr', 2)]:
24+
for exit_code in [0, 3]:
25+
with self.subTest(stream=stream, exit_code=exit_code):
26+
script = (f"import os; os.write({fd}, b'valid \\xc3\\xa9\\ninvalid \\xff\\r\\n'); "
27+
f"raise SystemExit({exit_code})")
28+
result = runner.Execute([sys.executable, '-c', script], context, timeout=10)
29+
self.assertEqual(getattr(result, stream), 'valid é\ninvalid \ufffd\n')
30+
self.assertEqual(result.exit_code, exit_code)
31+
self.assertFalse(result.timed_out)
32+
self.assertEqual(os.listdir(directory), [])
33+
34+
35+
if __name__ == '__main__':
36+
unittest.main()
Collapse file

‎tools/test.py‎

Copy file name to clipboardExpand all lines: tools/test.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,10 @@ def setResourceLimits():
836836
)
837837
os.close(fd_out)
838838
os.close(fd_err)
839-
output = open(outname, encoding='utf8').read()
840-
errors = open(errname, encoding='utf8').read()
839+
with open(outname, encoding='utf8', errors='replace') as output_file:
840+
output = output_file.read()
841+
with open(errname, encoding='utf8', errors='replace') as error_file:
842+
errors = error_file.read()
841843
CheckedUnlink(outname)
842844
CheckedUnlink(errname)
843845

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.