Test and fix configtypes to_str.

This commit is contained in:
Florian Bruhin 2017-06-15 19:09:08 +02:00
parent 4c2f65819b
commit ecba175b16
2 changed files with 9 additions and 2 deletions

View File

@ -171,7 +171,7 @@ class BaseType:
Arguments: Arguments:
value: The value to check. value: The value to check.
""" """
assert isinstance(value, str) assert isinstance(value, str), value
if not value and not self.none_ok: if not value and not self.none_ok:
raise configexc.ValidationError(value, "may not be empty!") raise configexc.ValidationError(value, "may not be empty!")
if any(ord(c) < 32 or ord(c) == 0x7f for c in value): if any(ord(c) < 32 or ord(c) == 0x7f for c in value):
@ -233,7 +233,7 @@ class BaseType:
""" """
if value is None: if value is None:
return '' return ''
assert isinstance(value, str) assert isinstance(value, str), value
return value return value
def complete(self): def complete(self):
@ -1141,6 +1141,11 @@ class ShellCommand(BaseType):
"{}-placeholder.") "{}-placeholder.")
return value return value
def to_str(self, value):
if not value:
return ''
return json.dumps(value)
class Proxy(BaseType): class Proxy(BaseType):

View File

@ -33,7 +33,9 @@ def test_init():
assert isinstance(configdata.DATA, dict) assert isinstance(configdata.DATA, dict)
assert 'ignore_case' in configdata.DATA assert 'ignore_case' in configdata.DATA
for option in configdata.DATA.values(): for option in configdata.DATA.values():
# Make sure to_py and to_str work
option.typ.to_py(option.default) option.typ.to_py(option.default)
option.typ.to_str(option.default)
def test_init_benchmark(benchmark): def test_init_benchmark(benchmark):