mirror of https://github.com/python/cpython
bpo-46587: Skip tests if strftime does not support glibc extension (GH-31873)
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
d8066b420b
commit
2cf7f865f0
|
@ -1676,7 +1676,8 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
|
||||||
# Year 42 returns '42', not padded
|
# Year 42 returns '42', not padded
|
||||||
self.assertEqual(d.strftime("%Y"), '%d' % y)
|
self.assertEqual(d.strftime("%Y"), '%d' % y)
|
||||||
# '0042' is obtained anyway
|
# '0042' is obtained anyway
|
||||||
self.assertEqual(d.strftime("%4Y"), '%04d' % y)
|
if support.has_strftime_extensions:
|
||||||
|
self.assertEqual(d.strftime("%4Y"), '%04d' % y)
|
||||||
|
|
||||||
def test_replace(self):
|
def test_replace(self):
|
||||||
cls = self.theclass
|
cls = self.theclass
|
||||||
|
|
|
@ -520,6 +520,11 @@ def requires_subprocess():
|
||||||
"""Used for subprocess, os.spawn calls, fd inheritance"""
|
"""Used for subprocess, os.spawn calls, fd inheritance"""
|
||||||
return unittest.skipUnless(has_subprocess_support, "requires subprocess support")
|
return unittest.skipUnless(has_subprocess_support, "requires subprocess support")
|
||||||
|
|
||||||
|
# Does strftime() support glibc extension like '%4Y'?
|
||||||
|
try:
|
||||||
|
has_strftime_extensions = time.strftime("%4Y") != "%4Y"
|
||||||
|
except ValueError:
|
||||||
|
has_strftime_extensions = False
|
||||||
|
|
||||||
# Define the URL of a dedicated HTTP server for the network tests.
|
# Define the URL of a dedicated HTTP server for the network tests.
|
||||||
# The URL must use clear-text HTTP: no redirection to encrypted HTTPS.
|
# The URL must use clear-text HTTP: no redirection to encrypted HTTPS.
|
||||||
|
@ -769,29 +774,29 @@ def check_sizeof(test, o, size):
|
||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def run_with_locale(catstr, *locales):
|
def run_with_locale(catstr, *locales):
|
||||||
|
try:
|
||||||
|
import locale
|
||||||
|
category = getattr(locale, catstr)
|
||||||
|
orig_locale = locale.setlocale(category)
|
||||||
|
except AttributeError:
|
||||||
|
# if the test author gives us an invalid category string
|
||||||
|
raise
|
||||||
|
except:
|
||||||
|
# cannot retrieve original locale, so do nothing
|
||||||
|
locale = orig_locale = None
|
||||||
|
else:
|
||||||
|
for loc in locales:
|
||||||
try:
|
try:
|
||||||
import locale
|
locale.setlocale(category, loc)
|
||||||
category = getattr(locale, catstr)
|
break
|
||||||
orig_locale = locale.setlocale(category)
|
|
||||||
except AttributeError:
|
|
||||||
# if the test author gives us an invalid category string
|
|
||||||
raise
|
|
||||||
except:
|
except:
|
||||||
# cannot retrieve original locale, so do nothing
|
pass
|
||||||
locale = orig_locale = None
|
|
||||||
else:
|
|
||||||
for loc in locales:
|
|
||||||
try:
|
|
||||||
locale.setlocale(category, loc)
|
|
||||||
break
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
if locale and orig_locale:
|
if locale and orig_locale:
|
||||||
locale.setlocale(category, orig_locale)
|
locale.setlocale(category, orig_locale)
|
||||||
|
|
||||||
#=======================================================================
|
#=======================================================================
|
||||||
# Decorator for running a function in a specific timezone, correctly
|
# Decorator for running a function in a specific timezone, correctly
|
||||||
|
|
|
@ -682,6 +682,12 @@ class TestSupport(unittest.TestCase):
|
||||||
self.check_print_warning("a\nb",
|
self.check_print_warning("a\nb",
|
||||||
'Warning -- a\nWarning -- b\n')
|
'Warning -- a\nWarning -- b\n')
|
||||||
|
|
||||||
|
def test_has_strftime_extensions(self):
|
||||||
|
if support.is_emscripten or support.is_wasi or sys.platform == "win32":
|
||||||
|
self.assertFalse(support.has_strftime_extensions)
|
||||||
|
else:
|
||||||
|
self.assertTrue(support.has_strftime_extensions)
|
||||||
|
|
||||||
# XXX -follows a list of untested API
|
# XXX -follows a list of untested API
|
||||||
# make_legacy_pyc
|
# make_legacy_pyc
|
||||||
# is_resource_enabled
|
# is_resource_enabled
|
||||||
|
|
|
@ -622,6 +622,9 @@ class _TestStrftimeYear:
|
||||||
def yearstr(self, y):
|
def yearstr(self, y):
|
||||||
return time.strftime('%Y', (y,) + (0,) * 8)
|
return time.strftime('%Y', (y,) + (0,) * 8)
|
||||||
|
|
||||||
|
@unittest.skipUnless(
|
||||||
|
support.has_strftime_extensions, "requires strftime extension"
|
||||||
|
)
|
||||||
def test_4dyear(self):
|
def test_4dyear(self):
|
||||||
# Check that we can return the zero padded value.
|
# Check that we can return the zero padded value.
|
||||||
if self._format == '%04d':
|
if self._format == '%04d':
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Skip tests if platform's ``strftime`` does not support non-portable glibc
|
||||||
|
extensions.
|
Loading…
Reference in New Issue