summaryrefslogtreecommitdiff
path: root/tests/topotests/lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'tests/topotests/lib/test')
-rwxr-xr-xtests/topotests/lib/test/test_json.py344
-rwxr-xr-xtests/topotests/lib/test/test_run_and_expect.py13
-rwxr-xr-xtests/topotests/lib/test/test_version.py31
3 files changed, 115 insertions, 273 deletions
diff --git a/tests/topotests/lib/test/test_json.py b/tests/topotests/lib/test/test_json.py
index 3927ba095d..ba118d607a 100755
--- a/tests/topotests/lib/test/test_json.py
+++ b/tests/topotests/lib/test/test_json.py
@@ -32,36 +32,37 @@ import pytest
# Save the Current Working Directory to find lib files.
CWD = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.join(CWD, '../../'))
+sys.path.append(os.path.join(CWD, "../../"))
# pylint: disable=C0413
from lib.topotest import json_cmp
+
def test_json_intersect_true():
"Test simple correct JSON intersections"
dcomplete = {
- 'i1': 'item1',
- 'i2': 'item2',
- 'i3': 'item3',
- 'i100': 'item4',
+ "i1": "item1",
+ "i2": "item2",
+ "i3": "item3",
+ "i100": "item4",
}
dsub1 = {
- 'i1': 'item1',
- 'i3': 'item3',
+ "i1": "item1",
+ "i3": "item3",
}
dsub2 = {
- 'i1': 'item1',
- 'i2': 'item2',
+ "i1": "item1",
+ "i2": "item2",
}
dsub3 = {
- 'i100': 'item4',
- 'i2': 'item2',
+ "i100": "item4",
+ "i2": "item2",
}
dsub4 = {
- 'i50': None,
- 'i100': 'item4',
+ "i50": None,
+ "i100": "item4",
}
assert json_cmp(dcomplete, dsub1) is None
@@ -69,99 +70,66 @@ def test_json_intersect_true():
assert json_cmp(dcomplete, dsub3) is None
assert json_cmp(dcomplete, dsub4) is None
+
def test_json_intersect_false():
"Test simple incorrect JSON intersections"
dcomplete = {
- 'i1': 'item1',
- 'i2': 'item2',
- 'i3': 'item3',
- 'i100': 'item4',
+ "i1": "item1",
+ "i2": "item2",
+ "i3": "item3",
+ "i100": "item4",
}
# Incorrect value for 'i1'
dsub1 = {
- 'i1': 'item3',
- 'i3': 'item3',
+ "i1": "item3",
+ "i3": "item3",
}
# Non-existing key 'i5'
dsub2 = {
- 'i1': 'item1',
- 'i5': 'item2',
+ "i1": "item1",
+ "i5": "item2",
}
# Key should not exist
dsub3 = {
- 'i100': None,
+ "i100": None,
}
assert json_cmp(dcomplete, dsub1) is not None
assert json_cmp(dcomplete, dsub2) is not None
assert json_cmp(dcomplete, dsub3) is not None
+
def test_json_intersect_multilevel_true():
"Test multi level correct JSON intersections"
dcomplete = {
- 'i1': 'item1',
- 'i2': 'item2',
- 'i3': {
- 'i100': 'item100',
+ "i1": "item1",
+ "i2": "item2",
+ "i3": {"i100": "item100",},
+ "i4": {
+ "i41": {"i411": "item411",},
+ "i42": {"i421": "item421", "i422": "item422",},
},
- 'i4': {
- 'i41': {
- 'i411': 'item411',
- },
- 'i42': {
- 'i421': 'item421',
- 'i422': 'item422',
- }
- }
}
dsub1 = {
- 'i1': 'item1',
- 'i3': {
- 'i100': 'item100',
- },
- 'i10': None,
+ "i1": "item1",
+ "i3": {"i100": "item100",},
+ "i10": None,
}
dsub2 = {
- 'i1': 'item1',
- 'i2': 'item2',
- 'i3': {},
+ "i1": "item1",
+ "i2": "item2",
+ "i3": {},
}
dsub3 = {
- 'i2': 'item2',
- 'i4': {
- 'i41': {
- 'i411': 'item411',
- },
- 'i42': {
- 'i422': 'item422',
- 'i450': None,
- }
- }
- }
- dsub4 = {
- 'i2': 'item2',
- 'i4': {
- 'i41': {},
- 'i42': {
- 'i450': None,
- }
- }
- }
- dsub5 = {
- 'i2': 'item2',
- 'i3': {
- 'i100': 'item100',
- },
- 'i4': {
- 'i42': {
- 'i450': None,
- }
- }
+ "i2": "item2",
+ "i4": {"i41": {"i411": "item411",}, "i42": {"i422": "item422", "i450": None,}},
}
+ dsub4 = {"i2": "item2", "i4": {"i41": {}, "i42": {"i450": None,}}}
+ dsub5 = {"i2": "item2", "i3": {"i100": "item100",}, "i4": {"i42": {"i450": None,}}}
assert json_cmp(dcomplete, dsub1) is None
assert json_cmp(dcomplete, dsub2) is None
@@ -169,78 +137,43 @@ def test_json_intersect_multilevel_true():
assert json_cmp(dcomplete, dsub4) is None
assert json_cmp(dcomplete, dsub5) is None
+
def test_json_intersect_multilevel_false():
"Test multi level incorrect JSON intersections"
dcomplete = {
- 'i1': 'item1',
- 'i2': 'item2',
- 'i3': {
- 'i100': 'item100',
+ "i1": "item1",
+ "i2": "item2",
+ "i3": {"i100": "item100",},
+ "i4": {
+ "i41": {"i411": "item411",},
+ "i42": {"i421": "item421", "i422": "item422",},
},
- 'i4': {
- 'i41': {
- 'i411': 'item411',
- },
- 'i42': {
- 'i421': 'item421',
- 'i422': 'item422',
- }
- }
}
# Incorrect sub-level value
dsub1 = {
- 'i1': 'item1',
- 'i3': {
- 'i100': 'item00',
- },
- 'i10': None,
+ "i1": "item1",
+ "i3": {"i100": "item00",},
+ "i10": None,
}
# Inexistent sub-level
dsub2 = {
- 'i1': 'item1',
- 'i2': 'item2',
- 'i3': None,
+ "i1": "item1",
+ "i2": "item2",
+ "i3": None,
}
# Inexistent sub-level value
dsub3 = {
- 'i1': 'item1',
- 'i3': {
- 'i100': None,
- },
+ "i1": "item1",
+ "i3": {"i100": None,},
}
# Inexistent sub-sub-level value
- dsub4 = {
- 'i4': {
- 'i41': {
- 'i412': 'item412',
- },
- 'i42': {
- 'i421': 'item421',
- }
- }
- }
+ dsub4 = {"i4": {"i41": {"i412": "item412",}, "i42": {"i421": "item421",}}}
# Invalid sub-sub-level value
- dsub5 = {
- 'i4': {
- 'i41': {
- 'i411': 'item411',
- },
- 'i42': {
- 'i421': 'item420000',
- }
- }
- }
+ dsub5 = {"i4": {"i41": {"i411": "item411",}, "i42": {"i421": "item420000",}}}
# sub-sub-level should be value
- dsub6 = {
- 'i4': {
- 'i41': {
- 'i411': 'item411',
- },
- 'i42': 'foobar',
- }
- }
+ dsub6 = {"i4": {"i41": {"i411": "item411",}, "i42": "foobar",}}
assert json_cmp(dcomplete, dsub1) is not None
assert json_cmp(dcomplete, dsub2) is not None
@@ -249,80 +182,54 @@ 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',
+ "list": [{"i1": "item 1", "i2": "item 2",}, {"i10": "item 10",},],
+ "i100": "item 100",
}
# Test list type
dsub1 = {
- 'list': [],
+ "list": [],
}
# Test list correct list items
dsub2 = {
- 'list': [
- {
- 'i1': 'item 1',
- },
- ],
- 'i100': 'item 100',
+ "list": [{"i1": "item 1",},],
+ "i100": "item 100",
}
# Test list correct list size
dsub3 = {
- 'list': [
- {}, {},
- ],
+ "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',
+ "list": [{"i1": "item 1", "i2": "item 2",}, {"i10": "item 10",},],
+ "i100": "item 100",
}
# Test list type
dsub1 = {
- 'list': {},
+ "list": {},
}
# Test list incorrect list items
dsub2 = {
- 'list': [
- {
- 'i1': 'item 2',
- },
- ],
- 'i100': 'item 100',
+ "list": [{"i1": "item 2",},],
+ "i100": "item 100",
}
# Test list correct list size
dsub3 = {
- 'list': [
- {}, {}, {},
- ],
+ "list": [{}, {}, {},],
}
assert json_cmp(dcomplete, dsub1) is not None
@@ -334,53 +241,20 @@ def test_json_list_start_success():
"Test JSON encoded data that starts with a list that should succeed."
dcomplete = [
- {
- "id": 100,
- "value": "abc",
- },
- {
- "id": 200,
- "value": "abcd",
- },
- {
- "id": 300,
- "value": "abcde",
- },
+ {"id": 100, "value": "abc",},
+ {"id": 200, "value": "abcd",},
+ {"id": 300, "value": "abcde",},
]
- dsub1 = [
- {
- "id": 100,
- "value": "abc",
- }
- ]
+ dsub1 = [{"id": 100, "value": "abc",}]
- dsub2 = [
- {
- "id": 100,
- "value": "abc",
- },
- {
- "id": 200,
- "value": "abcd",
- }
- ]
+ dsub2 = [{"id": 100, "value": "abc",}, {"id": 200, "value": "abcd",}]
- dsub3 = [
- {
- "id": 300,
- "value": "abcde",
- }
- ]
+ dsub3 = [{"id": 300, "value": "abcde",}]
- dsub4 = [
- ]
+ dsub4 = []
- dsub5 = [
- {
- "id": 100,
- }
- ]
+ dsub5 = [{"id": 100,}]
assert json_cmp(dcomplete, dsub1) is None
assert json_cmp(dcomplete, dsub2) is None
@@ -393,58 +267,18 @@ def test_json_list_start_failure():
"Test JSON encoded data that starts with a list that should fail."
dcomplete = [
- {
- "id": 100,
- "value": "abc"
- },
- {
- "id": 200,
- "value": "abcd"
- },
- {
- "id": 300,
- "value": "abcde"
- },
+ {"id": 100, "value": "abc"},
+ {"id": 200, "value": "abcd"},
+ {"id": 300, "value": "abcde"},
]
- dsub1 = [
- {
- "id": 100,
- "value": "abcd",
- }
- ]
+ dsub1 = [{"id": 100, "value": "abcd",}]
- dsub2 = [
- {
- "id": 100,
- "value": "abc",
- },
- {
- "id": 200,
- "value": "abc",
- }
- ]
+ dsub2 = [{"id": 100, "value": "abc",}, {"id": 200, "value": "abc",}]
- dsub3 = [
- {
- "id": 100,
- "value": "abc",
- },
- {
- "id": 350,
- "value": "abcde",
- }
- ]
+ dsub3 = [{"id": 100, "value": "abc",}, {"id": 350, "value": "abcde",}]
- dsub4 = [
- {
- "value": "abcx",
- },
- {
- "id": 300,
- "value": "abcde",
- }
- ]
+ dsub4 = [{"value": "abcx",}, {"id": 300, "value": "abcde",}]
assert json_cmp(dcomplete, dsub1) is not None
assert json_cmp(dcomplete, dsub2) is not None
@@ -452,5 +286,5 @@ def test_json_list_start_failure():
assert json_cmp(dcomplete, dsub4) is not None
-if __name__ == '__main__':
+if __name__ == "__main__":
sys.exit(pytest.main())
diff --git a/tests/topotests/lib/test/test_run_and_expect.py b/tests/topotests/lib/test/test_run_and_expect.py
index 3c22c20e7b..d65d5baf37 100755
--- a/tests/topotests/lib/test/test_run_and_expect.py
+++ b/tests/topotests/lib/test/test_run_and_expect.py
@@ -32,11 +32,12 @@ import pytest
# Save the Current Working Directory to find lib files.
CWD = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.join(CWD, '../../'))
+sys.path.append(os.path.join(CWD, "../../"))
# pylint: disable=C0413
from lib.topotest import run_and_expect_type
+
def test_run_and_expect_type():
"Test basic `run_and_expect_type` functionality."
@@ -45,12 +46,16 @@ def test_run_and_expect_type():
return True
# Test value success.
- success, value = run_and_expect_type(return_true, bool, count=1, wait=0, avalue=True)
+ success, value = run_and_expect_type(
+ return_true, bool, count=1, wait=0, avalue=True
+ )
assert success is True
assert value is True
# Test value failure.
- success, value = run_and_expect_type(return_true, bool, count=1, wait=0, avalue=False)
+ success, value = run_and_expect_type(
+ return_true, bool, count=1, wait=0, avalue=False
+ )
assert success is False
assert value is True
@@ -70,5 +75,5 @@ def test_run_and_expect_type():
assert value is True
-if __name__ == '__main__':
+if __name__ == "__main__":
sys.exit(pytest.main())
diff --git a/tests/topotests/lib/test/test_version.py b/tests/topotests/lib/test/test_version.py
index 9204ac2084..7c2df00337 100755
--- a/tests/topotests/lib/test/test_version.py
+++ b/tests/topotests/lib/test/test_version.py
@@ -32,21 +32,22 @@ import pytest
# Save the Current Working Directory to find lib files.
CWD = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.join(CWD, '../../'))
+sys.path.append(os.path.join(CWD, "../../"))
# pylint: disable=C0413
from lib.topotest import version_cmp
+
def test_valid_versions():
"Test valid version compare results"
- curver = '3.0'
- samever = '3'
- oldver = '2.0'
- newver = '3.0.1'
- newerver = '3.0.11'
- vercustom = '3.0-dev'
- verysmallinc = '3.0.0.0.0.0.0.1'
+ curver = "3.0"
+ samever = "3"
+ oldver = "2.0"
+ newver = "3.0.1"
+ newerver = "3.0.11"
+ vercustom = "3.0-dev"
+ verysmallinc = "3.0.0.0.0.0.0.1"
assert version_cmp(curver, oldver) == 1
assert version_cmp(curver, newver) == -1
@@ -64,14 +65,15 @@ def test_valid_versions():
assert version_cmp(verysmallinc, verysmallinc) == 0
assert version_cmp(vercustom, verysmallinc) == -1
+
def test_invalid_versions():
"Test invalid version strings"
- curver = '3.0'
- badver1 = '.1'
- badver2 = '-1.0'
- badver3 = '.'
- badver4 = '3.-0.3'
+ curver = "3.0"
+ badver1 = ".1"
+ badver2 = "-1.0"
+ badver3 = "."
+ badver4 = "3.-0.3"
with pytest.raises(ValueError):
assert version_cmp(curver, badver1)
@@ -79,9 +81,10 @@ def test_invalid_versions():
assert version_cmp(curver, badver3)
assert version_cmp(curver, badver4)
+
def test_regression_1():
"""
Test regression on the following type of comparison: '3.0.2' > '3'
Expected result is 1.
"""
- assert version_cmp('3.0.2', '3') == 1
+ assert version_cmp("3.0.2", "3") == 1