py37: deal with Exception repr changes
Under Python 3.7, a trailing comma is no longer added to the init parameters generated by a repr() call: >>> repr(Exception('It Works')) "Exception('It Works')" vs >>> repr(Exception('It Works')) "Exception('It Works',)" Support pre and post Python 3.7 formats in test cases. Change-Id: I45bdf565e170793d0342a907628638369d4d0f2f Closes-Bug: #1783638
This commit is contained in:
parent
dc592c68e3
commit
254e0ae839
@ -116,8 +116,9 @@ class JSONUtilsTestMixin(object):
|
||||
self.assertIsInstance(val, six.text_type)
|
||||
|
||||
def test_dumps_exception_value(self):
|
||||
self.assertEqual('{"a": "ValueError(\'hello\',)"}',
|
||||
jsonutils.dumps({"a": ValueError("hello")}))
|
||||
self.assertIn(jsonutils.dumps({"a": ValueError("hello")}),
|
||||
['{"a": "ValueError(\'hello\',)"}',
|
||||
'{"a": "ValueError(\'hello\')"}'])
|
||||
|
||||
|
||||
class JSONUtilsTestJson(JSONUtilsTestMixin, test_base.BaseTestCase):
|
||||
@ -407,5 +408,6 @@ class ToPrimitiveTestCase(test_base.BaseTestCase):
|
||||
self.assertEqual('fallback', ret)
|
||||
|
||||
def test_exception(self):
|
||||
self.assertEqual("ValueError('an exception',)",
|
||||
jsonutils.to_primitive(ValueError("an exception")))
|
||||
self.assertIn(jsonutils.to_primitive(ValueError("an exception")),
|
||||
["ValueError('an exception',)",
|
||||
"ValueError('an exception')"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user