@@ -263,6 +263,62 @@ def test_format_unsupported_format(self, sample_proxy):
263263 with pytest .raises (ValueError , match = "Invalid format type" ):
264264 sample_proxy .format ("unsupported" )
265265
266+ def test_format_invalid_type_not_string_or_enum (self , sample_proxy ):
267+ """Test format with invalid type (not string or ProxyFormat enum)."""
268+ with pytest .raises (
269+ ValueError ,
270+ match = "Invalid format type: int. Expected ProxyFormat enum or string." ,
271+ ):
272+ sample_proxy .format (123 ) # int instead of string/enum
273+
274+ def test_format_invalid_type_none (self , sample_proxy ):
275+ """Test format with None type."""
276+ with pytest .raises (
277+ ValueError ,
278+ match = "Invalid format type: NoneType. Expected ProxyFormat enum or string." ,
279+ ):
280+ sample_proxy .format (None )
281+
282+ def test_format_invalid_type_list (self , sample_proxy ):
283+ """Test format with list type."""
284+ with pytest .raises (
285+ ValueError ,
286+ match = "Invalid format type: list. Expected ProxyFormat enum or string." ,
287+ ):
288+ sample_proxy .format (["requests" ])
289+
290+ def test_format_invalid_type_dict (self , sample_proxy ):
291+ """Test format with dict type."""
292+ with pytest .raises (
293+ ValueError ,
294+ match = "Invalid format type: dict. Expected ProxyFormat enum or string." ,
295+ ):
296+ sample_proxy .format ({"format" : "requests" })
297+
298+ def test_format_handlers_complete_coverage (self , sample_proxy ):
299+ """Test that all ProxyFormat enum values have corresponding handlers."""
300+ # This test ensures that if someone adds a new ProxyFormat enum value,
301+ # they must also add a corresponding handler in the format_handlers dictionary
302+
303+ # Get all ProxyFormat enum values
304+ all_proxy_formats = set (ProxyFormat )
305+
306+ # Test that each format can be processed without KeyError
307+ for format_type in all_proxy_formats :
308+ try :
309+ result = sample_proxy .format (format_type )
310+ assert (
311+ result is not None
312+ ), f"Format { format_type .value } should return a result"
313+ except KeyError as e :
314+ pytest .fail (f"Missing handler for ProxyFormat.{ format_type .name } : { e } " )
315+ except Exception as e :
316+ # Other exceptions are fine (like validation errors), but KeyError means missing handler
317+ if "KeyError" in str (type (e )):
318+ pytest .fail (
319+ f"Missing handler for ProxyFormat.{ format_type .name } : { e } "
320+ )
321+
266322 def test_format_proxy_with_limited_protocols (self ):
267323 """Test format with proxy that only supports specific protocols."""
268324 proxy = Proxy (
0 commit comments