From a5493fcc402bd1e569def84d2b0e05a722642ce7 Mon Sep 17 00:00:00 2001 From: Rashmil Panchani <32737711+Rashmil-1999@users.noreply.github.com> Date: Fri, 28 Jun 2024 10:04:44 -0500 Subject: [PATCH] removed the error codes (#600) Co-authored-by: Chen Wang --- .flake8 | 2 +- pyincore/utils/evaluateexpression.py | 4 +--- pyincore/utils/geoutil.py | 2 +- pyincore/utils/networkutil.py | 2 +- tests/pyincore/models/test_dfr3curve.py | 14 +++++++------- tests/pyincore/test_dataservice.py | 4 ++-- tests/pyincore/test_semanticservice.py | 2 +- 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/.flake8 b/.flake8 index 452caa0e..75412efd 100644 --- a/.flake8 +++ b/.flake8 @@ -1,4 +1,4 @@ [flake8] max-line-length = 180 -extend-ignore = E203,E501,E711,E712,E721,E731,E741,F401,F403,F405,F541,F841,W291 +extend-ignore = E203,E731,E741,F401,F403,F405,F541,F841,W291 exclude = __init__.py diff --git a/pyincore/utils/evaluateexpression.py b/pyincore/utils/evaluateexpression.py index 7adaf4ca..71d77df4 100644 --- a/pyincore/utils/evaluateexpression.py +++ b/pyincore/utils/evaluateexpression.py @@ -36,9 +36,7 @@ def evaluate(expression: str, parameters: dict = {}): if "__" in name or name in INVALID_NAMES: raise NameError(f"The use of '{name}' is not allowed.") for parameter in parameters: - if type(parameter) == "str" and ( - "__" in parameter or parameter in INVALID_NAMES - ): + if type(parameter) is str and ("__" in parameter or parameter in INVALID_NAMES): raise NameError(f"Using '{parameter}' is not allowed.") # TODO figure out a better way of doing this. Can we import the packages here directly? diff --git a/pyincore/utils/geoutil.py b/pyincore/utils/geoutil.py index 9adb0e5a..72ae236d 100644 --- a/pyincore/utils/geoutil.py +++ b/pyincore/utils/geoutil.py @@ -149,7 +149,7 @@ def degree_to_decimal(degree: int): int: A decimal value. """ - if degree == 0.0 or degree == None or degree == "": + if degree == 0.0 or degree is None or degree == "": decimal = "NA" else: degree = str(int(degree)) diff --git a/pyincore/utils/networkutil.py b/pyincore/utils/networkutil.py index b6b7f39b..4b7ac855 100644 --- a/pyincore/utils/networkutil.py +++ b/pyincore/utils/networkutil.py @@ -396,7 +396,7 @@ def validate_network_node_ids( node_list = list(set(node_list)) for node in link_node_list: - if node in node_list == False: + if node in node_list is False: validate = False return validate diff --git a/tests/pyincore/models/test_dfr3curve.py b/tests/pyincore/models/test_dfr3curve.py index e7793d40..68db26d9 100644 --- a/tests/pyincore/models/test_dfr3curve.py +++ b/tests/pyincore/models/test_dfr3curve.py @@ -160,9 +160,9 @@ def test_calculate_limit_state_probability( ) def test_calculate_repair_rates(repair_set, args, expected): result = repair_set.calculate_repair_rates(**args) - if type(result["PF_0"]) == numpy.ndarray: + if type(result["PF_0"]) is numpy.ndarray: assert numpy.allclose(result["PF_0"], expected, rtol=1e-03, atol=1e-03) - elif type(result["PF_0"]) == numpy.float64: + elif type(result["PF_0"]) is numpy.float64: assert result["PF_0"] == expected else: assert False @@ -182,9 +182,9 @@ def test_calculate_repair_rates(repair_set, args, expected): def test_calculate_inverse_repair_rates(repair_set, args, expected): result = repair_set.calculate_inverse_repair_rates(**args) print(result) - if type(result["PF_0"]) == numpy.ndarray: + if type(result["PF_0"]) is numpy.ndarray: assert numpy.allclose(result["PF_0"], expected, rtol=1e-03, atol=1e-03) - elif type(result["PF_0"]) == numpy.float64: + elif type(result["PF_0"]) is numpy.float64: assert result["PF_0"] == expected else: assert False @@ -203,9 +203,9 @@ def test_calculate_inverse_repair_rates(repair_set, args, expected): ) def test_calculate_restoration_rates(restoration_set, args, expected): result = restoration_set.calculate_restoration_rates(**args) - if type(result["PF_0"]) == numpy.ndarray: + if type(result["PF_0"]) is numpy.ndarray: assert numpy.allclose(result["PF_0"], expected, rtol=1e-03, atol=1e-03) - elif type(result["PF_0"]) == numpy.float64: + elif type(result["PF_0"]) is numpy.float64: assert result["PF_0"] == expected else: assert False @@ -224,7 +224,7 @@ def test_calculate_restoration_rates(restoration_set, args, expected): def test_calculate_pipeline_restoration_rates(restoration_set, args, expected): result = restoration_set.calculate_restoration_rates(**args) print(result) - if type(result["RT"]) == numpy.ndarray: + if type(result["RT"]) is numpy.ndarray: assert numpy.allclose(result["RT"], expected, rtol=1e-03, atol=1e-03) else: assert result["RT"] == expected diff --git a/tests/pyincore/test_dataservice.py b/tests/pyincore/test_dataservice.py index b12230e0..1abad269 100644 --- a/tests/pyincore/test_dataservice.py +++ b/tests/pyincore/test_dataservice.py @@ -58,7 +58,7 @@ def test_get_dataset_blob(datasvc): dataset_id = "5a284f0ac7d30d13bc0819c4" fname = datasvc.get_dataset_blob(dataset_id, join=True) - if type(fname) != str: + if type(fname) is not str: errors.append("doesn't return the correct filename!") # check if file or folder exists locally, which means successfully downloaded if not os.path.exists(fname): @@ -158,7 +158,7 @@ def test_get_file_blob(datasvc): dataset_id = "5a284f24c7d30d13bc081adb" fname = datasvc.get_file_blob(dataset_id) - if type(fname) != str: + if type(fname) is not str: errors.append("doesn't return the correct filename!") # check if file or folder exists locally, which means successfully downloaded if not os.path.exists(fname): diff --git a/tests/pyincore/test_semanticservice.py b/tests/pyincore/test_semanticservice.py index f55cce00..c9fea287 100644 --- a/tests/pyincore/test_semanticservice.py +++ b/tests/pyincore/test_semanticservice.py @@ -54,7 +54,7 @@ def test_get_semantic_type_by_name(semanticsvc): # find semantic type by name which exists semantic_types = semanticsvc.get_semantic_type_by_name(semantic_type_exists) # Checks semantic dictionary is not empty - assert type(semantic_types) == dict and bool( + assert type(semantic_types) is dict and bool( dict ), f"Should find one semantic type as {semantic_type_exists} exists" # find semantic type by name which does not exist