Validate configtypes.Key correctly

This commit is contained in:
Florian Bruhin 2018-02-27 07:56:10 +01:00
parent 612387633d
commit f40f4082ba
2 changed files with 9 additions and 4 deletions

View File

@ -1652,7 +1652,8 @@ class Key(BaseType):
self._basic_py_validation(value, str)
if not value:
return None
#if utils.is_special_key(value):
# value = '<{}>'.format(utils.normalize_keystr(value[1:-1]))
#return value
return keyutils.KeySequence.parse(value)
try:
return keyutils.KeySequence.parse(value)
except keyutils.KeyParseError as e:
raise configexc.ValidationError(value, str(e))

View File

@ -2064,6 +2064,10 @@ class TestKey:
def test_to_py_valid(self, klass, val, expected):
assert klass().to_py(val) == expected
def test_to_py_invalid(self, klass):
with pytest.raises(configexc.ValidationError):
klass().to_py('\U00010000')
@pytest.mark.parametrize('first, second, equal', [
(re.compile('foo'), RegexEq('foo'), True),