]> git.puffer.fish Git - mirror/frr.git/commitdiff
topotest: always show diff on json_cmp failure
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Thu, 9 Nov 2017 20:10:54 +0000 (18:10 -0200)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 28 Nov 2018 01:22:12 +0000 (20:22 -0500)
Append diffs on all json_cmp failures so the reader can compare JSON
field differences.

tests/topotests/lib/topotest.py

index 8cf02c26fb3eab1c0b727e4d20d0561300d1b59c..42ac62213ae530c70de07df34c01c9dd1e375336 100644 (file)
@@ -92,21 +92,22 @@ def json_cmp(d1, d2):
         s2_req = set([key for key in nd2 if nd2[key] is not None])
         diff = s2_req - s1
         if diff != set({}):
-            result.add_error('expected key(s) {} in {} (have {})'.format(
-                str(list(diff)), parent, str(list(s1))))
+            result.add_error('expected key(s) {} in {} (have {}):\n{}'.format(
+                str(list(diff)), parent, str(list(s1)), json_diff(nd1, nd2)))
 
         for key in s2.intersection(s1):
             # Test for non existence of key in d2
             if nd2[key] is None:
-                result.add_error('"{}" should not exist in {} (have {})'.format(
-                    key, parent, str(s1)))
+                result.add_error('"{}" should not exist in {} (have {}):\n{}'.format(
+                    key, parent, str(s1), json_diff(nd1[key], nd2[key])))
                 continue
             # If nd1 key is a dict, we have to recurse in it later.
             if isinstance(nd2[key], type({})):
                 if not isinstance(nd1[key], type({})):
                     result.add_error(
                         '{}["{}"] has different type than expected '.format(parent, key) +
-                        '(have {}, expected {})'.format(type(nd1[key]), type(nd2[key])))
+                        '(have {}, expected {}):\n{}'.format(
+                            type(nd1[key]), type(nd2[key]), json_diff(nd1[key], nd2[key])))
                     continue
                 nparent = '{}["{}"]'.format(parent, key)
                 squeue.append((nd1[key], nd2[key], nparent))
@@ -116,7 +117,8 @@ def json_cmp(d1, d2):
                 if not isinstance(nd1[key], type([])):
                     result.add_error(
                         '{}["{}"] has different type than expected '.format(parent, key) +
-                        '(have {}, expected {})'.format(type(nd1[key]), type(nd2[key])))
+                        '(have {}, expected {}):\n{}'.format(
+                            type(nd1[key]), type(nd2[key]), json_diff(nd1[key], nd2[key])))
                     continue
                 # Check list size
                 if len(nd2[key]) > len(nd1[key]):