Skip to content

Commit 9541826

Browse files
committed
merge tests; fix formatting
1 parent ed87c7d commit 9541826

2 files changed

Lines changed: 28 additions & 56 deletions

File tree

Lib/test/datetimetester.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,32 +2207,19 @@ def test_strptime_D_format(self):
22072207
self.theclass.strptime(test_date, "%m/%d/%y")
22082208
)
22092209

2210-
def test_strptime_t_format(self):
2211-
test_year,test_month,test_day = 2026,2,20
2212-
whitespaces = ('',' ','\t','\r','\v','\n','\f')
2213-
for ws in (*whitespaces,''.join(whitespaces)):
2214-
with self.subTest(whitespace=ws):
2215-
self.assertEqual(
2216-
self.theclass.strptime(
2217-
f'{test_year:04d}{ws}{test_month:02d}{ws}{test_day:02d}',
2218-
"%Y%t%m%t%d"
2219-
),
2220-
self.theclass(test_year,test_month,test_day)
2221-
)
2222-
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-
2210+
def test_strptime_n_and_t_format(self):
2211+
year, month, day = 2026, 2, 20
2212+
whitespaces = ('', ' ', '\t', '\r', '\v', '\n', '\f')
2213+
for fd in ('n', 't'):
2214+
for ws in (*whitespaces, ''.join(whitespaces)):
2215+
with self.subTest(format_descriptor=fd, whitespace=ws):
2216+
self.assertEqual(
2217+
self.theclass.strptime(
2218+
f"{year:04d}{ws}{month:02d}{ws}{day:02d}",
2219+
f"%Y%{fd}%m%{fd}%d"
2220+
),
2221+
self.theclass(year, month, day)
2222+
)
22362223

22372224
#############################################################################
22382225
# datetime tests

Lib/test/test_strptime.py

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -670,37 +670,22 @@ def test_strptime_D_format(self):
670670
time.strptime(test_date, "%m/%d/%y")
671671
)
672672

673-
def test_strptime_t_format(self):
674-
test_year,test_month,test_day = 2026,2,20
675-
whitespaces = ('',' ','\t','\r','\v','\n','\f')
676-
for ws in (*whitespaces,''.join(whitespaces)):
677-
with self.subTest(whitespace=ws):
678-
self.assertEqual(
679-
time.strptime(
680-
f'{test_year:04d}{ws}{test_month:02d}{ws}{test_day:02d}',
681-
"%Y%t%m%t%d"
682-
),
683-
time.strptime(
684-
f'{test_year:04d}-{test_month:02d}-{test_day:02d}',
685-
"%Y-%m-%d"
673+
def test_strptime_n_and_t_format(self):
674+
year, month, day = 2026, 2, 20
675+
whitespaces = ('', ' ', '\t', '\r', '\v', '\n', '\f')
676+
for fd in ('n', 't'):
677+
for ws in (*whitespaces, ''.join(whitespaces)):
678+
with self.subTest(format_descriptor=fd, whitespace=ws):
679+
self.assertEqual(
680+
time.strptime(
681+
f"{year:04d}{ws}{month:02d}{ws}{day:02d}",
682+
f"%Y%{fd}%m%{fd}%d"
683+
),
684+
time.strptime(
685+
f'{year:04d}-{month:02d}-{day:02d}',
686+
"%Y-%m-%d"
687+
)
686688
)
687-
)
688-
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-
)
704689

705690
class Strptime12AMPMTests(unittest.TestCase):
706691
"""Test a _strptime regression in '%I %p' at 12 noon (12 PM)"""

0 commit comments

Comments
 (0)