Compare commits
2 commits
be8b1e7e4f
...
b5d477a439
| Author | SHA1 | Date | |
|---|---|---|---|
| b5d477a439 | |||
| 54ac0c980a |
4 changed files with 42 additions and 2 deletions
23
tests/test_option_regexp.py
Normal file
23
tests/test_option_regexp.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
""" RegexpOption
|
||||||
|
"""
|
||||||
|
from .autopath import do_autopath
|
||||||
|
do_autopath()
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from tiramisu import RegexpOption, OptionDescription, Config
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
class ColorOption(RegexpOption):
|
||||||
|
__slots__ = tuple()
|
||||||
|
_type = 'Color'
|
||||||
|
_regexp = re.compile(r"^#(?:[0-9a-f]{3}){1,2}$")
|
||||||
|
|
||||||
|
|
||||||
|
def test_regexp_option():
|
||||||
|
r = ColorOption('test', 'test')
|
||||||
|
od = OptionDescription('od', 'od', [r])
|
||||||
|
cfg = Config(od)
|
||||||
|
cfg.option('test').value.set('#ff0000')
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
cfg.option('test').value.set('not a color')
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
"""
|
"""
|
||||||
from .function import calc_value, calc_value_property_help, valid_ip_netmask, \
|
from .function import calc_value, calc_value_property_help, valid_ip_netmask, \
|
||||||
valid_network_netmask, valid_in_network, valid_broadcast, \
|
valid_network_netmask, valid_in_network, valid_broadcast, \
|
||||||
valid_not_equal, function_waiting_for_dict
|
valid_not_equal, function_waiting_for_dict, function_waiting_for_error
|
||||||
from .autolib import Calculation, Params, ParamOption, ParamDynOption, ParamSelfOption, \
|
from .autolib import Calculation, Params, ParamOption, ParamDynOption, ParamSelfOption, \
|
||||||
ParamValue, ParamIndex, ParamIdentifier, ParamInformation, ParamSelfInformation
|
ParamValue, ParamIndex, ParamIdentifier, ParamInformation, ParamSelfInformation
|
||||||
from .option import *
|
from .option import *
|
||||||
|
|
@ -51,6 +51,7 @@ allfuncs = ['Calculation',
|
||||||
'valid_in_network',
|
'valid_in_network',
|
||||||
'valid_broadcast',
|
'valid_broadcast',
|
||||||
'function_waiting_for_dict',
|
'function_waiting_for_dict',
|
||||||
|
'function_waiting_for_error',
|
||||||
]
|
]
|
||||||
allfuncs.extend(all_options)
|
allfuncs.extend(all_options)
|
||||||
del(all_options)
|
del(all_options)
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import weakref
|
||||||
from .error import PropertiesOptionError, ConfigError, LeadershipError, ValueWarning
|
from .error import PropertiesOptionError, ConfigError, LeadershipError, ValueWarning
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
from .setting import undefined, ConfigBag
|
from .setting import undefined, ConfigBag
|
||||||
from .function import FUNCTION_WAITING_FOR_DICT
|
from .function import FUNCTION_WAITING_FOR_DICT, FUNCTION_WAITING_FOR_ERROR
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -662,6 +662,11 @@ def carry_out_calculation(subconfig: 'SubConfig',
|
||||||
args.append({'propertyerror': str(err), 'name': option.impl_get_display_name(subconfig)})
|
args.append({'propertyerror': str(err), 'name': option.impl_get_display_name(subconfig)})
|
||||||
else:
|
else:
|
||||||
kwargs[key] = {'propertyerror': str(err), 'name': option.impl_get_display_name(subconfig)}
|
kwargs[key] = {'propertyerror': str(err), 'name': option.impl_get_display_name(subconfig)}
|
||||||
|
if callback.__name__ in FUNCTION_WAITING_FOR_ERROR:
|
||||||
|
if key is None:
|
||||||
|
args.append(err)
|
||||||
|
else:
|
||||||
|
kwargs[key] = err
|
||||||
ret = calculate(subconfig,
|
ret = calculate(subconfig,
|
||||||
callback,
|
callback,
|
||||||
allow_value_error,
|
allow_value_error,
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ from .error import display_list
|
||||||
|
|
||||||
|
|
||||||
FUNCTION_WAITING_FOR_DICT = []
|
FUNCTION_WAITING_FOR_DICT = []
|
||||||
|
FUNCTION_WAITING_FOR_ERROR = []
|
||||||
|
|
||||||
|
|
||||||
def function_waiting_for_dict(function):
|
def function_waiting_for_dict(function):
|
||||||
|
|
@ -36,6 +37,16 @@ def function_waiting_for_dict(function):
|
||||||
return function
|
return function
|
||||||
|
|
||||||
|
|
||||||
|
def function_waiting_for_error(function):
|
||||||
|
"""functions (calculation or validation) receive by default only the value of other options
|
||||||
|
set PropertyError too
|
||||||
|
"""
|
||||||
|
name = function.__name__
|
||||||
|
if name not in FUNCTION_WAITING_FOR_ERROR:
|
||||||
|
FUNCTION_WAITING_FOR_ERROR.append(name)
|
||||||
|
return function
|
||||||
|
|
||||||
|
|
||||||
@function_waiting_for_dict
|
@function_waiting_for_dict
|
||||||
def valid_network_netmask(network: dict,
|
def valid_network_netmask(network: dict,
|
||||||
netmask: dict,
|
netmask: dict,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue