summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2019-09-11 10:50:38 (GMT)
committerGitHub <noreply@github.com>2019-09-11 10:50:38 (GMT)
commitf2173ae38fa49235c3cdc28ae2ca2e19a375a596 (patch)
tree3b8da2cef5c99cbc560bdb0b4570781fc67fade9
parentc37447481ec8f6d0e49d0587ec0de3f9e7d56b28 (diff)
downloadcpython-f2173ae38fa49235c3cdc28ae2ca2e19a375a596.zip
cpython-f2173ae38fa49235c3cdc28ae2ca2e19a375a596.tar.gz
cpython-f2173ae38fa49235c3cdc28ae2ca2e19a375a596.tar.bz2
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.
-rw-r--r--Lib/test/datetimetester.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index a1ed614..32977b1 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -1449,15 +1449,20 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
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)