@@ -201,58 +201,12 @@ def _broken_get(env_name: str, default=None):
201201
202202
203203@pytest .mark .parametrize ("client_class" , [Hyperbrowser , AsyncHyperbrowser ])
204- def test_client_wraps_api_key_strip_runtime_errors (client_class ):
205- class _BrokenStripApiKey (str ):
206- def strip (self , chars = None ): # type: ignore[override]
207- _ = chars
208- raise RuntimeError ("api key strip exploded" )
204+ def test_client_rejects_string_subclass_api_key_input (client_class ):
205+ class _ApiKey (str ):
206+ pass
209207
210- with pytest .raises (HyperbrowserError , match = "Failed to normalize api_key" ) as exc_info :
211- client_class (api_key = _BrokenStripApiKey ("test-key" ))
212-
213- assert isinstance (exc_info .value .original_error , RuntimeError )
214-
215-
216- @pytest .mark .parametrize ("client_class" , [Hyperbrowser , AsyncHyperbrowser ])
217- def test_client_preserves_hyperbrowser_api_key_strip_errors (client_class ):
218- class _BrokenStripApiKey (str ):
219- def strip (self , chars = None ): # type: ignore[override]
220- _ = chars
221- raise HyperbrowserError ("custom strip failure" )
222-
223- with pytest .raises (HyperbrowserError , match = "custom strip failure" ) as exc_info :
224- client_class (api_key = _BrokenStripApiKey ("test-key" ))
225-
226- assert exc_info .value .original_error is None
227-
228-
229- @pytest .mark .parametrize ("client_class" , [Hyperbrowser , AsyncHyperbrowser ])
230- def test_client_wraps_non_string_api_key_strip_results (client_class ):
231- class _NonStringStripResultApiKey (str ):
232- def strip (self , chars = None ): # type: ignore[override]
233- _ = chars
234- return object ()
235-
236- with pytest .raises (HyperbrowserError , match = "Failed to normalize api_key" ) as exc_info :
237- client_class (api_key = _NonStringStripResultApiKey ("test-key" ))
238-
239- assert isinstance (exc_info .value .original_error , TypeError )
240-
241-
242- @pytest .mark .parametrize ("client_class" , [Hyperbrowser , AsyncHyperbrowser ])
243- def test_client_wraps_api_key_string_subclass_strip_results (client_class ):
244- class _BrokenLengthApiKey (str ):
245- class _NormalizedKey (str ):
246- pass
247-
248- def strip (self , chars = None ): # type: ignore[override]
249- _ = chars
250- return self ._NormalizedKey ("test-key" )
251-
252- with pytest .raises (HyperbrowserError , match = "Failed to normalize api_key" ) as exc_info :
253- client_class (api_key = _BrokenLengthApiKey ("test-key" ))
254-
255- assert isinstance (exc_info .value .original_error , TypeError )
208+ with pytest .raises (HyperbrowserError , match = "api_key must be a string" ):
209+ client_class (api_key = _ApiKey ("test-key" ))
256210
257211
258212@pytest .mark .parametrize ("client_class" , [Hyperbrowser , AsyncHyperbrowser ])
0 commit comments