@@ -210,19 +210,14 @@ def test_no_path(self):
210210 assert u .query_string == ""
211211 assert u .fragment == ""
212212
213- @pytest .mark .xfail (
214- # FIXME: remove "no cover" pragmas upon xfail marker deletion
215- reason = "https://github.com/aio-libs/yarl/issues/821" ,
216- raises = ValueError ,
217- )
218213 def test_no_host (self ):
219- u = URL ("//:80 " )
220- assert u .scheme == "" # pragma: no cover
221- assert u .host == "" # pragma: no cover
222- assert u .port == 80 # pragma: no cover
223- assert u .path == "/" # pragma: no cover
224- assert u .query_string == "" # pragma: no cover
225- assert u .fragment == "" # pragma: no cover
214+ u = URL ("//:77 " )
215+ assert u .scheme == ""
216+ assert u .host == ""
217+ assert u .port == 77
218+ assert u .path == "/"
219+ assert u .query_string == ""
220+ assert u .fragment == ""
226221
227222 def test_double_port (self ):
228223 with pytest .raises (ValueError ):
@@ -457,9 +452,19 @@ def test_complex_frag(self):
457452
458453
459454class TestStripEmptyParts :
460- def test_all_empty (self ):
455+ def test_all_empty_http (self ):
461456 with pytest .raises (ValueError ):
462- URL ("//@:?#" )
457+ URL ("http://@:?#" )
458+
459+ def test_all_empty (self ):
460+ u = URL ("//@:?#" )
461+ assert u .scheme == ""
462+ assert u .user is None
463+ assert u .password is None
464+ assert u .host == ""
465+ assert u .path == ""
466+ assert u .query_string == ""
467+ assert u .fragment == ""
463468
464469 def test_path_only (self ):
465470 u = URL ("///path" )
@@ -580,3 +585,22 @@ def test_empty_path(self):
580585 assert u .path == ""
581586 assert u .query_string == ""
582587 assert u .fragment == ""
588+
589+
590+ @pytest .mark .parametrize (
591+ ("scheme" ),
592+ [
593+ ("http" ),
594+ ("https" ),
595+ ("ws" ),
596+ ("wss" ),
597+ ("ftp" ),
598+ ],
599+ )
600+ def test_schemes_that_require_host (scheme : str ) -> None :
601+ """Verify that schemes that require a host raise with empty host."""
602+ expect = (
603+ "Invalid URL: host is required for " f"absolute urls with the { scheme } scheme"
604+ )
605+ with pytest .raises (ValueError , match = expect ):
606+ URL (f"{ scheme } ://:1" )
0 commit comments