update tests

This commit is contained in:
Emmanuel Garette 2018-12-08 00:02:23 +01:00
parent da99c8eb69
commit f9b9ccacf1
5 changed files with 109 additions and 106 deletions

View File

@ -119,58 +119,58 @@ def test_port():
f = PortOption('f', '', allow_private=True)
od = OptionDescription('od', '', [a, b, c, d, e, f])
cfg = Config(od)
raises(ValueError, "cfg.option('a').value.set(0)")
cfg.option('a').value.set(1)
cfg.option('a').value.set(1023)
cfg.option('a').value.set(1024)
cfg.option('a').value.set(49151)
raises(ValueError, "cfg.option('a').value.set(49152)")
raises(ValueError, "cfg.option('a').value.set(65535)")
raises(ValueError, "cfg.option('a').value.set(65536)")
raises(ValueError, "cfg.option('a').value.set('0')")
cfg.option('a').value.set('1')
cfg.option('a').value.set('1023')
cfg.option('a').value.set('1024')
cfg.option('a').value.set('49151')
raises(ValueError, "cfg.option('a').value.set('49152')")
raises(ValueError, "cfg.option('a').value.set('65535')")
raises(ValueError, "cfg.option('a').value.set('65536')")
cfg.option('b').value.set(0)
cfg.option('b').value.set(1)
cfg.option('b').value.set(1023)
cfg.option('b').value.set(1024)
cfg.option('b').value.set(49151)
raises(ValueError, "cfg.option('b').value.set(49152)")
raises(ValueError, "cfg.option('b').value.set(65535)")
raises(ValueError, "cfg.option('b').value.set(65536)")
cfg.option('b').value.set('0')
cfg.option('b').value.set('1')
cfg.option('b').value.set('1023')
cfg.option('b').value.set('1024')
cfg.option('b').value.set('49151')
raises(ValueError, "cfg.option('b').value.set('49152')")
raises(ValueError, "cfg.option('b').value.set('65535')")
raises(ValueError, "cfg.option('b').value.set('65536')")
cfg.option('c').value.set(0)
cfg.option('c').value.set(1)
cfg.option('c').value.set(1023)
raises(ValueError, "cfg.option('c').value.set(1024)")
raises(ValueError, "cfg.option('c').value.set(49151)")
raises(ValueError, "cfg.option('c').value.set(49152)")
raises(ValueError, "cfg.option('c').value.set(65535)")
raises(ValueError, "cfg.option('c').value.set(65536)")
cfg.option('c').value.set('0')
cfg.option('c').value.set('1')
cfg.option('c').value.set('1023')
raises(ValueError, "cfg.option('c').value.set('1024')")
raises(ValueError, "cfg.option('c').value.set('49151')")
raises(ValueError, "cfg.option('c').value.set('49152')")
raises(ValueError, "cfg.option('c').value.set('65535')")
raises(ValueError, "cfg.option('c').value.set('65536')")
cfg.option('d').value.set(0)
raises(ValueError, "cfg.option('d').value.set(1)")
raises(ValueError, "cfg.option('d').value.set(1023)")
raises(ValueError, "cfg.option('d').value.set(1024)")
raises(ValueError, "cfg.option('d').value.set(49151)")
raises(ValueError, "cfg.option('d').value.set(49152)")
raises(ValueError, "cfg.option('d').value.set(65535)")
raises(ValueError, "cfg.option('d').value.set(65536)")
cfg.option('d').value.set('0')
raises(ValueError, "cfg.option('d').value.set('1')")
raises(ValueError, "cfg.option('d').value.set('1023')")
raises(ValueError, "cfg.option('d').value.set('1024')")
raises(ValueError, "cfg.option('d').value.set('49151')")
raises(ValueError, "cfg.option('d').value.set('49152')")
raises(ValueError, "cfg.option('d').value.set('65535')")
raises(ValueError, "cfg.option('d').value.set('65536')")
cfg.option('e').value.set(0)
cfg.option('e').value.set(1)
cfg.option('e').value.set(1023)
cfg.option('e').value.set(1024)
cfg.option('e').value.set(49151)
cfg.option('e').value.set(49152)
cfg.option('e').value.set(65535)
cfg.option('e').value.set('0')
cfg.option('e').value.set('1')
cfg.option('e').value.set('1023')
cfg.option('e').value.set('1024')
cfg.option('e').value.set('49151')
cfg.option('e').value.set('49152')
cfg.option('e').value.set('65535')
raises(ValueError, "cfg.option('f').value.set(0)")
cfg.option('f').value.set(1)
cfg.option('f').value.set(1023)
cfg.option('f').value.set(1024)
cfg.option('f').value.set(49151)
cfg.option('f').value.set(49152)
cfg.option('f').value.set(65535)
raises(ValueError, "cfg.option('f').value.set(65536)")
raises(ValueError, "cfg.option('f').value.set('0')")
cfg.option('f').value.set('1')
cfg.option('f').value.set('1023')
cfg.option('f').value.set('1024')
cfg.option('f').value.set('49151')
cfg.option('f').value.set('49152')
cfg.option('f').value.set('65535')
raises(ValueError, "cfg.option('f').value.set('65536')")
def test_port_range():
@ -182,69 +182,69 @@ def test_port_range():
f = PortOption('f', '', allow_range=True, allow_private=True)
od = OptionDescription('od', '', [a, b, c, d, e, f])
cfg = Config(od)
raises(ValueError, "cfg.option('a').value.set(0)")
cfg.option('a').value.set(1)
cfg.option('a').value.set(1023)
cfg.option('a').value.set(1024)
cfg.option('a').value.set(49151)
raises(ValueError, "cfg.option('a').value.set(49152)")
raises(ValueError, "cfg.option('a').value.set(65535)")
raises(ValueError, "cfg.option('a').value.set(65536)")
raises(ValueError, "cfg.option('a').value.set('0')")
cfg.option('a').value.set('1')
cfg.option('a').value.set('1023')
cfg.option('a').value.set('1024')
cfg.option('a').value.set('49151')
raises(ValueError, "cfg.option('a').value.set('49152')")
raises(ValueError, "cfg.option('a').value.set('65535')")
raises(ValueError, "cfg.option('a').value.set('65536')")
cfg.option('a').value.set('1:49151')
raises(ValueError, "cfg.option('a').value.set('0:49151')")
raises(ValueError, "cfg.option('a').value.set('1:49152')")
cfg.option('b').value.set(0)
cfg.option('b').value.set(1)
cfg.option('b').value.set(1023)
cfg.option('b').value.set(1024)
cfg.option('b').value.set(49151)
raises(ValueError, "cfg.option('b').value.set(49152)")
raises(ValueError, "cfg.option('b').value.set(65535)")
raises(ValueError, "cfg.option('b').value.set(65536)")
cfg.option('b').value.set('0')
cfg.option('b').value.set('1')
cfg.option('b').value.set('1023')
cfg.option('b').value.set('1024')
cfg.option('b').value.set('49151')
raises(ValueError, "cfg.option('b').value.set('49152')")
raises(ValueError, "cfg.option('b').value.set('65535')")
raises(ValueError, "cfg.option('b').value.set('65536')")
cfg.option('b').value.set('0:49151')
raises(ValueError, "cfg.option('b').value.set('0:49152')")
cfg.option('c').value.set(0)
cfg.option('c').value.set(1)
cfg.option('c').value.set(1023)
raises(ValueError, "cfg.option('c').value.set(1024)")
raises(ValueError, "cfg.option('c').value.set(49151)")
raises(ValueError, "cfg.option('c').value.set(49152)")
raises(ValueError, "cfg.option('c').value.set(65535)")
raises(ValueError, "cfg.option('c').value.set(65536)")
cfg.option('c').value.set('0')
cfg.option('c').value.set('1')
cfg.option('c').value.set('1023')
raises(ValueError, "cfg.option('c').value.set('1024')")
raises(ValueError, "cfg.option('c').value.set('49151')")
raises(ValueError, "cfg.option('c').value.set('49152')")
raises(ValueError, "cfg.option('c').value.set('65535')")
raises(ValueError, "cfg.option('c').value.set('65536')")
cfg.option('c').value.set('0:1023')
raises(ValueError, "cfg.option('c').value.set('0:1024')")
cfg.option('d').value.set(0)
raises(ValueError, "cfg.option('d').value.set(1)")
raises(ValueError, "cfg.option('d').value.set(1023)")
raises(ValueError, "cfg.option('d').value.set(1024)")
raises(ValueError, "cfg.option('d').value.set(49151)")
raises(ValueError, "cfg.option('d').value.set(49152)")
raises(ValueError, "cfg.option('d').value.set(65535)")
raises(ValueError, "cfg.option('d').value.set(65536)")
cfg.option('d').value.set('0')
raises(ValueError, "cfg.option('d').value.set('1')")
raises(ValueError, "cfg.option('d').value.set('1023')")
raises(ValueError, "cfg.option('d').value.set('1024')")
raises(ValueError, "cfg.option('d').value.set('49151')")
raises(ValueError, "cfg.option('d').value.set('49152')")
raises(ValueError, "cfg.option('d').value.set('65535')")
raises(ValueError, "cfg.option('d').value.set('65536')")
raises(ValueError, "cfg.option('d').value.set('0:0')")
raises(ValueError, "cfg.option('d').value.set('0:1')")
cfg.option('e').value.set(0)
cfg.option('e').value.set(1)
cfg.option('e').value.set(1023)
cfg.option('e').value.set(1024)
cfg.option('e').value.set(49151)
cfg.option('e').value.set(49152)
cfg.option('e').value.set(65535)
cfg.option('e').value.set('0')
cfg.option('e').value.set('1')
cfg.option('e').value.set('1023')
cfg.option('e').value.set('1024')
cfg.option('e').value.set('49151')
cfg.option('e').value.set('49152')
cfg.option('e').value.set('65535')
cfg.option('e').value.set('0:65535')
raises(ValueError, "cfg.option('e').value.set('0:65536')")
raises(ValueError, "cfg.option('f').value.set(0)")
cfg.option('f').value.set(1)
cfg.option('f').value.set(1023)
cfg.option('f').value.set(1024)
cfg.option('f').value.set(49151)
cfg.option('f').value.set(49152)
cfg.option('f').value.set(65535)
raises(ValueError, "cfg.option('f').value.set(65536)")
raises(ValueError, "cfg.option('f').value.set('0')")
cfg.option('f').value.set('1')
cfg.option('f').value.set('1023')
cfg.option('f').value.set('1024')
cfg.option('f').value.set('49151')
cfg.option('f').value.set('49152')
cfg.option('f').value.set('65535')
raises(ValueError, "cfg.option('f').value.set('65536')")
cfg.option('f').value.set('1:65535')
cfg.option('f').value.set('3:4')
raises(ValueError, "cfg.option('f').value.set('0:65535')")

View File

@ -860,7 +860,7 @@ def test_all_dyndescription():
api.option('dodval1.intrval1').value.set(1)
api.option('dodval1.floaval1').value.set(0.1)
api.option('dodval1.unival1').value.set(u"no")
api.option('dodval1.portval1').value.set(80)
api.option('dodval1.portval1').value.set('80')
api.option('dodval1.broadval1').value.set("1.1.1.255")
api.option('dodval1.domainval1').value.set("test.com")
api.option('dodval1.emailval1').value.set("test@test.com")
@ -877,7 +877,7 @@ def test_all_dyndescription():
assert api.option('dodval1.intrval1').value.get() == 1
assert api.option('dodval1.floaval1').value.get() == 0.1
assert api.option('dodval1.unival1').value.get() == u"no"
assert api.option('dodval1.portval1').value.get() == 80
assert api.option('dodval1.portval1').value.get() == '80'
assert api.option('dodval1.broadval1').value.get() == "1.1.1.255"
assert api.option('dodval1.domainval1').value.get() == "test.com"
assert api.option('dodval1.emailval1').value.get() == "test@test.com"

View File

@ -217,7 +217,7 @@ def test_apply_requires_from_config():
api.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('opt.str').value.get()")
assert 'hidden' in api.forcepermissive.option('opt.str').property.get()
assert 'hidden' not in api.forcepermissive.option('opt.str').property.get(apply_requires=False)
assert 'hidden' not in api.forcepermissive.option('opt.str').option.properties()
def test_apply_requires_with_disabled():
@ -232,7 +232,7 @@ def test_apply_requires_with_disabled():
assert not 'disabled' in api.option('opt.str').property.get()
api.option('int').value.set(1)
raises(PropertiesOptionError, "api.option('opt.str').value.get()")
assert 'disabled' not in api.unrestraint.option('opt.str').property.get(apply_requires=False)
assert 'disabled' not in api.unrestraint.option('opt.str').option.properties()
assert 'disabled' in api.unrestraint.option('opt.str').property.get()

View File

@ -346,16 +346,18 @@ class Option(BaseOption):
check_error,
is_warnings_only)
except ValueError as err:
val_err = ValueOptionError(val,
if config_bag is undefined or \
'demoting_error' not in config_bag.properties:
raise ValueOptionError(val,
self._display_name,
option_bag.ori_option,
'{0}'.format(err))
if 'demoting_error' in config_bag.properties:
warnings.warn_explicit(val_err,
ValueErrorWarning,
self.__class__.__name__, 0)
else:
raise val_err
warnings.warn_explicit(ValueOptionError(val,
self._display_name,
option_bag.ori_option,
'{0}'.format(err)),
ValueErrorWarning,
self.__class__.__name__, 0)
def _validate_calculator(self,
callback: Callable,

View File

@ -28,7 +28,8 @@ class SynDynOption:
"""
__slots__ = ('rootpath',
'opt',
'suffix')
'suffix',
'__weakref__')
def __init__(self,
opt: BaseOption,