Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion netcompare/check_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CheckType(ABC):
"""Check Type Base Abstract Class."""

@staticmethod
def init(check_type: str):
def create(check_type: str):
"""Factory pattern to get the appropriate CheckType implementation.

Args:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_get_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def test_jmspath_return_none(data):
"""Habdle exception when JMSPath retunr None."""
my_jmspath = "global[*]"
my_check = CheckType.init(check_type="exact_match")
my_check = CheckType.create(check_type="exact_match")
with pytest.raises(TypeError) as error:
my_check.get_value(output=data, path=my_jmspath)() # pylint: disable=E0110

Expand Down
2 changes: 1 addition & 1 deletion tests/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
@pytest.mark.parametrize("filename, check_type_str, evaluate_args, path, expected_result", operator_all_tests)
def test_operator(filename, check_type_str, evaluate_args, path, expected_result):
"""Validate all operator check types."""
check = CheckType.init(check_type_str)
check = CheckType.create(check_type_str)
# There is not concept of "pre" and "post" in operator.
data = load_json_file("api", filename)
value = check.get_value(data, path)
Expand Down
16 changes: 8 additions & 8 deletions tests/test_sw_upgrade_device_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_show_version(platform, command, jpath, expected_parameter, check_should
filename = f"{platform}_{command}.json"
command = load_json_file("sw_upgrade", filename)

check = CheckType.init("parameter_match")
check = CheckType.create("parameter_match")
value = check.get_value(command, jpath)
eval_results, passed = check.evaluate(value, expected_parameter, "match") # pylint: disable=E1121
assert passed is check_should_pass, f"FAILED, eval_result: {eval_results}"
Expand Down Expand Up @@ -50,7 +50,7 @@ def test_show_interfaces_state(platform, command, jpath, check_should_pass):
command_post[0]["link_status"] = "down"
command_post[1]["protocol_status"] = "down"

check = CheckType.init("exact_match")
check = CheckType.create("exact_match")
pre_value = CheckType.get_value(command_pre, jpath)
post_value = CheckType.get_value(command_post, jpath)
eval_results, passed = check.evaluate(post_value, pre_value)
Expand All @@ -69,7 +69,7 @@ def test_show_ip_route_exact_match(platform, command):
"""Test identical route table pass the test with exact_match."""
command_pre = command_post = load_json_file("sw_upgrade", f"{platform}_{command}.json")

check = CheckType.init("exact_match")
check = CheckType.create("exact_match")
eval_results, passed = check.evaluate(command_post, command_pre)
assert passed is True, f"FAILED, eval_result: {eval_results}"

Expand All @@ -85,7 +85,7 @@ def test_show_ip_route_exact_match(platform, command):
def test_show_ip_route_missing_and_additional_routes(platform, command):
"""Test missing or additional routes fail the test with exact_match."""
command_pre = command_post = load_json_file("sw_upgrade", f"{platform}_{command}.json")
check = CheckType.init("exact_match")
check = CheckType.create("exact_match")
print(len(command_pre))
eval_results_missing, passed_missing = check.evaluate(command_post[:30], command_pre)
eval_results_additional, passed_additional = check.evaluate(command_post, command_pre[:30])
Expand Down Expand Up @@ -114,7 +114,7 @@ def test_bgp_neighbor_state(platform, command, jpath, check_should_pass):
state_key = "state" if "arista" in platform else "bgp_state"
command_post[0][state_key] = "Idle"

check = CheckType.init("exact_match")
check = CheckType.create("exact_match")
pre_value = CheckType.get_value(command_pre, jpath)
post_value = CheckType.get_value(command_post, jpath)
eval_results, passed = check.evaluate(post_value, pre_value)
Expand All @@ -139,7 +139,7 @@ def test_bgp_prefix_tolerance(platform, command, prfx_post_value, tolerance, che

command_post[1]["state_pfxrcd"] = command_post[1]["state_pfxrcd"] = prfx_post_value

check = CheckType.init("tolerance")
check = CheckType.create("tolerance")
jpath = "[*].[$bgp_neigh$,state_pfxrcd]"
pre_value = CheckType.get_value(command_pre, jpath)
post_value = CheckType.get_value(command_post, jpath)
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_ospf_neighbor_state(platform, command, jpath, check_should_pass):
command_post[0]["state"] = "2WAY"
command_post = command_post[:1]

check = CheckType.init("exact_match")
check = CheckType.create("exact_match")
pre_value = CheckType.get_value(command_pre, jpath)
post_value = CheckType.get_value(command_post, jpath)
eval_results, passed = check.evaluate(post_value, pre_value)
Expand Down Expand Up @@ -199,6 +199,6 @@ def test_lldp_neighbor_state(platform, command, check_should_pass):
if check_should_pass is False:
command_post = command_post[:2]

check = CheckType.init("exact_match")
check = CheckType.create("exact_match")
eval_results, passed = check.evaluate(command_post, command_pre)
assert passed is check_should_pass, f"FAILED, eval_result: {eval_results}"
12 changes: 6 additions & 6 deletions tests/test_type_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def evaluate(self, *args, **kwargs):
)
def test_check_init(check_type_str, expected_class):
"""Validate that the returned class is the expected one."""
assert isinstance(CheckType.init(check_type_str), expected_class)
assert isinstance(CheckType.create(check_type_str), expected_class)


exception_tests_init = [
Expand All @@ -60,7 +60,7 @@ def test_check_init(check_type_str, expected_class):
def tests_exceptions_init(check_type_str, exception_type, expected_in_output):
"""Tests exceptions when check object is initialized."""
with pytest.raises(exception_type) as error:
CheckType.init(check_type_str)
CheckType.create(check_type_str)
assert expected_in_output in error.value.__str__()


Expand Down Expand Up @@ -123,7 +123,7 @@ def tests_exceptions_init(check_type_str, exception_type, expected_in_output):
@pytest.mark.parametrize("check_type_str, evaluate_args, folder_name, path, expected_results", check_type_tests)
def test_check_type_results(check_type_str, evaluate_args, folder_name, path, expected_results):
"""Validate that CheckType.evaluate returns the expected_results."""
check = CheckType.init(check_type_str)
check = CheckType.create(check_type_str)
pre_data, post_data = load_mocks(folder_name)
pre_value = check.get_value(pre_data, path)
post_value = check.get_value(post_data, path)
Expand Down Expand Up @@ -238,7 +238,7 @@ def test_check_type_results(check_type_str, evaluate_args, folder_name, path, ex
@pytest.mark.parametrize("folder_name, check_type_str, evaluate_args, path, expected_result", check_tests)
def test_checks(folder_name, check_type_str, evaluate_args, path, expected_result):
"""Validate multiple checks on the same data to catch corner cases."""
check = CheckType.init(check_type_str)
check = CheckType.create(check_type_str)
pre_data, post_data = load_mocks(folder_name)
pre_value = check.get_value(pre_data, path)
post_value = check.get_value(post_data, path)
Expand Down Expand Up @@ -283,7 +283,7 @@ def test_checks(folder_name, check_type_str, evaluate_args, path, expected_resul
)
def test_param_match(filename, check_type_str, evaluate_args, path, expected_result):
"""Validate parameter_match check type."""
check = CheckType.init(check_type_str)
check = CheckType.create(check_type_str)
# There is not concept of "pre" and "post" in parameter_match.
data = load_json_file("parameter_match", filename)
value = check.get_value(data, path)
Expand Down Expand Up @@ -330,7 +330,7 @@ def test_param_match(filename, check_type_str, evaluate_args, path, expected_res
@pytest.mark.parametrize("filename, check_type_str, evaluate_args, path, expected_result", regex_match)
def test_regex_match(filename, check_type_str, evaluate_args, path, expected_result):
"""Validate regex check type."""
check = CheckType.init(check_type_str)
check = CheckType.create(check_type_str)
# There is not concept of "pre" and "post" in parameter_match.
data = load_json_file("api", filename)
value = check.get_value(data, path)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_validates.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
@pytest.mark.parametrize("check_type_str, evaluate_args, expected_results", all_tests)
def test_validate_arguments(check_type_str, evaluate_args, expected_results):
"""Test CheckType validate method for each check-type."""
check = CheckType.init(check_type_str)
check = CheckType.create(check_type_str)

with pytest.raises(ValueError) as exc_info:
if check_type_str == "tolerance":
Expand Down