Skip to content

Commit 55ca618

Browse files
committed
rename init method in create
1 parent 85c782e commit 55ca618

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

netcompare/check_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CheckType(ABC):
1919
"""Check Type Base Abstract Class."""
2020

2121
@staticmethod
22-
def init(check_type: str):
22+
def create(check_type: str):
2323
"""Factory pattern to get the appropriate CheckType implementation.
2424
2525
Args:

tests/test_get_value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def test_jmspath_return_none(data):
1111
"""Habdle exception when JMSPath retunr None."""
1212
my_jmspath = "global[*]"
13-
my_check = CheckType.init(check_type="exact_match")
13+
my_check = CheckType.create(check_type="exact_match")
1414
with pytest.raises(TypeError) as error:
1515
my_check.get_value(output=data, path=my_jmspath)() # pylint: disable=E0110
1616

tests/test_operators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
@pytest.mark.parametrize("filename, check_type_str, evaluate_args, path, expected_result", operator_all_tests)
171171
def test_operator(filename, check_type_str, evaluate_args, path, expected_result):
172172
"""Validate all operator check types."""
173-
check = CheckType.init(check_type_str)
173+
check = CheckType.create(check_type_str)
174174
# There is not concept of "pre" and "post" in operator.
175175
data = load_json_file("api", filename)
176176
value = check.get_value(data, path)

tests/test_sw_upgrade_device_state.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_show_version(platform, command, jpath, expected_parameter, check_should
2121
filename = f"{platform}_{command}.json"
2222
command = load_json_file("sw_upgrade", filename)
2323

24-
check = CheckType.init("parameter_match")
24+
check = CheckType.create("parameter_match")
2525
value = check.get_value(command, jpath)
2626
eval_results, passed = check.evaluate(value, expected_parameter, "match") # pylint: disable=E1121
2727
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):
5050
command_post[0]["link_status"] = "down"
5151
command_post[1]["protocol_status"] = "down"
5252

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

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

@@ -85,7 +85,7 @@ def test_show_ip_route_exact_match(platform, command):
8585
def test_show_ip_route_missing_and_additional_routes(platform, command):
8686
"""Test missing or additional routes fail the test with exact_match."""
8787
command_pre = command_post = load_json_file("sw_upgrade", f"{platform}_{command}.json")
88-
check = CheckType.init("exact_match")
88+
check = CheckType.create("exact_match")
8989
print(len(command_pre))
9090
eval_results_missing, passed_missing = check.evaluate(command_post[:30], command_pre)
9191
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):
114114
state_key = "state" if "arista" in platform else "bgp_state"
115115
command_post[0][state_key] = "Idle"
116116

117-
check = CheckType.init("exact_match")
117+
check = CheckType.create("exact_match")
118118
pre_value = CheckType.get_value(command_pre, jpath)
119119
post_value = CheckType.get_value(command_post, jpath)
120120
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
139139

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

142-
check = CheckType.init("tolerance")
142+
check = CheckType.create("tolerance")
143143
jpath = "[*].[$bgp_neigh$,state_pfxrcd]"
144144
pre_value = CheckType.get_value(command_pre, jpath)
145145
post_value = CheckType.get_value(command_post, jpath)
@@ -168,7 +168,7 @@ def test_ospf_neighbor_state(platform, command, jpath, check_should_pass):
168168
command_post[0]["state"] = "2WAY"
169169
command_post = command_post[:1]
170170

171-
check = CheckType.init("exact_match")
171+
check = CheckType.create("exact_match")
172172
pre_value = CheckType.get_value(command_pre, jpath)
173173
post_value = CheckType.get_value(command_post, jpath)
174174
eval_results, passed = check.evaluate(post_value, pre_value)
@@ -199,6 +199,6 @@ def test_lldp_neighbor_state(platform, command, check_should_pass):
199199
if check_should_pass is False:
200200
command_post = command_post[:2]
201201

202-
check = CheckType.init("exact_match")
202+
check = CheckType.create("exact_match")
203203
eval_results, passed = check.evaluate(command_post, command_pre)
204204
assert passed is check_should_pass, f"FAILED, eval_result: {eval_results}"

tests/test_type_checks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def evaluate(self, *args, **kwargs):
4848
)
4949
def test_check_init(check_type_str, expected_class):
5050
"""Validate that the returned class is the expected one."""
51-
assert isinstance(CheckType.init(check_type_str), expected_class)
51+
assert isinstance(CheckType.create(check_type_str), expected_class)
5252

5353

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

6666

@@ -123,7 +123,7 @@ def tests_exceptions_init(check_type_str, exception_type, expected_in_output):
123123
@pytest.mark.parametrize("check_type_str, evaluate_args, folder_name, path, expected_results", check_type_tests)
124124
def test_check_type_results(check_type_str, evaluate_args, folder_name, path, expected_results):
125125
"""Validate that CheckType.evaluate returns the expected_results."""
126-
check = CheckType.init(check_type_str)
126+
check = CheckType.create(check_type_str)
127127
pre_data, post_data = load_mocks(folder_name)
128128
pre_value = check.get_value(pre_data, path)
129129
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
238238
@pytest.mark.parametrize("folder_name, check_type_str, evaluate_args, path, expected_result", check_tests)
239239
def test_checks(folder_name, check_type_str, evaluate_args, path, expected_result):
240240
"""Validate multiple checks on the same data to catch corner cases."""
241-
check = CheckType.init(check_type_str)
241+
check = CheckType.create(check_type_str)
242242
pre_data, post_data = load_mocks(folder_name)
243243
pre_value = check.get_value(pre_data, path)
244244
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
283283
)
284284
def test_param_match(filename, check_type_str, evaluate_args, path, expected_result):
285285
"""Validate parameter_match check type."""
286-
check = CheckType.init(check_type_str)
286+
check = CheckType.create(check_type_str)
287287
# There is not concept of "pre" and "post" in parameter_match.
288288
data = load_json_file("parameter_match", filename)
289289
value = check.get_value(data, path)
@@ -330,7 +330,7 @@ def test_param_match(filename, check_type_str, evaluate_args, path, expected_res
330330
@pytest.mark.parametrize("filename, check_type_str, evaluate_args, path, expected_result", regex_match)
331331
def test_regex_match(filename, check_type_str, evaluate_args, path, expected_result):
332332
"""Validate regex check type."""
333-
check = CheckType.init(check_type_str)
333+
check = CheckType.create(check_type_str)
334334
# There is not concept of "pre" and "post" in parameter_match.
335335
data = load_json_file("api", filename)
336336
value = check.get_value(data, path)

tests/test_validates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
@pytest.mark.parametrize("check_type_str, evaluate_args, expected_results", all_tests)
125125
def test_validate_arguments(check_type_str, evaluate_args, expected_results):
126126
"""Test CheckType validate method for each check-type."""
127-
check = CheckType.init(check_type_str)
127+
check = CheckType.create(check_type_str)
128128

129129
with pytest.raises(ValueError) as exc_info:
130130
if check_type_str == "tolerance":

0 commit comments

Comments
 (0)