urlmatch: Add tests for file://
This commit is contained in:
parent
a2836ba945
commit
45cc1aaeb0
@ -99,6 +99,7 @@ class UrlPattern:
|
|||||||
pattern = 'any:' + pattern[2:]
|
pattern = 'any:' + pattern[2:]
|
||||||
|
|
||||||
# Chromium handles file://foo like file:///foo
|
# Chromium handles file://foo like file:///foo
|
||||||
|
# FIXME This doesn't actually strip the hostname correctly.
|
||||||
if (pattern.startswith('file://') and
|
if (pattern.startswith('file://') and
|
||||||
not pattern.startswith('file:///')):
|
not pattern.startswith('file:///')):
|
||||||
pattern = 'file:///' + pattern[len("file://"):]
|
pattern = 'file:///' + pattern[len("file://"):]
|
||||||
|
@ -281,3 +281,33 @@ class TestMatchAnything:
|
|||||||
])
|
])
|
||||||
def test_special_schemes(pattern, url, expected):
|
def test_special_schemes(pattern, url, expected):
|
||||||
assert urlmatch.UrlPattern(pattern).matches(QUrl(url)) == expected
|
assert urlmatch.UrlPattern(pattern).matches(QUrl(url)) == expected
|
||||||
|
|
||||||
|
|
||||||
|
class TestFileScheme:
|
||||||
|
|
||||||
|
@pytest.fixture(params=[
|
||||||
|
'file:///foo*',
|
||||||
|
'file://foo*',
|
||||||
|
# FIXME This doesn't pass all tests
|
||||||
|
pytest.param('file://localhost/foo*', marks=pytest.mark.skip(
|
||||||
|
reason="We're not handling this correctly in all cases"))
|
||||||
|
])
|
||||||
|
def up(self, request):
|
||||||
|
return urlmatch.UrlPattern(request.param)
|
||||||
|
|
||||||
|
def test_attrs(self, up):
|
||||||
|
assert up._scheme == 'file'
|
||||||
|
assert up._host is None
|
||||||
|
assert not up._match_subdomains
|
||||||
|
assert not up._match_all
|
||||||
|
assert up._path == '/foo*'
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('url, expected', [
|
||||||
|
("file://foo", False),
|
||||||
|
("file://foobar", False),
|
||||||
|
("file:///foo", True),
|
||||||
|
("file:///foobar", True),
|
||||||
|
("file://localhost/foo", True),
|
||||||
|
])
|
||||||
|
def test_urls(self, up, url, expected):
|
||||||
|
assert up.matches(QUrl(url)) == expected
|
||||||
|
Loading…
Reference in New Issue
Block a user