@@ -82,6 +82,40 @@ def test_gpu_validation_fails_with_unsupported_accelerator():
8282 ManagedClusterConfig (head_accelerators = {"unsupported.com/accelerator" : 1 })
8383
8484
85+ def test_config_type_validation_errors (mocker ):
86+ """Test that type validation properly raises errors with incorrect types."""
87+ # Mock the _is_type method to return False for type checking
88+ mocker .patch .object (
89+ ManagedClusterConfig ,
90+ "_is_type" ,
91+ side_effect = lambda value , expected_type : False , # Always fail type check
92+ )
93+
94+ # This should raise TypeError during initialization
95+ with pytest .raises (TypeError , match = "Type validation failed" ):
96+ ManagedClusterConfig ()
97+
98+
99+ def test_config_is_type_method ():
100+ """Test the _is_type static method for type checking."""
101+ # Test basic types
102+ assert ManagedClusterConfig ._is_type ("test" , str ) is True
103+ assert ManagedClusterConfig ._is_type (123 , int ) is True
104+ assert ManagedClusterConfig ._is_type (123 , str ) is False
105+
106+ # Test optional types (Union with None)
107+ from typing import Optional
108+
109+ assert ManagedClusterConfig ._is_type (None , Optional [str ]) is True
110+ assert ManagedClusterConfig ._is_type ("test" , Optional [str ]) is True
111+ assert ManagedClusterConfig ._is_type (123 , Optional [str ]) is False
112+
113+ # Test dict types
114+ assert ManagedClusterConfig ._is_type ({}, dict ) is True
115+ assert ManagedClusterConfig ._is_type ({"key" : "value" }, dict ) is True
116+ assert ManagedClusterConfig ._is_type ([], dict ) is False
117+
118+
85119def test_ray_usage_stats_always_disabled_by_default ():
86120 """Test that RAY_USAGE_STATS_ENABLED is always set to '0' by default"""
87121 config = ManagedClusterConfig ()
0 commit comments