Fix and test UrlPattern/configutils.Values stringification

This commit is contained in:
Florian Bruhin 2018-02-20 06:27:15 +01:00
parent 145a21449b
commit 685e3ffcfe
3 changed files with 27 additions and 3 deletions

View File

@ -107,6 +107,12 @@ class UrlPattern:
# pylint: disable=protected-access
return self._to_tuple() == other._to_tuple()
def __repr__(self):
return utils.get_repr(self, pattern=self._pattern, constructor=True)
def __str__(self):
return self._pattern
def _fixup_pattern(self, pattern):
"""Make sure the given pattern is parseable by urllib.parse."""
if pattern.startswith('*:'): # Any scheme, but *:// is unparseable
@ -188,9 +194,6 @@ class UrlPattern:
raise ParseError("Ports are unsupported with {} scheme".format(
self._scheme))
def __repr__(self):
return utils.get_repr(self, pattern=self._pattern, constructor=True)
def _matches_scheme(self, scheme):
return self._scheme is None or self._scheme == scheme

View File

@ -55,6 +55,14 @@ def test_repr(opt, values):
assert repr(values) == expected
def test_str(values):
expected = [
'example.option = global value',
'*://www.example.com/: example.option = example value',
]
assert str(values) == '\n'.join(expected)
def test_str_empty(opt):
values = configutils.Values(opt)
assert str(values) == 'example.option: <unchanged>'

View File

@ -517,3 +517,16 @@ def test_equal(text1, text2, equal):
assert (pat1 == pat2) == equal
assert (hash(pat1) == hash(pat2)) == equal
def test_repr():
pat = urlmatch.UrlPattern('https://www.example.com/')
expected = ("qutebrowser.utils.urlmatch.UrlPattern("
"pattern='https://www.example.com/')")
assert repr(pat) == expected
def test_str():
text = 'https://www.example.com/'
pat = urlmatch.UrlPattern(text)
assert str(pat) == text