From ea05b7c5d1630573df7a28e04cccc0e379e9b9ec Mon Sep 17 00:00:00 2001 From: nh916 Date: Tue, 25 Jul 2023 16:27:42 -0700 Subject: [PATCH] wrote test function for `_is_node_field_valid` wrote test function and test cases for `_is_node_field_valid` --- src/cript/nodes/util/__init__.py | 2 +- tests/nodes/test_utils.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/nodes/test_utils.py diff --git a/src/cript/nodes/util/__init__.py b/src/cript/nodes/util/__init__.py index 30c0bf5e2..46fd39b78 100644 --- a/src/cript/nodes/util/__init__.py +++ b/src/cript/nodes/util/__init__.py @@ -286,7 +286,7 @@ def _is_node_field_valid(node_type_list: list) -> bool: """ # TODO consider having exception handling for the dict - if isinstance(node_type_list, list) and len(node_type_list) == 1 and isinstance(node_type_list[0], str): + if isinstance(node_type_list, list) and len(node_type_list) == 1 and isinstance(node_type_list[0], str) and node_type_list[0]: return True else: return False diff --git a/tests/nodes/test_utils.py b/tests/nodes/test_utils.py new file mode 100644 index 000000000..14826bafc --- /dev/null +++ b/tests/nodes/test_utils.py @@ -0,0 +1,18 @@ +from cript.nodes.util import _is_node_field_valid + + +def test_is_node_field_valid() -> None: + """ + test the `_is_node_field_valid()` function to be sure it does the node type check correctly + + checks both in places it should be valid and invalid + """ + assert _is_node_field_valid(node_type_list=["Project"]) is True + + assert _is_node_field_valid(node_type_list=["Project", "Material"]) is False + + assert _is_node_field_valid(node_type_list=[""]) is False + + assert _is_node_field_valid(node_type_list="Project") is False + + assert _is_node_field_valid(node_type_list=[]) is False