diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-10-18 13:51:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-18 13:51:29 (GMT) |
commit | 2e950e341930ea79549137d4d3771d5edb940e65 (patch) | |
tree | 184c996759f558d40566f5cf8bac89e4e11e1367 /Lib/test/test_time.py | |
parent | cda0ec8e7c4e9a010e5f73c5afaf18f86cb27b97 (diff) | |
download | cpython-2e950e341930ea79549137d4d3771d5edb940e65.zip cpython-2e950e341930ea79549137d4d3771d5edb940e65.tar.gz cpython-2e950e341930ea79549137d4d3771d5edb940e65.tar.bz2 |
Add tests for time.strftime() with invalid format string (GH-125696)
Diffstat (limited to 'Lib/test/test_time.py')
-rw-r--r-- | Lib/test/test_time.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index f8b99a9..d368f08 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -18,7 +18,7 @@ try: except ImportError: _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. 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) + 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): tt = time.gmtime(self.t) s1 = time.strftime('%c', tt) |