@@ -62,6 +62,42 @@ def __iter__(self):
6262 assert isinstance (exc_info .value .original_error , RuntimeError )
6363
6464
65+ @pytest .mark .parametrize ("transport_class" , [SyncTransport , AsyncTransport ])
66+ def test_transport_wraps_api_key_empty_check_length_failures (transport_class ):
67+ class _BrokenLengthApiKey (str ):
68+ class _NormalizedKey (str ):
69+ def __len__ (self ):
70+ raise RuntimeError ("api key length exploded" )
71+
72+ def strip (self , chars = None ): # type: ignore[override]
73+ _ = chars
74+ return self ._NormalizedKey ("test-key" )
75+
76+ with pytest .raises (HyperbrowserError , match = "Failed to normalize api_key" ) as exc_info :
77+ transport_class (api_key = _BrokenLengthApiKey ("test-key" ))
78+
79+ assert isinstance (exc_info .value .original_error , RuntimeError )
80+
81+
82+ @pytest .mark .parametrize ("transport_class" , [SyncTransport , AsyncTransport ])
83+ def test_transport_preserves_hyperbrowser_api_key_empty_check_length_failures (
84+ transport_class ,
85+ ):
86+ class _BrokenLengthApiKey (str ):
87+ class _NormalizedKey (str ):
88+ def __len__ (self ):
89+ raise HyperbrowserError ("custom length failure" )
90+
91+ def strip (self , chars = None ): # type: ignore[override]
92+ _ = chars
93+ return self ._NormalizedKey ("test-key" )
94+
95+ with pytest .raises (HyperbrowserError , match = "custom length failure" ) as exc_info :
96+ transport_class (api_key = _BrokenLengthApiKey ("test-key" ))
97+
98+ assert exc_info .value .original_error is None
99+
100+
65101@pytest .mark .parametrize ("transport_class" , [SyncTransport , AsyncTransport ])
66102def test_transport_preserves_hyperbrowser_api_key_character_iteration_failures (
67103 transport_class ,
0 commit comments