[Python-checkins] bpo-35066: Make trailing percent test more portable. (GH-15907)
Miss Islington (bot)
webhook-mailer at python.org
Wed Sep 11 07:47:21 EDT 2019
https://github.com/python/cpython/commit/f3e430b07975c84cf34c927851df234d04d5753f
commit: f3e430b07975c84cf34c927851df234d04d5753f
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-09-11T04:47:16-07:00
summary:
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 f2173ae38fa49235c3cdc28ae2ca2e19a375a596)
Co-authored-by: Benjamin Peterson <benjamin at python.org>
files:
M Lib/test/datetimetester.py
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index b440e5ab5fa6..d1a3c2ff9abc 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -1449,15 +1449,20 @@ def test_strftime(self):
t.strftime("%f")
def test_strftime_trailing_percent(self):
- # bpo-35066: make sure trailing '%' doesn't cause
- # datetime's strftime to complain
+ # bpo-35066: Make sure trailing '%' doesn't cause datetime's strftime to
+ # complain. Different libcs have different handling of trailing
+ # percents, so we simply check datetime's strftime acts the same as
+ # time.strftime.
t = self.theclass(2005, 3, 2)
try:
_time.strftime('%')
except ValueError:
self.skipTest('time module does not support trailing %')
- self.assertEqual(t.strftime('%'), '%')
- self.assertEqual(t.strftime("m:%m d:%d y:%y %"), "m:03 d:02 y:05 %")
+ self.assertEqual(t.strftime('%'), _time.strftime('%', t.timetuple()))
+ self.assertEqual(
+ t.strftime("m:%m d:%d y:%y %"),
+ _time.strftime("m:03 d:02 y:05 %", t.timetuple()),
+ )
def test_format(self):
dt = self.theclass(2007, 9, 10)
More information about the Python-checkins
mailing list