From 254e0ae839ecc692192f29e3aa590e6d5d3377a7 Mon Sep 17 00:00:00 2001 From: Corey Bryant Date: Wed, 25 Jul 2018 16:52:22 -0400 Subject: [PATCH] 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 --- oslo_serialization/tests/test_jsonutils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/oslo_serialization/tests/test_jsonutils.py b/oslo_serialization/tests/test_jsonutils.py index da8edd4..afa8948 100644 --- a/oslo_serialization/tests/test_jsonutils.py +++ b/oslo_serialization/tests/test_jsonutils.py @@ -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')"])