Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for time.strftime() with invalid format string #125696

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add tests for time.strftime() with invalid format string
  • Loading branch information
serhiy-storchaka committed Oct 18, 2024
commit 5645851dc0ad98d0002e20e0615c79206daac5a8
13 changes: 12 additions & 1 deletion Lib/test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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
Expand Down Expand Up @@ -182,6 +182,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
Loading