support informations attribute for all options

This commit is contained in:
egarette@silique.fr 2024-07-05 19:35:39 +02:00
parent 4e1053bba9
commit f2893aaacd
3 changed files with 46 additions and 31 deletions

View file

@ -12,7 +12,11 @@ import pytest
from tiramisu import Config, Calculation, Params, ParamSelfInformation, calc_value from tiramisu import Config, Calculation, Params, ParamSelfInformation, calc_value
from tiramisu.i18n import _ from tiramisu.i18n import _
from tiramisu import Config, IntOption, FloatOption, ChoiceOption, \ from tiramisu import Config, IntOption, FloatOption, ChoiceOption, \
BoolOption, StrOption, SymLinkOption, OptionDescription, undefined BoolOption, StrOption, SymLinkOption, OptionDescription, undefined, \
DomainnameOption, EmailOption, URLOption, RegexpOption, IPOption, \
PortOption, NetworkOption, NetmaskOption, BroadcastOption, UsernameOption, \
GroupnameOption, DateOption, FilenameOption, PasswordOption, MACOption, \
PermissionsOption
from tiramisu.error import ConflictError, ConfigError, PropertiesOptionError from tiramisu.error import ConflictError, ConfigError, PropertiesOptionError
@ -129,6 +133,29 @@ def test_not_valid_properties():
# assert not list_sessions() # assert not list_sessions()
def test_information_load():
ChoiceOption('a', '', ('a', 'b'), informations={'info': 'value'})
BoolOption('a', '', informations={'info': 'value'})
IntOption('a', '', informations={'info': 'value'})
FloatOption('a', '', informations={'info': 'value'})
StrOption('a', '', informations={'info': 'value'})
RegexpOption('a', '', informations={'info': 'value'})
IPOption('a', '', informations={'info': 'value'})
PortOption('a', '', informations={'info': 'value'})
NetworkOption('a', '', informations={'info': 'value'})
NetmaskOption('a', '', informations={'info': 'value'})
BroadcastOption('a', '', informations={'info': 'value'})
DomainnameOption('a', '', informations={'info': 'value'})
EmailOption('a', '', informations={'info': 'value'})
URLOption('a', '', informations={'info': 'value'})
UsernameOption('a', '', informations={'info': 'value'})
GroupnameOption('a', '', informations={'info': 'value'})
DateOption('a', '', informations={'info': 'value'})
FilenameOption('a', '', informations={'info': 'value'})
PasswordOption('a', '', informations={'info': 'value'})
MACOption('a', '', informations={'info': 'value'})
PermissionsOption('a', '', informations={'info': 'value'})
def test_information_config(): def test_information_config():
od1 = make_description() od1 = make_description()
cfg = Config(od1) cfg = Config(od1)

View file

@ -45,17 +45,13 @@ class DomainnameOption(StrOption):
def __init__(self, def __init__(self,
name: str, name: str,
doc: str, doc: str,
default: Any=undefined, *args,
default_multi: Any=None,
multi: bool=False,
validators: Optional[List[Calculation]]=None,
properties: Optional[List[str]]=None,
warnings_only: bool=False,
allow_ip: bool=False, allow_ip: bool=False,
allow_cidr_network: bool=False, allow_cidr_network: bool=False,
type: str='domainname', type: str='domainname',
allow_without_dot: bool=False, allow_without_dot: bool=False,
allow_startswith_dot: bool=False, allow_startswith_dot: bool=False,
**kwargs,
) -> None: ) -> None:
# pylint: disable=too-many-branches,too-many-locals,too-many-arguments # pylint: disable=too-many-branches,too-many-locals,too-many-arguments
if type not in ['netbios', 'hostname', 'domainname']: if type not in ['netbios', 'hostname', 'domainname']:
@ -94,24 +90,23 @@ class DomainnameOption(StrOption):
extra['_has_upper'] = re.compile('[A-Z]') extra['_has_upper'] = re.compile('[A-Z]')
if allow_ip: if allow_ip:
extra['_ip'] = IPOption(name, extra['_ip'] = IPOption(name,
doc) doc,
)
extra['_allow_ip'] = allow_ip extra['_allow_ip'] = allow_ip
if allow_cidr_network: if allow_cidr_network:
extra['_network'] = NetworkOption(name, extra['_network'] = NetworkOption(name,
doc, doc,
cidr=True) cidr=True,
)
extra['_allow_cidr_network'] = allow_cidr_network extra['_allow_cidr_network'] = allow_cidr_network
extra['_allow_startswith_dot'] = allow_startswith_dot extra['_allow_startswith_dot'] = allow_startswith_dot
super().__init__(name, super().__init__(name,
doc, doc,
default=default, *args,
default_multi=default_multi, extra=extra,
multi=multi, **kwargs,
validators=validators, )
properties=properties,
warnings_only=warnings_only,
extra=extra)
def _get_len(self, type_): def _get_len(self, type_):
if type_ == 'netbios': if type_ == 'netbios':

View file

@ -41,13 +41,7 @@ class URLOption(StrOption):
def __init__(self, def __init__(self,
name: str, name: str,
doc: str, doc: str,
default: Any=undefined, *args,
default_multi: Any=None,
multi: bool=False,
validators: Optional[List[Calculation]]=None,
properties: Optional[List[str]]=None,
warnings_only: bool=False,
extra: Optional[Dict]=None,
allow_ip: bool=False, allow_ip: bool=False,
type: str='domainname', type: str='domainname',
allow_without_dot=False, allow_without_dot=False,
@ -55,7 +49,9 @@ class URLOption(StrOption):
allow_zero: bool=False, allow_zero: bool=False,
allow_wellknown: bool=True, allow_wellknown: bool=True,
allow_registred: bool=True, allow_registred: bool=True,
allow_private: bool=False) -> None: allow_private: bool=False,
**kwargs,
) -> None:
# pylint: disable=too-many-arguments,too-many-locals,redefined-builtin # pylint: disable=too-many-arguments,too-many-locals,redefined-builtin
extra = {'_domainname': DomainnameOption(name, extra = {'_domainname': DomainnameOption(name,
doc, doc,
@ -71,13 +67,10 @@ class URLOption(StrOption):
allow_private=allow_private)} allow_private=allow_private)}
super().__init__(name, super().__init__(name,
doc, doc,
default=default, extra=extra,
default_multi=default_multi, *args,
multi=multi, **kwargs,
validators=validators, )
properties=properties,
warnings_only=warnings_only,
extra=extra)
def _get_domain_port_files(self, def _get_domain_port_files(self,
value: str) -> (str, str): value: str) -> (str, str):