Compare commits
5 Commits
release/0.
...
release/0.
Author | SHA1 | Date | |
---|---|---|---|
039e2e6b7b | |||
0dc298dedc | |||
cfb4eb3b3c | |||
a7f470c837 | |||
76d63eb707 |
14
tests/test_simple.py
Normal file
14
tests/test_simple.py
Normal 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()")
|
@ -1,5 +1,5 @@
|
|||||||
from .api import Config
|
from .api import Config
|
||||||
|
|
||||||
__version__ = "0.1"
|
__version__ = "0.2"
|
||||||
__all__ = ('Config',)
|
__all__ = ('Config',)
|
||||||
|
|
||||||
|
@ -75,6 +75,12 @@ class TiramisuOptionOption:
|
|||||||
self.schema = schema
|
self.schema = schema
|
||||||
|
|
||||||
def doc(self):
|
def doc(self):
|
||||||
|
description = self.description()
|
||||||
|
if not description:
|
||||||
|
return self.name()
|
||||||
|
return description
|
||||||
|
|
||||||
|
def description(self):
|
||||||
if self.issymlinkoption():
|
if self.issymlinkoption():
|
||||||
schema = self.config.get_schema(self.schema['opt_path'])
|
schema = self.config.get_schema(self.schema['opt_path'])
|
||||||
else:
|
else:
|
||||||
@ -805,12 +811,16 @@ class Config:
|
|||||||
subpaths = path.split('.')[len(root):]
|
subpaths = path.split('.')[len(root):]
|
||||||
else:
|
else:
|
||||||
subpaths = path.split('.')
|
subpaths = path.split('.')
|
||||||
|
current_subpath = 'root'
|
||||||
for subpath in subpaths:
|
for subpath in subpaths:
|
||||||
if root_path:
|
if root_path:
|
||||||
root_path += '.' + subpath
|
root_path += '.' + subpath
|
||||||
else:
|
else:
|
||||||
root_path = subpath
|
root_path = subpath
|
||||||
schema = schema['properties'][root_path]
|
schema = schema['properties'].get(root_path)
|
||||||
|
if schema is None:
|
||||||
|
raise AttributeError(_('option "{0}" inconnue dans l\'optiondescription "{1}"').format(subpath, current_subpath))
|
||||||
|
current_subpath = subpath
|
||||||
return schema
|
return schema
|
||||||
|
|
||||||
def isleader(self,
|
def isleader(self,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
try:
|
try:
|
||||||
from tiramisu.error import APIError, ValueWarning, ValueOptionError, ValueErrorWarning, PropertiesOptionError, ConfigError, display_list
|
from tiramisu.error import APIError, ValueWarning, ValueOptionError, ValueErrorWarning, PropertiesOptionError, ConfigError, display_list
|
||||||
except ModuleNotFoundError:
|
except ImportError:
|
||||||
import weakref
|
import weakref
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ except ModuleNotFoundError:
|
|||||||
if self.msg:
|
if self.msg:
|
||||||
return self.msg
|
return self.msg
|
||||||
if self._option_bag is None:
|
if self._option_bag is None:
|
||||||
return "unknown error"
|
return "option désactivée"
|
||||||
req = self._settings.apply_requires(self._option_bag,
|
req = self._settings.apply_requires(self._option_bag,
|
||||||
True)
|
True)
|
||||||
# if req != {} or self._orig_opt is not None:
|
# if req != {} or self._orig_opt is not None:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
try:
|
try:
|
||||||
from tiramisu.i18n import _
|
from tiramisu.i18n import _
|
||||||
except ModuleNotFoundError:
|
except ImportError:
|
||||||
# FIXME
|
# FIXME
|
||||||
def _(val):
|
def _(val):
|
||||||
return val
|
return val
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
try:
|
try:
|
||||||
from tiramisu.setting import undefined
|
from tiramisu.setting import undefined
|
||||||
except ModuleNotFoundError:
|
except ImportError:
|
||||||
class Undefined(object):
|
class Undefined(object):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'Undefined'
|
return 'Undefined'
|
||||||
|
Reference in New Issue
Block a user