mirror of
https://github.com/python/cpython.git
synced 2024-11-24 17:47:13 +01:00
Add tests for time.strftime() with invalid format string (GH-125696)
This commit is contained in:
parent
cda0ec8e7c
commit
2e950e3419
@ -18,7 +18,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
_testinternalcapi = None
|
_testinternalcapi = None
|
||||||
|
|
||||||
from test.support import skip_if_buggy_ucrt_strfptime
|
from test.support import skip_if_buggy_ucrt_strfptime, SuppressCrashReport
|
||||||
|
|
||||||
# Max year is only limited by the size of C int.
|
# Max year is only limited by the size of C int.
|
||||||
SIZEOF_INT = sysconfig.get_config_var('SIZEOF_INT') or 4
|
SIZEOF_INT = sysconfig.get_config_var('SIZEOF_INT') or 4
|
||||||
@ -182,6 +182,17 @@ class TimeTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertRaises(TypeError, time.strftime, b'%S', tt)
|
self.assertRaises(TypeError, time.strftime, b'%S', tt)
|
||||||
|
|
||||||
|
def test_strftime_invalid_format(self):
|
||||||
|
tt = time.gmtime(self.t)
|
||||||
|
with SuppressCrashReport():
|
||||||
|
for i in range(1, 128):
|
||||||
|
format = ' %' + chr(i)
|
||||||
|
with self.subTest(format=format):
|
||||||
|
try:
|
||||||
|
time.strftime(format, tt)
|
||||||
|
except ValueError as exc:
|
||||||
|
self.assertEqual(str(exc), 'Invalid format string')
|
||||||
|
|
||||||
def test_strftime_special(self):
|
def test_strftime_special(self):
|
||||||
tt = time.gmtime(self.t)
|
tt = time.gmtime(self.t)
|
||||||
s1 = time.strftime('%c', tt)
|
s1 = time.strftime('%c', tt)
|
||||||
|
Loading…
Reference in New Issue
Block a user