diff --git a/netcompare/check_types.py b/netcompare/check_types.py index 55d194b..f0e491a 100644 --- a/netcompare/check_types.py +++ b/netcompare/check_types.py @@ -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: diff --git a/tests/test_get_value.py b/tests/test_get_value.py index 836327b..6821200 100644 --- a/tests/test_get_value.py +++ b/tests/test_get_value.py @@ -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 diff --git a/tests/test_operators.py b/tests/test_operators.py index bbb486d..e2d4845 100644 --- a/tests/test_operators.py +++ b/tests/test_operators.py @@ -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) diff --git a/tests/test_sw_upgrade_device_state.py b/tests/test_sw_upgrade_device_state.py index 683b74d..bb65d06 100644 --- a/tests/test_sw_upgrade_device_state.py +++ b/tests/test_sw_upgrade_device_state.py @@ -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}" @@ -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) @@ -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}" @@ -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]) @@ -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) @@ -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) @@ -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) @@ -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}" diff --git a/tests/test_type_checks.py b/tests/test_type_checks.py index 99ac67a..ab8b06f 100644 --- a/tests/test_type_checks.py +++ b/tests/test_type_checks.py @@ -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 = [ @@ -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__() @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/tests/test_validates.py b/tests/test_validates.py index bd7d2db..ad0b523 100644 --- a/tests/test_validates.py +++ b/tests/test_validates.py @@ -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":