From 38e409b8df936ce03497f07b6ba977540c8350f7 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Fri, 9 Jan 2015 19:21:05 +0000 Subject: [PATCH] Be more informative when JSONpaths do not match When the YAML files uses JSONpaths that do not or cannot match we need to know which patch it was that didn't match, otherwise we just get a rather lame error message that is not useful information for fixing the problem. --- gabbi/case.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gabbi/case.py b/gabbi/case.py index 0ccb0b0..e3eed64 100644 --- a/gabbi/case.py +++ b/gabbi/case.py @@ -81,7 +81,9 @@ class HTTPTestCase(testtools.TestCase): self.json_data = response_data for path in json_paths: match = self._extract_json_path_value(response_data, path) - self.assertEqual(json_paths[path], match) + self.assertEqual(json_paths[path], match, + 'Unable to match %s as %s' + % (path, json_paths[path])) def _decode_content(self, response, content): """Decode content to a proper string.""" @@ -107,7 +109,12 @@ class HTTPTestCase(testtools.TestCase): """ path_expr = jsonpath_rw.parse(path) matches = [match.value for match in path_expr.find(data)] - return matches[0] + try: + return matches[0] + except IndexError: + raise ValueError( + "JSONPath '%s' failed to match on data: '%s'" + % (path, data)) def _load_data_file(self, filename): """Read a file from the current test directory."""