From f9b9ccacf11d91d06c2c67a13a4b7f1ea02ace21 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 8 Dec 2018 00:02:23 +0100 Subject: [PATCH] update tests --- test/test_config_ip.py | 188 ++++++++++++++--------------- test/test_dyn_optiondescription.py | 4 +- test/test_option_setting.py | 4 +- tiramisu/option/option.py | 16 +-- tiramisu/option/syndynoption.py | 3 +- 5 files changed, 109 insertions(+), 106 deletions(-) diff --git a/test/test_config_ip.py b/test/test_config_ip.py index 049c2ec..a515808 100644 --- a/test/test_config_ip.py +++ b/test/test_config_ip.py @@ -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')") diff --git a/test/test_dyn_optiondescription.py b/test/test_dyn_optiondescription.py index f29426d..e3887ff 100644 --- a/test/test_dyn_optiondescription.py +++ b/test/test_dyn_optiondescription.py @@ -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" diff --git a/test/test_option_setting.py b/test/test_option_setting.py index 86e10b1..df49cbc 100644 --- a/test/test_option_setting.py +++ b/test/test_option_setting.py @@ -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() diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index 915857d..9740a18 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -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, diff --git a/tiramisu/option/syndynoption.py b/tiramisu/option/syndynoption.py index 5dc82e2..08d2627 100644 --- a/tiramisu/option/syndynoption.py +++ b/tiramisu/option/syndynoption.py @@ -28,7 +28,8 @@ class SynDynOption: """ __slots__ = ('rootpath', 'opt', - 'suffix') + 'suffix', + '__weakref__') def __init__(self, opt: BaseOption,