Skip to content

Commit

Permalink
[3.12] Add tests for time.strftime() with invalid format string (pyth…
Browse files Browse the repository at this point in the history
…onGH-125696) (pythonGH-125701)

(cherry picked from commit 2e950e3)

Co-authored-by: Serhiy Storchaka <[email protected]>
  • Loading branch information
miss-islington and serhiy-storchaka authored Oct 18, 2024
1 parent aa9faee commit 9393378
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Lib/test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
except ImportError:
_testcapi = 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
Expand Down Expand Up @@ -178,6 +178,17 @@ def test_strftime(self):

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)
Expand Down

0 comments on commit 9393378

Please sign in to comment.