gh-91904: Fix setting envvar PYTHONREGRTEST_UNICODE_GUARD (GH-91905)

It always failed on non-UTF-8 locale and prevented running regrtests.
This commit is contained in:
Serhiy Storchaka 2022-04-25 17:35:14 +03:00 committed by GitHub
parent 93d280141c
commit 54d068adfb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

View file

@ -5,6 +5,7 @@ import signal
import sys import sys
import unittest import unittest
from test import support from test import support
from test.support.os_helper import TESTFN_UNDECODABLE, FS_NONASCII
try: try:
import gc import gc
except ImportError: except ImportError:
@ -104,10 +105,10 @@ def setup_tests(ns):
# Ensure there's a non-ASCII character in env vars at all times to force # Ensure there's a non-ASCII character in env vars at all times to force
# tests consider this case. See BPO-44647 for details. # tests consider this case. See BPO-44647 for details.
os.environ.setdefault( if TESTFN_UNDECODABLE and os.supports_bytes_environ:
UNICODE_GUARD_ENV, os.environb.setdefault(UNICODE_GUARD_ENV.encode(), TESTFN_UNDECODABLE)
"\N{SMILING FACE WITH SUNGLASSES}", elif FS_NONASCII:
) os.environ.setdefault(UNICODE_GUARD_ENV, FS_NONASCII)
def replace_stdout(): def replace_stdout():

View file

@ -1339,7 +1339,7 @@ class ArgsTestCase(BaseTestCase):
def test_unicode_guard_env(self): def test_unicode_guard_env(self):
guard = os.environ.get(setup.UNICODE_GUARD_ENV) guard = os.environ.get(setup.UNICODE_GUARD_ENV)
self.assertIsNotNone(guard, f"{setup.UNICODE_GUARD_ENV} not set") self.assertIsNotNone(guard, f"{setup.UNICODE_GUARD_ENV} not set")
if guard != "\N{SMILING FACE WITH SUNGLASSES}": if guard.isascii():
# Skip to signify that the env var value was changed by the user; # Skip to signify that the env var value was changed by the user;
# possibly to something ASCII to work around Unicode issues. # possibly to something ASCII to work around Unicode issues.
self.skipTest("Modified guard") self.skipTest("Modified guard")

View file

@ -0,0 +1,2 @@
Fix initialization of :envvar:`PYTHONREGRTEST_UNICODE_GUARD` which prevented
running regression tests on non-UTF-8 locale.