Skip to content

Commit 3a26205

Browse files
committed
init tests for %n support in strptime
1 parent c674612 commit 3a26205

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

Lib/test/datetimetester.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,6 +2220,19 @@ def test_strptime_t_format(self):
22202220
self.theclass(test_year,test_month,test_day)
22212221
)
22222222

2223+
def test_strptime_n_format(self):
2224+
test_year,test_month,test_day = 2026,2,25
2225+
whitespaces = ('',' ','\t','\r','\v','\n','\f')
2226+
for ws in (*whitespaces,''.join(whitespaces)):
2227+
with self.subTest(whitespace=ws):
2228+
self.assertEqual(
2229+
self.theclass.strptime(
2230+
f'{test_year:04d}{ws}{test_month:02d}{ws}{test_day:02d}',
2231+
"%Y%n%m%n%d"
2232+
),
2233+
self.theclass(test_year,test_month,test_day)
2234+
)
2235+
22232236

22242237
#############################################################################
22252238
# datetime tests

Lib/test/test_strptime.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,22 @@ def test_strptime_t_format(self):
686686
)
687687
)
688688

689+
def test_strptime_n_format(self):
690+
test_year,test_month,test_day = 2026,2,20
691+
whitespaces = ('',' ','\t','\r','\v','\n','\f')
692+
for ws in (*whitespaces,''.join(whitespaces)):
693+
with self.subTest(whitespace=ws):
694+
self.assertEqual(
695+
time.strptime(
696+
f'{test_year:04d}{ws}{test_month:02d}{ws}{test_day:02d}',
697+
"%Y%n%m%n%d"
698+
),
699+
time.strptime(
700+
f'{test_year:04d}-{test_month:02d}-{test_day:02d}',
701+
"%Y-%m-%d"
702+
)
703+
)
704+
689705
class Strptime12AMPMTests(unittest.TestCase):
690706
"""Test a _strptime regression in '%I %p' at 12 noon (12 PM)"""
691707

Lib/test/test_time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def test_strptime(self):
359359
# raising an exception.
360360
tt = time.gmtime(self.t)
361361
for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'D', 'F', 'H', 'I',
362-
'j', 'm', 'M', 'p', 'S', 't', 'T',
362+
'j', 'm', 'M', 'n', 'p', 'S', 't', 'T',
363363
'U', 'w', 'W', 'x', 'X', 'y', 'Y', 'Z', '%'):
364364
format = '%' + directive
365365
if directive == 'd':

0 commit comments

Comments
 (0)