Skip to content

Commit 9393378

Browse files
[3.12] Add tests for time.strftime() with invalid format string (GH-125696) (GH-125701)
(cherry picked from commit 2e950e3) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent aa9faee commit 9393378

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Lib/test/test_time.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
except ImportError:
1515
_testcapi = None
1616

17-
from test.support import skip_if_buggy_ucrt_strfptime
17+
from test.support import skip_if_buggy_ucrt_strfptime, SuppressCrashReport
1818

1919
# Max year is only limited by the size of C int.
2020
SIZEOF_INT = sysconfig.get_config_var('SIZEOF_INT') or 4
@@ -178,6 +178,17 @@ def test_strftime(self):
178178

179179
self.assertRaises(TypeError, time.strftime, b'%S', tt)
180180

181+
def test_strftime_invalid_format(self):
182+
tt = time.gmtime(self.t)
183+
with SuppressCrashReport():
184+
for i in range(1, 128):
185+
format = ' %' + chr(i)
186+
with self.subTest(format=format):
187+
try:
188+
time.strftime(format, tt)
189+
except ValueError as exc:
190+
self.assertEqual(str(exc), 'Invalid format string')
191+
181192
def test_strftime_special(self):
182193
tt = time.gmtime(self.t)
183194
s1 = time.strftime('%c', tt)

0 commit comments

Comments
 (0)