From 685e3ffcfefd2e27d1151292b354a8af5c47b509 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 20 Feb 2018 06:27:15 +0100 Subject: [PATCH] Fix and test UrlPattern/configutils.Values stringification --- qutebrowser/utils/urlmatch.py | 9 ++++++--- tests/unit/config/test_configutils.py | 8 ++++++++ tests/unit/utils/test_urlmatch.py | 13 +++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/qutebrowser/utils/urlmatch.py b/qutebrowser/utils/urlmatch.py index c59db211b..d2f9c4fe6 100644 --- a/qutebrowser/utils/urlmatch.py +++ b/qutebrowser/utils/urlmatch.py @@ -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 diff --git a/tests/unit/config/test_configutils.py b/tests/unit/config/test_configutils.py index 74a85edb2..e961948d5 100644 --- a/tests/unit/config/test_configutils.py +++ b/tests/unit/config/test_configutils.py @@ -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: ' diff --git a/tests/unit/utils/test_urlmatch.py b/tests/unit/utils/test_urlmatch.py index ce300391b..83746dcca 100644 --- a/tests/unit/utils/test_urlmatch.py +++ b/tests/unit/utils/test_urlmatch.py @@ -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