better error messages if option doesn't exists

This commit is contained in:
Emmanuel Garette 2019-08-03 21:27:36 +02:00
parent cfb4eb3b3c
commit 0dc298dedc
2 changed files with 19 additions and 1 deletions

14
tests/test_simple.py Normal file
View File

@ -0,0 +1,14 @@
from json import loads
from tiramisu_api import Config
from pytest import raises
def test_list_option():
filename = 'tests/data/boolean1.json'
with open(filename, 'r') as fh:
json = loads(fh.read())
#
config = Config(json)
opts = []
raises(AttributeError, "config.option('unknown').value.get()")
raises(AttributeError, "config.option('options.unknown').value.get()")

View File

@ -811,12 +811,16 @@ class Config:
subpaths = path.split('.')[len(root):]
else:
subpaths = path.split('.')
current_subpath = 'root'
for subpath in subpaths:
if root_path:
root_path += '.' + subpath
else:
root_path = subpath
schema = schema['properties'][root_path]
schema = schema['properties'].get(root_path)
if schema is None:
raise AttributeError(_(f'option "{subpath}" inconnue dans l\'optiondescription "{current_subpath}"'))
current_subpath = subpath
return schema
def isleader(self,