summaryrefslogtreecommitdiff
path: root/tests/topotests/lib/test/test_json.py
diff options
context:
space:
mode:
authorRafael Zalamena <rzalamena@gmail.com>2017-07-05 13:46:28 -0300
committerDonald Sharp <sharpd@cumulusnetworks.com>2018-11-27 20:22:11 -0500
commitdc0d3fc53f86310cb5789dedf647f981975e94fa (patch)
treee0e6c68f1171e51644fe592771493037c5bf9c1f /tests/topotests/lib/test/test_json.py
parent19ccab570b5a9c231dea2be4793523a7001aee72 (diff)
topotest: add JSON list comparation support
Add missing list support for json_cmp(). The missing support was noticed while writing the BGP ECMP topology test.
Diffstat (limited to 'tests/topotests/lib/test/test_json.py')
-rwxr-xr-xtests/topotests/lib/test/test_json.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/topotests/lib/test/test_json.py b/tests/topotests/lib/test/test_json.py
index 87bf48dda2..e397194503 100755
--- a/tests/topotests/lib/test/test_json.py
+++ b/tests/topotests/lib/test/test_json.py
@@ -249,5 +249,85 @@ def test_json_intersect_multilevel_false():
assert json_cmp(dcomplete, dsub5) is not None
assert json_cmp(dcomplete, dsub6) is not None
+def test_json_with_list_sucess():
+ "Test successful json comparisons that have lists."
+
+ dcomplete = {
+ 'list': [
+ {
+ 'i1': 'item 1',
+ 'i2': 'item 2',
+ },
+ {
+ 'i10': 'item 10',
+ },
+ ],
+ 'i100': 'item 100',
+ }
+
+ # Test list type
+ dsub1 = {
+ 'list': [],
+ }
+ # Test list correct list items
+ dsub2 = {
+ 'list': [
+ {
+ 'i1': 'item 1',
+ },
+ ],
+ 'i100': 'item 100',
+ }
+ # Test list correct list size
+ dsub3 = {
+ 'list': [
+ {}, {},
+ ],
+ }
+
+ assert json_cmp(dcomplete, dsub1) is None
+ assert json_cmp(dcomplete, dsub2) is None
+ assert json_cmp(dcomplete, dsub3) is None
+
+def test_json_with_list_failure():
+ "Test failed json comparisons that have lists."
+
+ dcomplete = {
+ 'list': [
+ {
+ 'i1': 'item 1',
+ 'i2': 'item 2',
+ },
+ {
+ 'i10': 'item 10',
+ },
+ ],
+ 'i100': 'item 100',
+ }
+
+ # Test list type
+ dsub1 = {
+ 'list': {},
+ }
+ # Test list incorrect list items
+ dsub2 = {
+ 'list': [
+ {
+ 'i1': 'item 2',
+ },
+ ],
+ 'i100': 'item 100',
+ }
+ # Test list correct list size
+ dsub3 = {
+ 'list': [
+ {}, {}, {},
+ ],
+ }
+
+ assert json_cmp(dcomplete, dsub1) is not None
+ assert json_cmp(dcomplete, dsub2) is not None
+ assert json_cmp(dcomplete, dsub3) is not None
+
if __name__ == '__main__':
sys.exit(pytest.main())