From b205ad500b94bcf836ab8d84cdd138316796645b Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 27 Jul 2016 10:31:02 -0400 Subject: [PATCH] Add tests for configtypes.Url --- qutebrowser/config/configtypes.py | 4 +--- tests/unit/config/test_configtypes.py | 28 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index c30f582dd..4907d9f2f 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -1285,9 +1285,7 @@ class Url(BaseType): if not value: return val = self.transform(value) - if val is None: - raise configexc.ValidationError(value, "URL may not be empty!") - elif not val.isValid(): + if not val.isValid(): raise configexc.ValidationError(value, "invalid URL - " "{}".format(val.errorString())) diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index cfb338643..391ae757a 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -1813,6 +1813,34 @@ class TestEncoding: assert klass().transform(val) == expected +class TestUrl: + + """Test Url.""" + + TESTS = { + 'http://qutebrowser.org/': QUrl('http://qutebrowser.org/'), + 'http://heise.de/': QUrl('http://heise.de/'), + '': None, + } + + @pytest.fixture + def klass(self): + return configtypes.Url + + @pytest.mark.parametrize('val', sorted(TESTS)) + def test_validate_valid(self, klass, val): + klass(none_ok=True).validate(val) + + @pytest.mark.parametrize('val', ['', '+']) + def test_validate_invalid(self, klass, val): + with pytest.raises(configexc.ValidationError): + klass().validate(val) + + @pytest.mark.parametrize('val, expected', sorted(TESTS.items())) + def test_transform_single(self, klass, val, expected): + assert klass().transform(val) == expected + + class TestSessionName: """Test SessionName."""