diff --git a/tests/types/test_type_helpers.py b/tests/types/test_type_helpers.py index f7cefd0..3ab5953 100644 --- a/tests/types/test_type_helpers.py +++ b/tests/types/test_type_helpers.py @@ -101,5 +101,60 @@ def test_is_list_of(): assert is_list_of(["x", 2], (str, int)) is True +def test_is_dict_of_edge_cases(): + # Test empty dictionary + assert is_dict_of({}, key_allowed_types=str) is True, ( + "Empty dictionary should return True" + ) + # Test None as input + assert is_dict_of(None, key_allowed_types=str) is False, ( + "None input should return False" + ) + # Test dictionary with a None value + assert ( + is_dict_of( + {"key": None}, + key_allowed_types=str, + value_allowed_types=(str, type(None)), + ) + is True + ), "Dictionary with None value should pass if None is an allowed type" + # Test nested dictionary by specifying allowed value types that do not include dict + assert ( + is_dict_of( + {"key": {"nested_key": "value"}}, + key_allowed_types=str, + value_allowed_types=(str, int), + ) + is False + ), ( + "Nested dictionaries should return False if dict is not an allowed value type" + ) + # Test nested dictionary when no value types are specified (documents current behavior) + assert ( + is_dict_of({"key": {"nested_key": "value"}}, key_allowed_types=str) + is True + ), "Nested dictionaries are allowed when value types are not specified" + + +def test_is_list_of_edge_cases(): + # Test empty list + assert is_list_of([], str) is True, "Empty list should return True" + # Test None as input + assert is_list_of(None, str) is False, "None input should return False" + # Test list with a None value + assert is_list_of([None], str) is False, ( + "List with None value should return False if None is not an allowed type" + ) + # Test list with a None value where None is an allowed type + assert is_list_of([None], (str, type(None))) is True, ( + "List with None value should pass if None is an allowed type" + ) + # Test nested list + assert is_list_of([["a", "b"]], str) is False, ( + "Nested lists should return False" + ) + + if __name__ == "__main__": raise SystemExit(pytest.main([__file__]))