# Year 42 returns '42', not padded
self.assertEqual(d.strftime("%Y"), '%d' % y)
# '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):
cls = self.theclass
"""Used for subprocess, os.spawn calls, fd inheritance"""
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.
# The URL must use clear-text HTTP: no redirection to encrypted HTTPS.
@contextlib.contextmanager
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:
- import locale
- category = getattr(locale, catstr)
- orig_locale = locale.setlocale(category)
- except AttributeError:
- # if the test author gives us an invalid category string
- raise
+ locale.setlocale(category, loc)
+ break
except:
- # cannot retrieve original locale, so do nothing
- locale = orig_locale = None
- else:
- for loc in locales:
- try:
- locale.setlocale(category, loc)
- break
- except:
- pass
+ pass
- try:
- yield
- finally:
- if locale and orig_locale:
- locale.setlocale(category, orig_locale)
+ try:
+ yield
+ finally:
+ if locale and orig_locale:
+ locale.setlocale(category, orig_locale)
#=======================================================================
# Decorator for running a function in a specific timezone, correctly
self.check_print_warning("a\nb",
'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
# make_legacy_pyc
# is_resource_enabled