diff --git a/tests/test_page_inputs.py b/tests/test_page_inputs.py index 57be5b64..a87a9867 100644 --- a/tests/test_page_inputs.py +++ b/tests/test_page_inputs.py @@ -6,7 +6,6 @@ import parsel from web_poet import RequestUrl, ResponseUrl -from web_poet._base import _Url from web_poet.page_inputs import ( HttpRequest, HttpResponse, @@ -445,31 +444,3 @@ def test_browser_html(): assert html.xpath("//p/text()").getall() == ["Hello, ", "world!"] assert html.css("p::text").getall() == ["Hello, ", "world!"] assert isinstance(html.selector, parsel.Selector) - - -def test_url_base_class(): - url_str = "http://example.com" - url = _Url(url_str) - assert str(url) == url_str - assert repr(url) == "_Url('http://example.com')" - - with pytest.raises(TypeError): - _Url(123) - - -def test_url_subclass(): - url_str = "http://example.com" - - class MyUrl(_Url): - pass - - class MyUrl2(_Url): - pass - - url = MyUrl(url_str) - assert str(url) == url_str - assert url._url == url_str - assert repr(url) == "MyUrl('http://example.com')" - - url2 = MyUrl2(url) - assert str(url2) == str(url) diff --git a/tests/test_url.py b/tests/test_url.py new file mode 100644 index 00000000..fba26a9c --- /dev/null +++ b/tests/test_url.py @@ -0,0 +1,51 @@ +import pytest + +from web_poet._base import _Url +from web_poet import RequestUrl, ResponseUrl + + +def test_url_base_class(): + url_str = "http://example.com" + url = _Url(url_str) + assert str(url) == url_str + assert repr(url) == "_Url('http://example.com')" + + +def test_url_init_validation(): + with pytest.raises(TypeError): + _Url(123) + + +def test_url_subclasses(): + url_str = "http://example.com" + + class MyUrl(_Url): + pass + + class MyUrl2(_Url): + pass + + url = MyUrl(url_str) + assert str(url) == url_str + assert url._url == url_str + assert repr(url) == "MyUrl('http://example.com')" + + url2 = MyUrl2(url) + assert str(url2) == str(url) + + +@pytest.mark.parametrize('url_cls', [_Url, RequestUrl, ResponseUrl]) +def test_str_equality(url_cls): + url_str = "http://example.com#foo" + url = url_cls(url_str) + assert url != url_str + assert str(url) == url_str + + +def test_url_classes_eq(): + url_str = "http://example.com#foo" + request_url = RequestUrl(url_str) + response_url = ResponseUrl(url_str) + + assert request_url != response_url + assert str(request_url) == str(response_url)