Skip to content

Commit e9927fb

Browse files
committed
update tests with subtests for all whitespace chars covered by '\s'
1 parent dac5692 commit e9927fb

2 files changed

Lines changed: 23 additions & 17 deletions

File tree

Lib/test/datetimetester.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,13 +2209,16 @@ def test_strptime_D_format(self):
22092209

22102210
def test_strptime_t_format(self):
22112211
test_year,test_month,test_day = 2026,2,20
2212-
self.assertEqual(
2213-
self.theclass.strptime(
2214-
f'{test_year} \r {test_month}\t \n{test_day}',
2215-
"%Y%t%m%t%d"
2216-
),
2217-
self.theclass(test_year,test_month,test_day)
2218-
)
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+
)
22192222

22202223

22212224
#############################################################################

Lib/test/test_strptime.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -672,16 +672,19 @@ def test_strptime_D_format(self):
672672

673673
def test_strptime_t_format(self):
674674
test_year,test_month,test_day = 2026,2,20
675-
self.assertEqual(
676-
time.strptime(
677-
f'{test_year} \r {test_month}\t \n{test_day}',
678-
"%Y%t%m%t%d"
679-
),
680-
time.strptime(
681-
f'{test_year}-{test_month}-{test_day}',
682-
"%Y-%m-%d"
683-
)
684-
)
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"
686+
)
687+
)
685688

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

0 commit comments

Comments
 (0)