From: Ondrej Lichtner <olichtne(a)redhat.com>
The default value returned by get_multi_opt was [None] (a list with a
single None element) which doesn't make a lot of sense and results in
testers incorrectly using the following construct:
opt = get_multi_opt('xyz')
if opt:
do_something
or:
for i in opt:
do something
Both of which will be invoced even if the parameter is not defined and
will try to do something with the None value...
This commit changes the behaviour of get_multi_opt to return [] as the
default value.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Common/TestsCommon.py | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/lnst/Common/TestsCommon.py b/lnst/Common/TestsCommon.py
index accb6b8..195bb0c 100644
--- a/lnst/Common/TestsCommon.py
+++ b/lnst/Common/TestsCommon.py
@@ -79,7 +79,7 @@ class TestGeneric(NetTestCommandGeneric):
'''
return re.sub(r'/.*', r'', value)
- if default != None:
+ if default != None and default != []:
'''
In case a default value is passed, retype value
by the default value type.
@@ -94,10 +94,7 @@ class TestGeneric(NetTestCommandGeneric):
except KeyError:
if mandatory:
raise TestOptionMissing("Missing option '%s'!" % name)
- if multi:
- return [default]
- else:
- return default
+ return default
if multi:
value = []
@@ -114,7 +111,7 @@ class TestGeneric(NetTestCommandGeneric):
'''
return self.get_opt(name, mandatory=True, opt_type=opt_type)
- def get_multi_opt(self, name, mandatory=False, opt_type="", default=None):
+ def get_multi_opt(self, name, mandatory=False, opt_type="", default=[]):
'''
This should be used to get multi options (array of values)
'''
--
2.10.0