Skip to content

Commit 0553369

Browse files
bpo-35066: Make trailing percent test more portable. (GH-15907)
Different libc implementations have different behavior when presented with trailing % in strftime strings. To make test_strftime_trailing_percent more portable, compare the output of datetime.strftime directly to that of time.strftime rather than hardcoding. (cherry picked from commit f2173ae) Co-authored-by: Benjamin Peterson <benjamin@python.org>
1 parent d378fdb commit 0553369

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

Lib/test/datetimetester.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,15 +1411,20 @@ def test_strftime(self):
14111411
t.strftime("%f")
14121412

14131413
def test_strftime_trailing_percent(self):
1414-
# bpo-35066: make sure trailing '%' doesn't cause
1415-
# datetime's strftime to complain
1414+
# bpo-35066: Make sure trailing '%' doesn't cause datetime's strftime to
1415+
# complain. Different libcs have different handling of trailing
1416+
# percents, so we simply check datetime's strftime acts the same as
1417+
# time.strftime.
14161418
t = self.theclass(2005, 3, 2)
14171419
try:
14181420
_time.strftime('%')
14191421
except ValueError:
14201422
self.skipTest('time module does not support trailing %')
1421-
self.assertEqual(t.strftime('%'), '%')
1422-
self.assertEqual(t.strftime("m:%m d:%d y:%y %"), "m:03 d:02 y:05 %")
1423+
self.assertEqual(t.strftime('%'), _time.strftime('%', t.timetuple()))
1424+
self.assertEqual(
1425+
t.strftime("m:%m d:%d y:%y %"),
1426+
_time.strftime("m:03 d:02 y:05 %", t.timetuple()),
1427+
)
14231428

14241429
def test_format(self):
14251430
dt = self.theclass(2007, 9, 10)

0 commit comments

Comments
 (0)