def test_url_is_not_str(): url = URL("http://example.com") assert not isinstance(url, str)
def test_origin(): url = URL("http://*****:*****@example.com:8888/path/to?a=1&b=2") assert URL("http://example.com:8888") == url.origin()
def test_with_path_dots(): url = URL("http://example.com") assert str(url.with_path("/test/.")) == "http://example.com/test/"
def test_div_for_relative_url(): url = URL("a") / "b" assert url.raw_parts == ("a", "b")
def test_div_with_colon_and_at(): url = URL("http://example.com/base") / "path:abc@123" assert url.raw_path == "/base/path:abc@123"
def test_div_with_slash(): url = URL("http://example.com/path/") assert str(url / "to") == "http://example.com/path/to"
def test_div_cleanup_query_and_fragment(): url = URL("http://example.com/path?a=1#frag") assert str(url / "to") == "http://example.com/path/to"
def test_plus_in_path(): url = URL("http://example.com/test/x+y%2Bz/:+%2B/") assert "/test/x+y+z/:++/" == url.path
def test_parent_raw_parts(): url = URL("http://example.com/path/to") assert url.parent.raw_parts == ("/", "path")
def test_relative_raw_name_slash(): url = URL("/") assert "" == url.raw_name
def test_name_non_ascii(): url = URL("http://example.com/путь") assert url.name == "путь"
def test_relative_raw_name_starting_from_slash(): url = URL("/path/to") assert "to" == url.raw_name
def test_relative_raw_name(): url = URL("path/to") assert "to" == url.raw_name
def test_raw_name_root3(): url = URL("http://example.com/") assert "" == url.raw_name
def test_div(): url = URL("http://example.com/path") assert str(url / "to") == "http://example.com/path/to"
def test_double_parent_raw_path(): url = URL("http://example.com/path/to") assert url.parent.parent.raw_path == "/"
def test_repr(): url = URL("http://example.com") assert "URL('http://example.com')" == repr(url)
def test_str(): url = URL("http://example.com:8888/path/to?a=1&b=2") assert str(url) == "http://example.com:8888/path/to?a=1&b=2"
def test_div_path_starting_from_slash_is_forbidden(): url = URL("http://example.com/path/") with pytest.raises(ValueError): url / "/to/others"
def test_empty_parent_raw_path2(): url = URL("http://example.com") assert url.parent.parent.raw_path == "/"
def test_div_for_empty_url(): url = URL() / "a" assert url.raw_parts == ("a", )
def test_clear_fragment_on_getting_parent(): url = URL("http://example.com/path/to#frag") assert URL("http://example.com/path") == url.parent
def test_div_for_relative_url_started_with_slash(): url = URL("/a") / "b" assert url.raw_parts == ("/", "a", "b")
def test_clear_fragment_on_getting_parent_toplevel(): url = URL("http://example.com/#frag") assert URL("http://example.com/") == url.parent
def test_div_with_dots(): url = URL("http://example.com/base") / "../path/./to" assert url.raw_path == "/path/to"
def test_clear_query_on_getting_parent(): url = URL("http://example.com/path/to?a=b") assert URL("http://example.com/path") == url.parent
def test_with_path_encoded(): url = URL("http://example.com") assert str(url.with_path("/test", encoded=True)) == "http://example.com/test"
def test_clear_query_on_getting_parent_toplevel(): url = URL("http://example.com/?a=b") assert URL("http://example.com/") == url.parent
def test_with_path_relative(): url = URL("/path") assert str(url.with_path("/new")) == "/new"
def test_raw_name(): url = URL("http://example.com/path/to#frag") assert "to" == url.raw_name