Skip to content

Commit a8d0320

Browse files
author
Patryk Szulczewski
committed
uniform parametrize, move fail message to utils
1 parent 577facc commit a8d0320

File tree

7 files changed

+30
-38
lines changed

7 files changed

+30
-38
lines changed

tests/test_diff_generator.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
import pytest
33
from netcompare.evaluator import diff_generator
44
from netcompare.runner import extract_values_from_output
5-
from .utility import load_mocks
5+
from .utility import load_mocks, ASSERT_FAIL_MESSAGE
66

77

88
exact_match_of_global_peers_via_napalm_getter = ("napalm_getter", "global.$peers$.*.[is_enabled,is_up]", [])
99

10-
exact_match_of_bgpPeerCaps_via_api = ("api", "result[0].vrfs.default.peerList[*].[$peerAddress$,state,bgpPeerCaps]", [])
10+
exact_match_of_bgp_peer_caps_via_api = (
11+
"api",
12+
"result[0].vrfs.default.peerList[*].[$peerAddress$,state,bgpPeerCaps]",
13+
[],
14+
)
1115

1216
exact_match_of_bgp_neigh_via_textfsm = ("textfsm", "result[*].[$bgp_neigh$,state]", [])
1317

@@ -39,7 +43,7 @@
3943

4044
eval_tests = [
4145
exact_match_of_global_peers_via_napalm_getter,
42-
exact_match_of_bgpPeerCaps_via_api,
46+
exact_match_of_bgp_peer_caps_via_api,
4347
exact_match_of_bgp_neigh_via_textfsm,
4448
raw_diff_of_interface_ma1_via_api_value_exclude,
4549
raw_diff_of_interface_ma1_via_api_novalue_exclude,
@@ -50,11 +54,6 @@
5054
exact_match_multi_nested_list,
5155
]
5256

53-
ASSERT_FAILED_MESSAGE = """Test output is different from expected output.
54-
output: {output}
55-
expected output: {expected_output}
56-
"""
57-
5857

5958
@pytest.mark.parametrize("folder_name, path, exclude", eval_tests)
6059
def test_eval(folder_name, path, exclude):
@@ -64,4 +63,4 @@ def test_eval(folder_name, path, exclude):
6463
post_value = extract_values_from_output(post_data, path, exclude)
6564
output = diff_generator(pre_value, post_value)
6665

67-
assert expected_output == output, ASSERT_FAILED_MESSAGE.format(output=output, expected_output=expected_output)
66+
assert expected_output == output, ASSERT_FAIL_MESSAGE.format(output=output, expected_output=expected_output)

tests/test_filter_parsers.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
"Filter parser unit tests."
22
import pytest
33
from netcompare.utils.filter_parsers import exclude_filter
4+
from .utility import ASSERT_FAIL_MESSAGE
45

56

6-
ASSERT_FAIL_MESSAGE = """Test output is different from expected output.
7-
output: {output}
8-
expected output: {expected_output}
9-
"""
10-
117
exclude_filter_case_1 = (
128
["interfaceStatistics"],
139
{

tests/test_flatten.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
"Flatten list unit test"
22
import pytest
33
from netcompare.utils.flatten import flatten_list
4+
from .utility import ASSERT_FAIL_MESSAGE
45

56

6-
ASSERT_FAIL_MESSAGE = """Test output is different from expected output.
7-
output: {output}
8-
expected output: {expected_output}
9-
"""
10-
117
flatten_list_case_1 = (
128
[[[[-1, 0], [-1, 0]]]],
139
[[-1, 0], [-1, 0]],

tests/test_jmspath_parsers.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
"""JMSPath parser unit tests."""
22
import pytest
33
from netcompare.utils.jmspath_parsers import jmspath_value_parser, jmspath_refkey_parser
4+
from .utility import ASSERT_FAIL_MESSAGE
45

56

6-
ASSERT_FAIL_MESSSAGE = """Test output is different from expected output.
7-
output: {output}
8-
expected output: {expected_output}
9-
"""
10-
117
value_parser_case_1 = (
128
"result[0].vrfs.default.peerList[*].[$peerAddress$,prefixesReceived]",
139
"result[0].vrfs.default.peerList[*].[peerAddress,prefixesReceived]",
@@ -61,10 +57,10 @@
6157
@pytest.mark.parametrize("path, expected_output", value_parser_tests)
6258
def test_value_parser(path, expected_output):
6359
output = jmspath_value_parser(path)
64-
assert expected_output == output, ASSERT_FAIL_MESSSAGE.format(output=output, expected_output=expected_output)
60+
assert expected_output == output, ASSERT_FAIL_MESSAGE.format(output=output, expected_output=expected_output)
6561

6662

6763
@pytest.mark.parametrize("path, expected_output", keyref_parser_tests)
6864
def test_keyref_parser(path, expected_output):
6965
output = jmspath_refkey_parser(path)
70-
assert expected_output == output, ASSERT_FAIL_MESSSAGE.format(output=output, expected_output=expected_output)
66+
assert expected_output == output, ASSERT_FAIL_MESSAGE.format(output=output, expected_output=expected_output)

tests/test_refkey.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
"""Reference key unit tests."""
22
import pytest
33
from netcompare.utils.refkey import keys_cleaner, keys_values_zipper, associate_key_of_my_value
4-
5-
6-
ASSERT_FAILED_MESSAGE = """Test output is different from expected output.
7-
output: {output}
8-
expected output: {expected_output}
9-
"""
4+
from .utility import ASSERT_FAIL_MESSAGE
105

116
keys_cleaner_case_1 = (
127
{"10.1.0.0": {"address_family": "ipv4"}},
@@ -41,16 +36,16 @@
4136
@pytest.mark.parametrize("wanted_key, expected_output", keys_cleaner_tests)
4237
def test_keys_cleaner(wanted_key, expected_output):
4338
output = keys_cleaner(wanted_key)
44-
assert expected_output == output, ASSERT_FAILED_MESSAGE.format(output=output, expected_output=expected_output)
39+
assert expected_output == output, ASSERT_FAIL_MESSAGE.format(output=output, expected_output=expected_output)
4540

4641

4742
@pytest.mark.parametrize("ref_keys, wanted_values, expected_output", keys_zipper_tests)
4843
def test_keys_zipper(ref_keys, wanted_values, expected_output):
4944
output = keys_values_zipper(ref_keys, wanted_values)
50-
assert expected_output == output, ASSERT_FAILED_MESSAGE.format(output=output, expected_output=expected_output)
45+
assert expected_output == output, ASSERT_FAIL_MESSAGE.format(output=output, expected_output=expected_output)
5146

5247

5348
@pytest.mark.parametrize("path, wanted_values, expected_output", keys_association_test)
5449
def test_keys_association(path, wanted_values, expected_output):
5550
output = associate_key_of_my_value(path, wanted_values)
56-
assert expected_output == output, ASSERT_FAILED_MESSAGE.format(output=output, expected_output=expected_output)
51+
assert expected_output == output, ASSERT_FAIL_MESSAGE.format(output=output, expected_output=expected_output)

tests/test_type_check.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"Check Type unit tests."
22
import pytest
33
from netcompare.check_type import CheckType, ExactMatchType, ToleranceType
4-
from .utility import load_mocks
4+
from .utility import load_mocks, ASSERT_FAIL_MESSAGE
55

66

77
@pytest.mark.parametrize(
@@ -83,7 +83,9 @@ def test_check_type_results(check_type_args, folder_name, path, expected_results
8383
pre_value = check.extract_value_from_json_path(pre_data, path)
8484
post_value = check.extract_value_from_json_path(post_data, path)
8585
actual_results = check.evaluate(pre_value, post_value)
86-
assert actual_results == expected_results
86+
assert actual_results == expected_results, ASSERT_FAIL_MESSAGE.format(
87+
output=actual_results, expected_output=expected_results
88+
)
8789

8890

8991
napalm_bgp_neighbor_status = (
@@ -127,4 +129,6 @@ def test_checks(folder_name, check_args, path, result_index):
127129
post_value = check.extract_value_from_json_path(post_data, path)
128130
actual_results = check.evaluate(pre_value, post_value)
129131

130-
assert list(actual_results) == results[result_index]
132+
assert list(actual_results) == results[result_index], ASSERT_FAIL_MESSAGE.format(
133+
output=actual_results, expected_output=results[result_index]
134+
)

tests/utility.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
dirname = os.path.dirname(os.path.abspath(__file__))
88

99

10+
ASSERT_FAIL_MESSAGE = """Test output is different from expected output.
11+
output: {output}
12+
expected output: {expected_output}
13+
"""
14+
15+
1016
def load_json_file(folder, filename):
1117
"""Load mock data from json file."""
1218
filepath = os.path.join(dirname, "mock", folder, filename)

0 commit comments

Comments
 (0)