From 3a1745a885a088c9a1f8f2885a7aff171197c1d9 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 29 Sep 2018 20:05:28 +0200 Subject: [PATCH] add tests for coverage --- test/test_masterslaves.py | 4 ++++ test/test_option.py | 21 +++++++++++++++++++++ test/test_option_setting.py | 2 ++ 3 files changed, 27 insertions(+) diff --git a/test/test_masterslaves.py b/test/test_masterslaves.py index 7877f3c..dfd9b5f 100644 --- a/test/test_masterslaves.py +++ b/test/test_masterslaves.py @@ -250,7 +250,11 @@ def test_groups_with_master_make_dict(): od = OptionDescription('root', '', [interface1]) api = Config(od) assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []} + assert api.option('ip_admin_eth0.ip_admin_eth0').value.len() == 0 + assert api.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 0 api.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip1', 'ip2']) + assert api.option('ip_admin_eth0.ip_admin_eth0').value.len() == 2 + assert api.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 2 assert api.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip1', 'ip2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None]} diff --git a/test/test_option.py b/test/test_option.py index da3643f..ea8be5a 100644 --- a/test/test_option.py +++ b/test/test_option.py @@ -123,6 +123,26 @@ def test_unknown_option(): raises(AttributeError, "api.option('od.unknown.suboption').value.get()") +def test_optiondescription_list(): + groups.notfamily1 = groups.GroupType('notfamily1') + i = IntOption('test', '') + i2 = IntOption('test', '') + od1 = OptionDescription('od', '', [i]) + od1.impl_set_group_type(groups.family) + od3 = OptionDescription('od2', '', [i2]) + od3.impl_set_group_type(groups.notfamily1) + od2 = OptionDescription('od', '', [od1, od3]) + od4 = OptionDescription('od', '', [od2]) + api = Config(od4) + assert len(list(api.option('od').list('option'))) == 0 + assert len(list(api.option('od').list('optiondescription'))) == 2 + assert len(list(api.option('od').list('optiondescription', group_type=groups.family))) == 1 + assert len(list(api.option('od').list('optiondescription', group_type=groups.notfamily1))) == 1 + assert len(list(api.option('od.od').list('option'))) == 1 + assert len(list(api.option('od.od2').list('option'))) == 1 + raises(APIError, "list(api.option.list('unknown'))") + + def test_optiondescription_group(): groups.notfamily = groups.GroupType('notfamily') i = IntOption('test', '') @@ -133,6 +153,7 @@ def test_optiondescription_group(): od3.impl_set_group_type(groups.notfamily) od2 = OptionDescription('od', '', [od1, od3]) api = Config(od2) + assert len(list(api.option.list('option'))) == 0 assert len(list(api.option.list('optiondescription'))) == 2 assert len(list(api.option.list('optiondescription', group_type=groups.family))) == 1 assert len(list(api.option.list('optiondescription', group_type=groups.notfamily))) == 1 diff --git a/test/test_option_setting.py b/test/test_option_setting.py index a5e9e4e..f200dcb 100644 --- a/test/test_option_setting.py +++ b/test/test_option_setting.py @@ -201,6 +201,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) def test_apply_requires_with_disabled(): @@ -215,6 +216,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' in api.unrestraint.option('opt.str').property.get()