diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 5110a6090..238aad78e 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -135,7 +135,7 @@ def data(readonly=False): "Whether to find text on a page case-insensitively."), ('startpage', - SettingValue(typ.List(), 'https://duckduckgo.com'), + SettingValue(typ.BaseList(), 'https://duckduckgo.com'), "The default page(s) to open at the start, separated by commas."), ('default-page', @@ -352,7 +352,7 @@ def data(readonly=False): "(requires restart)"), ('keyhint-blacklist', - SettingValue(typ.List(none_ok=True), ''), + SettingValue(typ.BaseList(none_ok=True), ''), "Keychains that shouldn't be shown in the keyhint dialog\n\n" "Globs are supported, so ';*' will blacklist all keychains" "starting with ';'. Use '*' to disable keyhints"), @@ -845,7 +845,7 @@ def data(readonly=False): "Whether host blocking is enabled."), ('host-blocking-whitelist', - SettingValue(typ.List(none_ok=True), 'piwik.org'), + SettingValue(typ.BaseList(none_ok=True), 'piwik.org'), "List of domains that should always be loaded, despite being " "ad-blocked.\n\n" "Domains may contain * and ? wildcards and are otherwise " diff --git a/qutebrowser/config/configtypes.py b/qutebrowser/config/configtypes.py index c5d04c2f7..62a72587e 100644 --- a/qutebrowser/config/configtypes.py +++ b/qutebrowser/config/configtypes.py @@ -299,7 +299,7 @@ class UniqueCharString(String): value, "String contains duplicate values!") -class GenList(BaseType): +class List(BaseType): """Base class for a (string-)list setting.""" @@ -311,19 +311,20 @@ class GenList(BaseType): if not value: return None else: - return [self.inner_type.transform(v) for v in value.split(',')] + return [self.inner_type.transform(v.strip()) + for v in value.split(',')] def validate(self, value): self._basic_validation(value) if not value: return for val in value.split(','): - self.inner_type.validate(val) + self.inner_type.validate(val.strip()) -class List(GenList): +class BaseList(List): - """Base class for a (string-)list setting.""" + """Base class for a list using BaseType.""" def __init__(self, none_ok=False, valid_values=None): super().__init__(BaseType(), none_ok) @@ -334,13 +335,9 @@ class List(GenList): super().validate(value) else: self._basic_validation(value) - if value: - vals = super().transform(value) - if None in vals: - raise configexc.ValidationError(value, "may not be empty!") -class FlagList(GenList): +class FlagList(BaseList): """Base class for a list setting that contains one or more flags. @@ -348,17 +345,10 @@ class FlagList(GenList): self.valid_values (if not empty). """ - def __init__(self, none_ok=False, valid_values=None): - super().__init__(BaseType(), none_ok) - self.inner_type.valid_values = valid_values - combinable_values = None def validate(self, value): - if self.inner_type.valid_values is not None: - super().validate(value) - else: - self._basic_validation(value) + super().validate(value) if not value: return vals = super().transform(value) @@ -471,7 +461,7 @@ class Int(BaseType): "smaller!".format(self.maxval)) -class IntList(GenList): +class IntList(List): """Base class for an int-list setting.""" @@ -560,7 +550,7 @@ class Perc(BaseType): "less!".format(self.maxval)) -class PercList(GenList): +class PercList(List): """Base class for a list of percentages. @@ -855,7 +845,7 @@ class Regex(BaseType): return re.compile(value, self.flags) -class RegexList(GenList): +class RegexList(List): """A list of regexes.""" @@ -1009,7 +999,7 @@ class WebKitBytes(BaseType): return int(val) * multiplicator -class WebKitBytesList(GenList): +class WebKitBytesList(List): """A size with an optional suffix. @@ -1361,7 +1351,7 @@ class Url(BaseType): "{}".format(val.errorString())) -class UrlList(GenList): +class UrlList(List): """A list of URLs.""" diff --git a/tests/unit/config/test_configtypes.py b/tests/unit/config/test_configtypes.py index 97cf3f41c..e0c8293cb 100644 --- a/tests/unit/config/test_configtypes.py +++ b/tests/unit/config/test_configtypes.py @@ -354,18 +354,31 @@ class TestString: assert klass(valid_values=valid_values).complete() == expected +class ListSubclass(configtypes.List): + + """A subclass of List which we use in tests. Similar to FlagList. + + Valid values are 'foo', 'bar' and 'baz'. + """ + + def __init__(self, none_ok_inner=False, none_ok_outer=False): + super().__init__(configtypes.BaseType(none_ok_inner), none_ok_outer) + self.inner_type.valid_values = configtypes.ValidValues('foo', + 'bar', 'baz') + + class TestList: """Test List.""" @pytest.fixture def klass(self): - return configtypes.List + return ListSubclass @pytest.mark.parametrize('val', ['', 'foo', 'foo,bar', 'foo, bar']) def test_validate_valid(self, klass, val): - klass(none_ok=True).validate(val) + klass(none_ok_outer=True).validate(val) @pytest.mark.parametrize('val', ['', 'foo,,bar']) def test_validate_invalid(self, klass, val): @@ -374,14 +387,14 @@ class TestList: def test_invalid_empty_value_none_ok(self, klass): with pytest.raises(configexc.ValidationError): - klass(none_ok=True).validate('foo,,bar') + klass(none_ok_outer=True).validate('foo,,bar') + klass(none_ok_inner=True).validate('') @pytest.mark.parametrize('val, expected', [ ('foo', ['foo']), ('foo,bar,baz', ['foo', 'bar', 'baz']), ('', None), - # Not implemented yet - pytest.mark.xfail(('foo, bar', ['foo', 'bar'])), + ('foo, bar', ['foo', 'bar']) ]) def test_transform(self, klass, val, expected): assert klass().transform(val) == expected diff --git a/tests/unit/config/test_configtypes_hypothesis.py b/tests/unit/config/test_configtypes_hypothesis.py index 477df599d..a5b40c417 100644 --- a/tests/unit/config/test_configtypes_hypothesis.py +++ b/tests/unit/config/test_configtypes_hypothesis.py @@ -36,7 +36,7 @@ def gen_classes(): pass elif member is configtypes.MappingType: pass - elif member is configtypes.GenList: + elif member is configtypes.List: pass elif member is configtypes.FormatString: yield functools.partial(member, fields=['a', 'b'])