From 12b81b2e6166eb4b36f83240bd7cb8f10b7657d8 Mon Sep 17 00:00:00 2001 From: Samuel Merritt Date: Thu, 12 Jun 2014 16:51:28 -0700 Subject: [PATCH] Fix SLO test with old simplejson Our requirements.txt contains "simplejson>=2.0.9". With that version, attempting to decode invalid JSON raises ValueError, not simplejson.JSONDecodeError. In fact, there is no such thing as JSONDecodeError; it isn't introduced until a later version. Also, stdlib's json module doesn't have a JSONDecodeError either. However, JSONDecodeError inherits from ValueError, so we can just catch that instead. Also added a better failure message when invalid JSON is detected; we'll now fail immediately instead of later in some assertEqual(). Change-Id: I7f0db20b2d72e89c961cb43daa6888ecd878f769 --- test/unit/common/middleware/test_slo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/common/middleware/test_slo.py b/test/unit/common/middleware/test_slo.py index b6c3034cce..e3d978031d 100644 --- a/test/unit/common/middleware/test_slo.py +++ b/test/unit/common/middleware/test_slo.py @@ -821,8 +821,8 @@ class TestSloGetManifest(SloTestCase): headers) try: resp_data = json.loads(body) - except json.JSONDecodeError: - resp_data = None + except ValueError: + self.fail("Invalid JSON in manifest GET: %r" % body) self.assertEqual( resp_data,