Skip to content

Commit

Permalink
gh-109237: Fix test_site for non-ASCII working directory (#109238)
Browse files Browse the repository at this point in the history
Fix test_site.test_underpth_basic() when the working directory
contains at least one non-ASCII character: encode the "._pth" file to
UTF-8 and enable the UTF-8 Mode to use UTF-8 for the child process
stdout.
  • Loading branch information
vstinner committed Sep 10, 2023
1 parent d6892c2 commit cbb3a6f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Lib/test/test_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def _create_underpth_exe(self, lines, exe_pth=True):
_pth_file = os.path.splitext(exe_file)[0] + '._pth'
else:
_pth_file = os.path.splitext(dll_file)[0] + '._pth'
with open(_pth_file, 'w') as f:
with open(_pth_file, 'w', encoding='utf8') as f:
for line in lines:
print(line, file=f)
return exe_file
Expand Down Expand Up @@ -613,7 +613,7 @@ def test_underpth_basic(self):
os.path.dirname(exe_file),
pth_lines)

output = subprocess.check_output([exe_file, '-c',
output = subprocess.check_output([exe_file, '-X', 'utf8', '-c',
'import sys; print("\\n".join(sys.path) if sys.flags.no_site else "")'
], encoding='utf-8', errors='surrogateescape')
actual_sys_path = output.rstrip().split('\n')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix ``test_site.test_underpth_basic()`` when the working directory contains
at least one non-ASCII character: encode the ``._pth`` file to UTF-8 and
enable the UTF-8 Mode to use UTF-8 for the child process stdout. Patch by
Victor Stinner.

0 comments on commit cbb3a6f

Please sign in to comment.