@@ -767,6 +767,96 @@ def test_div_with_dots():
767767 assert url .raw_path == "/path/to"
768768
769769
770+ # joinpath
771+
772+
773+ def test_joinpath_root ():
774+ url = URL ("http://example.com" )
775+ assert str (url .joinpath ("path" , "to" )) == "http://example.com/path/to"
776+
777+
778+ def test_joinpath_root_with_slash ():
779+ url = URL ("http://example.com/" )
780+ assert str (url .joinpath ("path" , "to" )) == "http://example.com/path/to"
781+
782+
783+ def test_joinpath ():
784+ url = URL ("http://example.com/path" )
785+ assert str (url .joinpath ("to" )) == "http://example.com/path/to"
786+
787+
788+ def test_joinpath_with_slash ():
789+ url = URL ("http://example.com/path/" )
790+ assert str (url .joinpath ("to" )) == "http://example.com/path/to"
791+
792+
793+ def test_joinpath_path_starting_from_slash_is_forbidden ():
794+ url = URL ("http://example.com/path/" )
795+ with pytest .raises (ValueError ):
796+ assert url .joinpath ("/to/others" )
797+
798+
799+ def test_joinpath_cleanup_query_and_fragment ():
800+ url = URL ("http://example.com/path?a=1#frag" )
801+ assert str (url .joinpath ("to" )) == "http://example.com/path/to"
802+
803+
804+ def test_joinpath_for_empty_url ():
805+ url = URL ().joinpath ("a" )
806+ assert url .raw_parts == ("a" ,)
807+
808+
809+ def test_joinpath_for_relative_url ():
810+ url = URL ("a" ).joinpath ("b" )
811+ assert url .raw_parts == ("a" , "b" )
812+
813+
814+ def test_joinpath_for_relative_url_started_with_slash ():
815+ url = URL ("/a" ).joinpath ("b" )
816+ assert url .raw_parts == ("/" , "a" , "b" )
817+
818+
819+ def test_joinpath_non_ascii ():
820+ url = URL ("http://example.com/сюда" )
821+ url2 = url .joinpath ("туда" )
822+ assert url2 .path == "/сюда/туда"
823+ assert url2 .raw_path == "/%D1%81%D1%8E%D0%B4%D0%B0/%D1%82%D1%83%D0%B4%D0%B0"
824+ assert url2 .parts == ("/" , "сюда" , "туда" )
825+ assert url2 .raw_parts == (
826+ "/" ,
827+ "%D1%81%D1%8E%D0%B4%D0%B0" ,
828+ "%D1%82%D1%83%D0%B4%D0%B0" ,
829+ )
830+
831+
832+ def test_joinpath_percent_encoded ():
833+ url = URL ("http://example.com/path" )
834+ url2 = url .joinpath ("%cf%80" )
835+ assert url2 .path == "/path/%cf%80"
836+ assert url2 .raw_path == "/path/%25cf%2580"
837+ assert url2 .parts == ("/" , "path" , "%cf%80" )
838+ assert url2 .raw_parts == ("/" , "path" , "%25cf%2580" )
839+
840+
841+ def test_joinpath_encoded_percent_encoded ():
842+ url = URL ("http://example.com/path" )
843+ url2 = url .joinpath ("%cf%80" , encoded = True )
844+ assert url2 .path == "/path/π"
845+ assert url2 .raw_path == "/path/%cf%80"
846+ assert url2 .parts == ("/" , "path" , "π" )
847+ assert url2 .raw_parts == ("/" , "path" , "%cf%80" )
848+
849+
850+ def test_joinpath_with_colon_and_at ():
851+ url = URL ("http://example.com/base" ).joinpath ("path:abc@123" )
852+ assert url .raw_path == "/base/path:abc@123"
853+
854+
855+ def test_joinpath_with_dots ():
856+ url = URL ("http://example.com/base" ).joinpath (".." , "path" , "." , "to" )
857+ assert url .raw_path == "/path/to"
858+
859+
770860# with_path
771861
772862
0 commit comments