summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMichaelSaah <mike.saah@gmail.com>2019-01-14 10:23:39 (GMT)
committerVictor Stinner <vstinner@redhat.com>2019-01-14 10:23:39 (GMT)
commit454b3d4ea246e8751534e105548d141ed7b0b032 (patch)
tree6a337c41728d51a65521e0a9b47176654775cfd4 /Lib/test
parent5bb146aaea1484bcc117ab6cb38dda39ceb5df0f (diff)
downloadcpython-454b3d4ea246e8751534e105548d141ed7b0b032.zip
cpython-454b3d4ea246e8751534e105548d141ed7b0b032.tar.gz
cpython-454b3d4ea246e8751534e105548d141ed7b0b032.tar.bz2
bpo-35066: _dateime.datetime.strftime copies trailing '%' (GH-10692)
Previously, calling the strftime() method on a datetime object with a trailing '%' in the format string would result in an exception. However, this only occured when the datetime C module was being used; the python implementation did not match this behavior. Datetime is now PEP-399 compliant, and will not throw an exception on a trailing '%'.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/datetimetester.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index 2f838c4..d729c7e 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -1351,6 +1351,17 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
#check that this standard extension works
t.strftime("%f")
+ def test_strftime_trailing_percent(self):
+ # bpo-35066: make sure trailing '%' doesn't cause
+ # datetime's strftime to complain
+ 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 %")
+
def test_format(self):
dt = self.theclass(2007, 9, 10)
self.assertEqual(dt.__format__(''), str(dt))