mirror of
https://github.com/python/cpython.git
synced 2025-07-31 23:23:11 +00:00
Fix problem spotted by Coverity that occurs if tzinfo.tzname().replace()
returns a non-string when converting %Z. Will backport.
This commit is contained in:
parent
29892cc386
commit
d5b0c9b87e
2 changed files with 20 additions and 4 deletions
|
@ -1168,6 +1168,17 @@ class TestDateTime(TestDate):
|
|||
self.assertEqual(dt2 - dt1, us)
|
||||
self.assert_(dt1 < dt2)
|
||||
|
||||
def test_strftime_with_bad_tzname_replace(self):
|
||||
# verify ok if tzinfo.tzname().replace() returns a non-string
|
||||
class MyTzInfo(FixedOffset):
|
||||
def tzname(self, dt):
|
||||
class MyStr(str):
|
||||
def replace(self, *args):
|
||||
return None
|
||||
return MyStr('name')
|
||||
t = self.theclass(2005, 3, 2, 0, 0, 0, 0, MyTzInfo(3, 'name'))
|
||||
self.assertRaises(TypeError, t.strftime, '%Z')
|
||||
|
||||
def test_bad_constructor_arguments(self):
|
||||
# bad years
|
||||
self.theclass(MINYEAR, 1, 1) # no exception
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue