@@ -1081,6 +1081,42 @@ def test_netloc_slashes(self):
10811081
10821082 return
10831083
1084+ def test_rooted_to_relative (self ):
1085+ # type: () -> None
1086+ """
1087+ On host-relative URLs, the C{rooted} flag can be updated to indicate
1088+ that the path should no longer be treated as absolute.
1089+ """
1090+ a = URL (path = ['hello' ])
1091+ self .assertEqual (a .to_text (), 'hello' )
1092+ b = a .replace (rooted = True )
1093+ self .assertEqual (b .to_text (), '/hello' )
1094+ self .assertNotEqual (a , b )
1095+
1096+ def test_autorooted (self ):
1097+ # type: () -> None
1098+ """
1099+ The C{rooted} flag can be updated in some cases, but it cannot be made
1100+ to conflict with other facts surrounding the URL; for example, all URLs
1101+ involving an authority (host) are inherently rooted because it is not
1102+ syntactically possible to express otherwise; also, once an unrooted URL
1103+ gains a path that starts with an empty string, that empty string is
1104+ elided and it becomes rooted, because these cases are syntactically
1105+ indistinguisable in real URL text.
1106+ """
1107+ relative_path_rooted = URL (path = ['' , 'foo' ], rooted = False )
1108+ self .assertEqual (relative_path_rooted .rooted , True )
1109+ relative_flag_rooted = URL (path = ['foo' ], rooted = True )
1110+ self .assertEqual (relative_flag_rooted .rooted , True )
1111+ self .assertEqual (relative_path_rooted , relative_flag_rooted )
1112+
1113+ attempt_unrooted_absolute = URL (host = "foo" , path = ['bar' ], rooted = False )
1114+ normal_absolute = URL (host = "foo" , path = ["bar" ])
1115+ attempted_rooted_replacement = normal_absolute .replace (rooted = True )
1116+ self .assertEqual (attempt_unrooted_absolute , normal_absolute )
1117+ self .assertEqual (normal_absolute .rooted , True )
1118+ self .assertEqual (attempt_unrooted_absolute .rooted , True )
1119+
10841120 def test_wrong_constructor (self ):
10851121 # type: () -> None
10861122 with self .assertRaises (ValueError ):
0 commit comments