-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move URL tests to a separate file; a few test for equality / inequality
- Loading branch information
Showing
2 changed files
with
51 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |