Skip to content

Commit

Permalink
Move URL tests to a separate file; a few test for equality / inequality
Browse files Browse the repository at this point in the history
  • Loading branch information
kmike committed Jun 7, 2022
1 parent ea11f3d commit ba4e615
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 29 deletions.
29 changes: 0 additions & 29 deletions tests/test_page_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
51 changes: 51 additions & 0 deletions tests/test_url.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit ba4e615

Please sign in to comment.