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.
This commit is contained in:
Benjamin Peterson 2019-09-11 11:50:38 +01:00 committed by GitHub
parent c37447481e
commit f2173ae38f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -1449,15 +1449,20 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
t.strftime("%f") t.strftime("%f")
def test_strftime_trailing_percent(self): def test_strftime_trailing_percent(self):
# bpo-35066: make sure trailing '%' doesn't cause # bpo-35066: Make sure trailing '%' doesn't cause datetime's strftime to
# datetime's strftime to complain # 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) t = self.theclass(2005, 3, 2)
try: try:
_time.strftime('%') _time.strftime('%')
except ValueError: except ValueError:
self.skipTest('time module does not support trailing %') self.skipTest('time module does not support trailing %')
self.assertEqual(t.strftime('%'), '%') self.assertEqual(t.strftime('%'), _time.strftime('%', t.timetuple()))
self.assertEqual(t.strftime("m:%m d:%d y:%y %"), "m:03 d:02 y:05 %") self.assertEqual(
t.strftime("m:%m d:%d y:%y %"),
_time.strftime("m:03 d:02 y:05 %", t.timetuple()),
)
def test_format(self): def test_format(self):
dt = self.theclass(2007, 9, 10) dt = self.theclass(2007, 9, 10)