Remove unnecessary List subclasses
This commit is contained in:
parent
9e86933913
commit
083baf1222
@ -254,7 +254,7 @@ def data(readonly=False):
|
|||||||
|
|
||||||
('ui', sect.KeyValue(
|
('ui', sect.KeyValue(
|
||||||
('zoom-levels',
|
('zoom-levels',
|
||||||
SettingValue(typ.PercList(minval=0),
|
SettingValue(typ.List(typ.Perc(minval=0)),
|
||||||
'25%,33%,50%,67%,75%,90%,100%,110%,125%,150%,175%,'
|
'25%,33%,50%,67%,75%,90%,100%,110%,125%,150%,175%,'
|
||||||
'200%,250%,300%,400%,500%'),
|
'200%,250%,300%,400%,500%'),
|
||||||
"The available zoom levels, separated by commas."),
|
"The available zoom levels, separated by commas."),
|
||||||
@ -826,7 +826,7 @@ def data(readonly=False):
|
|||||||
|
|
||||||
('host-block-lists',
|
('host-block-lists',
|
||||||
SettingValue(
|
SettingValue(
|
||||||
typ.UrlList(none_ok=True),
|
typ.List(typ.Url(), none_ok=True),
|
||||||
'http://www.malwaredomainlist.com/hostslist/hosts.txt,'
|
'http://www.malwaredomainlist.com/hostslist/hosts.txt,'
|
||||||
'http://someonewhocares.org/hosts/hosts,'
|
'http://someonewhocares.org/hosts/hosts,'
|
||||||
'http://winhelp2002.mvps.org/hosts.zip,'
|
'http://winhelp2002.mvps.org/hosts.zip,'
|
||||||
@ -916,13 +916,13 @@ def data(readonly=False):
|
|||||||
"auto-follow."),
|
"auto-follow."),
|
||||||
|
|
||||||
('next-regexes',
|
('next-regexes',
|
||||||
SettingValue(typ.RegexList(flags=re.IGNORECASE),
|
SettingValue(typ.List(typ.Regex(flags=re.IGNORECASE)),
|
||||||
r'\bnext\b,\bmore\b,\bnewer\b,\b[>→≫]\b,\b(>>|»)\b,'
|
r'\bnext\b,\bmore\b,\bnewer\b,\b[>→≫]\b,\b(>>|»)\b,'
|
||||||
r'\bcontinue\b'),
|
r'\bcontinue\b'),
|
||||||
"A comma-separated list of regexes to use for 'next' links."),
|
"A comma-separated list of regexes to use for 'next' links."),
|
||||||
|
|
||||||
('prev-regexes',
|
('prev-regexes',
|
||||||
SettingValue(typ.RegexList(flags=re.IGNORECASE),
|
SettingValue(typ.List(typ.Regex(flags=re.IGNORECASE)),
|
||||||
r'\bprev(ious)?\b,\bback\b,\bolder\b,\b[<←≪]\b,'
|
r'\bprev(ious)?\b,\bback\b,\bolder\b,\b[<←≪]\b,'
|
||||||
r'\b(<<|«)\b'),
|
r'\b(<<|«)\b'),
|
||||||
"A comma-separated list of regexes to use for 'prev' links."),
|
"A comma-separated list of regexes to use for 'prev' links."),
|
||||||
|
@ -461,15 +461,6 @@ class Int(BaseType):
|
|||||||
"smaller!".format(self.maxval))
|
"smaller!".format(self.maxval))
|
||||||
|
|
||||||
|
|
||||||
class IntList(List):
|
|
||||||
|
|
||||||
"""Base class for an int-list setting."""
|
|
||||||
|
|
||||||
def __init__(self, none_ok=False, valid_values=None):
|
|
||||||
super().__init__(Int(none_ok=none_ok), none_ok=none_ok)
|
|
||||||
self.inner_type.valid_values = valid_values
|
|
||||||
|
|
||||||
|
|
||||||
class Float(BaseType):
|
class Float(BaseType):
|
||||||
|
|
||||||
"""Base class for a float setting.
|
"""Base class for a float setting.
|
||||||
@ -550,19 +541,6 @@ class Perc(BaseType):
|
|||||||
"less!".format(self.maxval))
|
"less!".format(self.maxval))
|
||||||
|
|
||||||
|
|
||||||
class PercList(List):
|
|
||||||
|
|
||||||
"""Base class for a list of percentages.
|
|
||||||
|
|
||||||
Attributes:
|
|
||||||
minval: Minimum value (inclusive).
|
|
||||||
maxval: Maximum value (inclusive).
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, minval=None, maxval=None, none_ok=False):
|
|
||||||
super().__init__(Perc(minval, maxval, none_ok), none_ok=none_ok)
|
|
||||||
|
|
||||||
|
|
||||||
class PercOrInt(BaseType):
|
class PercOrInt(BaseType):
|
||||||
|
|
||||||
"""Percentage or integer.
|
"""Percentage or integer.
|
||||||
@ -845,14 +823,6 @@ class Regex(BaseType):
|
|||||||
return re.compile(value, self.flags)
|
return re.compile(value, self.flags)
|
||||||
|
|
||||||
|
|
||||||
class RegexList(List):
|
|
||||||
|
|
||||||
"""A list of regexes."""
|
|
||||||
|
|
||||||
def __init__(self, flags=0, none_ok=False):
|
|
||||||
super().__init__(Regex(flags, none_ok), none_ok=none_ok)
|
|
||||||
|
|
||||||
|
|
||||||
class File(BaseType):
|
class File(BaseType):
|
||||||
|
|
||||||
"""A file on the local filesystem."""
|
"""A file on the local filesystem."""
|
||||||
@ -1171,10 +1141,14 @@ PaddingValues = collections.namedtuple('PaddingValues', ['top', 'bottom',
|
|||||||
'left', 'right'])
|
'left', 'right'])
|
||||||
|
|
||||||
|
|
||||||
class Padding(IntList):
|
class Padding(List):
|
||||||
|
|
||||||
"""Setting for paddings around elements."""
|
"""Setting for paddings around elements."""
|
||||||
|
|
||||||
|
def __init__(self, none_ok=False, valid_values=None):
|
||||||
|
super().__init__(Int(none_ok=none_ok), none_ok=none_ok)
|
||||||
|
self.inner_type.valid_values = valid_values
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
self._basic_validation(value)
|
self._basic_validation(value)
|
||||||
if not value:
|
if not value:
|
||||||
@ -1351,15 +1325,6 @@ class Url(BaseType):
|
|||||||
"{}".format(val.errorString()))
|
"{}".format(val.errorString()))
|
||||||
|
|
||||||
|
|
||||||
class UrlList(List):
|
|
||||||
|
|
||||||
"""A list of URLs."""
|
|
||||||
|
|
||||||
def __init__(self, none_ok=False, valid_values=None):
|
|
||||||
super().__init__(Url(), none_ok)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class HeaderDict(BaseType):
|
class HeaderDict(BaseType):
|
||||||
|
|
||||||
"""A JSON-like dictionary for custom HTTP headers."""
|
"""A JSON-like dictionary for custom HTTP headers."""
|
||||||
|
@ -595,37 +595,6 @@ class TestInt:
|
|||||||
assert klass(none_ok=True).transform(val) == expected
|
assert klass(none_ok=True).transform(val) == expected
|
||||||
|
|
||||||
|
|
||||||
class TestIntList:
|
|
||||||
|
|
||||||
"""Test IntList."""
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def klass(self):
|
|
||||||
return configtypes.IntList
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('val', ['', '1,2', '1', '23,1337'])
|
|
||||||
def test_validate_valid(self, klass, val):
|
|
||||||
klass(none_ok=True).validate(val)
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('val', ['', '1,,2', '23,foo,1337'])
|
|
||||||
def test_validate_invalid(self, klass, val):
|
|
||||||
with pytest.raises(configexc.ValidationError):
|
|
||||||
klass().validate(val)
|
|
||||||
|
|
||||||
def test_invalid_empty_value_none_ok(self, klass):
|
|
||||||
klass(none_ok=True).validate('1,,2')
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('val, expected', [
|
|
||||||
('1', [1]),
|
|
||||||
('23,42', [23, 42]),
|
|
||||||
('', None),
|
|
||||||
('1,,2', [1, None, 2]),
|
|
||||||
('23, 42', [23, 42]),
|
|
||||||
])
|
|
||||||
def test_transform(self, klass, val, expected):
|
|
||||||
assert klass().transform(val) == expected
|
|
||||||
|
|
||||||
|
|
||||||
class TestFloat:
|
class TestFloat:
|
||||||
|
|
||||||
"""Test Float."""
|
"""Test Float."""
|
||||||
@ -718,52 +687,6 @@ class TestPerc:
|
|||||||
assert klass().transform(val) == expected
|
assert klass().transform(val) == expected
|
||||||
|
|
||||||
|
|
||||||
class TestPercList:
|
|
||||||
|
|
||||||
"""Test PercList."""
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def klass(self):
|
|
||||||
return configtypes.PercList
|
|
||||||
|
|
||||||
def test_minval_gt_maxval(self, klass):
|
|
||||||
with pytest.raises(ValueError):
|
|
||||||
klass(minval=2, maxval=1)
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('kwargs, val', [
|
|
||||||
({}, '23%,42%,1337%'),
|
|
||||||
({'minval': 2}, '2%,3%'),
|
|
||||||
({'maxval': 2}, '1%,2%'),
|
|
||||||
({'minval': 2, 'maxval': 3}, '2%,3%'),
|
|
||||||
({'none_ok': True}, '42%,,23%'),
|
|
||||||
({'none_ok': True}, ''),
|
|
||||||
])
|
|
||||||
def test_validate_valid(self, klass, kwargs, val):
|
|
||||||
klass(**kwargs).validate(val)
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('kwargs, val', [
|
|
||||||
({}, '23%,42,1337%'),
|
|
||||||
({'minval': 2}, '1%,2%'),
|
|
||||||
({'maxval': 2}, '2%,3%'),
|
|
||||||
({'minval': 2, 'maxval': 3}, '1%,2%'),
|
|
||||||
({'minval': 2, 'maxval': 3}, '3%,4%'),
|
|
||||||
({}, '42%,,23%'),
|
|
||||||
({}, ''),
|
|
||||||
])
|
|
||||||
def test_validate_invalid(self, klass, kwargs, val):
|
|
||||||
with pytest.raises(configexc.ValidationError):
|
|
||||||
klass(**kwargs).validate(val)
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('val, expected', [
|
|
||||||
('', None),
|
|
||||||
('1337%', [1337]),
|
|
||||||
('23%,42%,1337%', [23, 42, 1337]),
|
|
||||||
('23%,,42%', [23, None, 42]),
|
|
||||||
])
|
|
||||||
def test_transform(self, klass, val, expected):
|
|
||||||
assert klass().transform(val) == expected
|
|
||||||
|
|
||||||
|
|
||||||
class TestPercOrInt:
|
class TestPercOrInt:
|
||||||
|
|
||||||
"""Test PercOrInt."""
|
"""Test PercOrInt."""
|
||||||
@ -1239,59 +1162,6 @@ class TestRegex:
|
|||||||
klass().validate('foo')
|
klass().validate('foo')
|
||||||
|
|
||||||
|
|
||||||
class TestRegexList:
|
|
||||||
|
|
||||||
"""Test RegexList."""
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def klass(self):
|
|
||||||
return configtypes.RegexList
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('val', [
|
|
||||||
r'(foo|bar),[abcd]?,1337{42}',
|
|
||||||
r'(foo|bar),,1337{42}',
|
|
||||||
r'',
|
|
||||||
])
|
|
||||||
def test_validate_valid(self, klass, val):
|
|
||||||
klass(none_ok=True).validate(val)
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('val', [
|
|
||||||
r'(foo|bar),,1337{42}',
|
|
||||||
r'',
|
|
||||||
r'(foo|bar),((),1337{42}',
|
|
||||||
r'(' * 500,
|
|
||||||
], ids=['empty value', 'empty', 'unmatched parens', 'too many parens'])
|
|
||||||
def test_validate_invalid(self, klass, val):
|
|
||||||
with pytest.raises(configexc.ValidationError):
|
|
||||||
klass().validate(val)
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('val', [
|
|
||||||
r'foo\Xbar',
|
|
||||||
r'foo\Cbar',
|
|
||||||
])
|
|
||||||
def test_validate_maybe_valid(self, klass, val):
|
|
||||||
"""Those values are valid on some Python versions (and systems?).
|
|
||||||
|
|
||||||
On others, they raise a DeprecationWarning because of an invalid
|
|
||||||
escape. This tests makes sure this gets translated to a
|
|
||||||
ValidationError.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
klass().validate(val)
|
|
||||||
except configexc.ValidationError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('val, expected', [
|
|
||||||
('foo', [RegexEq('foo')]),
|
|
||||||
('foo,bar,baz', [RegexEq('foo'), RegexEq('bar'),
|
|
||||||
RegexEq('baz')]),
|
|
||||||
('foo,,bar', [RegexEq('foo'), None, RegexEq('bar')]),
|
|
||||||
('', None),
|
|
||||||
])
|
|
||||||
def test_transform(self, klass, val, expected):
|
|
||||||
assert klass().transform(val) == expected
|
|
||||||
|
|
||||||
|
|
||||||
def unrequired_class(**kwargs):
|
def unrequired_class(**kwargs):
|
||||||
return configtypes.File(required=False, **kwargs)
|
return configtypes.File(required=False, **kwargs)
|
||||||
|
|
||||||
@ -1976,44 +1846,6 @@ class TestEncoding:
|
|||||||
assert klass().transform(val) == expected
|
assert klass().transform(val) == expected
|
||||||
|
|
||||||
|
|
||||||
class TestUrlList:
|
|
||||||
|
|
||||||
"""Test UrlList."""
|
|
||||||
|
|
||||||
TESTS = {
|
|
||||||
'http://qutebrowser.org/': [QUrl('http://qutebrowser.org/')],
|
|
||||||
'http://qutebrowser.org/,http://heise.de/':
|
|
||||||
[QUrl('http://qutebrowser.org/'), QUrl('http://heise.de/')],
|
|
||||||
'': None,
|
|
||||||
}
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def klass(self):
|
|
||||||
return configtypes.UrlList
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('val', sorted(TESTS))
|
|
||||||
def test_validate_valid(self, klass, val):
|
|
||||||
klass(none_ok=True).validate(val)
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('val', [
|
|
||||||
'',
|
|
||||||
'foo,,bar',
|
|
||||||
'+', # invalid URL with QUrl.fromUserInput
|
|
||||||
])
|
|
||||||
def test_validate_invalid(self, klass, val):
|
|
||||||
with pytest.raises(configexc.ValidationError):
|
|
||||||
klass().validate(val)
|
|
||||||
|
|
||||||
def test_validate_empty_item(self, klass):
|
|
||||||
"""Test validate with empty item and none_ok = False."""
|
|
||||||
with pytest.raises(configexc.ValidationError):
|
|
||||||
klass().validate('foo,,bar')
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('val, expected', sorted(TESTS.items()))
|
|
||||||
def test_transform_single(self, klass, val, expected):
|
|
||||||
assert klass().transform(val) == expected
|
|
||||||
|
|
||||||
|
|
||||||
class TestSessionName:
|
class TestSessionName:
|
||||||
|
|
||||||
"""Test SessionName."""
|
"""Test SessionName."""
|
||||||
|
Loading…
Reference in New Issue
Block a user