Skip to content

Commit f2173ae

Browse files
authored
bpo-35066: Make trailing percent test more portable. (pythonGH-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.
1 parent c374474 commit f2173ae

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Lib/test/datetimetester.py

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

14511451
def test_strftime_trailing_percent(self):
1452-
# bpo-35066: make sure trailing '%' doesn't cause
1453-
# datetime's strftime to complain
1452+
# bpo-35066: Make sure trailing '%' doesn't cause datetime's strftime to
1453+
# complain. Different libcs have different handling of trailing
1454+
# percents, so we simply check datetime's strftime acts the same as
1455+
# time.strftime.
14541456
t = self.theclass(2005, 3, 2)
14551457
try:
14561458
_time.strftime('%')
14571459
except ValueError:
14581460
self.skipTest('time module does not support trailing %')
1459-
self.assertEqual(t.strftime('%'), '%')
1460-
self.assertEqual(t.strftime("m:%m d:%d y:%y %"), "m:03 d:02 y:05 %")
1461+
self.assertEqual(t.strftime('%'), _time.strftime('%', t.timetuple()))
1462+
self.assertEqual(
1463+
t.strftime("m:%m d:%d y:%y %"),
1464+
_time.strftime("m:03 d:02 y:05 %", t.timetuple()),
1465+
)
14611466

14621467
def test_format(self):
14631468
dt = self.theclass(2007, 9, 10)

0 commit comments

Comments
 (0)