Always require 4 values for padding.

This commit is contained in:
Florian Bruhin 2015-08-01 00:29:31 +02:00
parent 22ae0c5bca
commit 451477593f
3 changed files with 6 additions and 12 deletions

View File

@ -537,12 +537,11 @@ def data(readonly=False):
('padding', ('padding',
SettingValue(typ.Padding(), '0,0,5,5'), SettingValue(typ.Padding(), '0,0,5,5'),
"Padding for tabs (single value or 'top, bottom, left, right')."), "Padding for tabs (top, bottom, left, right)."),
('indicator-padding', ('indicator-padding',
SettingValue(typ.Padding(), '2,2,0,4'), SettingValue(typ.Padding(), '2,2,0,4'),
"Padding for indicators (single value or 'top, bottom, left, " "Padding for indicators (top, bottom, left, right)."),
"right')."),
readonly=readonly readonly=readonly
)), )),

View File

@ -1139,7 +1139,7 @@ class Padding(IntList):
try: try:
vals = self.transform(value) vals = self.transform(value)
except (ValueError, TypeError): except (ValueError, TypeError):
raise configexc.ValidationError(value, "must be a list of 1 or 4 " raise configexc.ValidationError(value, "must be a list of 4 "
"integers!") "integers!")
if None in vals and not self.none_ok: if None in vals and not self.none_ok:
raise configexc.ValidationError(value, "items may not be empty!") raise configexc.ValidationError(value, "items may not be empty!")
@ -1152,11 +1152,7 @@ class Padding(IntList):
elems = super().transform(value) elems = super().transform(value)
if elems is None: if elems is None:
return elems return elems
if len(elems) == 1: return PaddingValues(*elems)
val = elems[0]
return PaddingValues(val, val, val, val)
else:
return PaddingValues(*elems)
class Encoding(BaseType): class Encoding(BaseType):

View File

@ -1559,17 +1559,17 @@ class TestPadding:
@pytest.mark.parametrize('val', [ @pytest.mark.parametrize('val', [
'', '',
'0',
'5',
'1,,2,3', '1,,2,3',
'1,2,3,4', '1,2,3,4',
'1, 2, 3, 4', '1, 2, 3, 4',
'0,0,0,0',
]) ])
def test_validate_valid(self, klass, val): def test_validate_valid(self, klass, val):
klass(none_ok=True).validate(val) klass(none_ok=True).validate(val)
@pytest.mark.parametrize('val', [ @pytest.mark.parametrize('val', [
'', '',
'5',
'1,,2,3', '1,,2,3',
'0.5', '0.5',
'-1', '-1',
@ -1584,7 +1584,6 @@ class TestPadding:
@pytest.mark.parametrize('val, expected', [ @pytest.mark.parametrize('val, expected', [
('', None), ('', None),
('5', (5, 5, 5, 5)),
('1,2,3,4', (1, 2, 3, 4)), ('1,2,3,4', (1, 2, 3, 4)),
]) ])
def test_transform(self, klass, val, expected): def test_transform(self, klass, val, expected):