@@ -509,6 +509,97 @@ def port(self) -> int:
509509 ClientConfig .normalize_base_url ("https://example.local" )
510510
511511
512+ def test_client_config_normalize_base_url_wraps_hostname_access_errors (
513+ monkeypatch : pytest .MonkeyPatch ,
514+ ):
515+ class _ParsedURL :
516+ scheme = "https"
517+ netloc = "example.local"
518+ query = ""
519+ fragment = ""
520+ username = None
521+ password = None
522+ path = "/api"
523+
524+ @property
525+ def hostname (self ):
526+ raise RuntimeError ("hostname parser exploded" )
527+
528+ @property
529+ def port (self ) -> int :
530+ return 443
531+
532+ monkeypatch .setattr (config_module , "urlparse" , lambda _value : _ParsedURL ())
533+
534+ with pytest .raises (HyperbrowserError , match = "Failed to parse base_url host" ) as exc_info :
535+ ClientConfig .normalize_base_url ("https://example.local" )
536+
537+ assert exc_info .value .original_error is not None
538+
539+
540+ def test_client_config_normalize_base_url_wraps_credential_access_errors (
541+ monkeypatch : pytest .MonkeyPatch ,
542+ ):
543+ class _ParsedURL :
544+ scheme = "https"
545+ netloc = "example.local"
546+ hostname = "example.local"
547+ query = ""
548+ fragment = ""
549+ path = "/api"
550+
551+ @property
552+ def username (self ):
553+ raise RuntimeError ("credential parser exploded" )
554+
555+ @property
556+ def password (self ):
557+ return None
558+
559+ @property
560+ def port (self ) -> int :
561+ return 443
562+
563+ monkeypatch .setattr (config_module , "urlparse" , lambda _value : _ParsedURL ())
564+
565+ with pytest .raises (
566+ HyperbrowserError , match = "Failed to parse base_url credentials"
567+ ) as exc_info :
568+ ClientConfig .normalize_base_url ("https://example.local" )
569+
570+ assert exc_info .value .original_error is not None
571+
572+
573+ def test_client_config_normalize_base_url_preserves_hyperbrowser_hostname_errors (
574+ monkeypatch : pytest .MonkeyPatch ,
575+ ):
576+ class _ParsedURL :
577+ scheme = "https"
578+ netloc = "example.local"
579+ query = ""
580+ fragment = ""
581+ username = None
582+ password = None
583+ path = "/api"
584+
585+ @property
586+ def hostname (self ):
587+ raise HyperbrowserError ("custom hostname parser failure" )
588+
589+ @property
590+ def port (self ) -> int :
591+ return 443
592+
593+ monkeypatch .setattr (config_module , "urlparse" , lambda _value : _ParsedURL ())
594+
595+ with pytest .raises (
596+ HyperbrowserError , match = "custom hostname parser failure"
597+ ) as exc_info :
598+ ClientConfig .normalize_base_url ("https://example.local" )
599+
600+ assert exc_info .value .original_error is None
601+
602+
512603def test_client_config_normalize_base_url_wraps_path_decode_runtime_errors (
513604 monkeypatch : pytest .MonkeyPatch ,
514605):
0 commit comments