Fix configtypes.Perc.to_str()
If we used an int/float in config.py for a Perc value (e.g. zoom.default), to_str() returned int/float instead of str, causing qWarnings and bugs.
This commit is contained in:
parent
f53fd56c3d
commit
a9c1fc665f
@ -847,7 +847,10 @@ class Perc(_Numeric):
|
||||
def to_str(self, value: typing.Union[None, float, int, str]) -> str:
|
||||
if value is None:
|
||||
return ''
|
||||
return value
|
||||
elif isinstance(value, str):
|
||||
return value
|
||||
else:
|
||||
return '{}%'.format(value)
|
||||
|
||||
|
||||
class PercOrInt(_Numeric):
|
||||
|
@ -1113,8 +1113,13 @@ class TestPerc:
|
||||
with pytest.raises(configexc.ValidationError):
|
||||
klass(**kwargs).to_py(val)
|
||||
|
||||
def test_to_str(self, klass):
|
||||
assert klass().to_str('42%') == '42%'
|
||||
@pytest.mark.parametrize('value, expected', [
|
||||
('42%', '42%'),
|
||||
(42, '42%'),
|
||||
(42.5, '42.5%'),
|
||||
])
|
||||
def test_to_str(self, klass, value, expected):
|
||||
assert klass().to_str(value) == expected
|
||||
|
||||
|
||||
class TestPercOrInt:
|
||||
|
Loading…
Reference in New Issue
Block a user