commit 967ca0eaf660f18955bdd06f7a77ebbffd088a32 Author: Jiri Pirko jpirko@redhat.com Date: Wed Jun 29 16:08:48 2011 +0200
TestGeneric: Implement multi-value options
Might become handy. Just repeat the option in xml with different values and you can get them all in particular test.
Signed-off-by: Jiri Pirko jpirko@redhat.com
Common/TestsCommon.py | 47 ++++++++++++++++++++++++++++++++++++----------- NetTest/NetTestParse.py | 4 +++- 2 files changed, 39 insertions(+), 12 deletions(-) --- diff --git a/Common/TestsCommon.py b/Common/TestsCommon.py index f9beaf2..197bb62 100644 --- a/Common/TestsCommon.py +++ b/Common/TestsCommon.py @@ -70,27 +70,39 @@ class TestGeneric(NetTestCommandGeneric): self.set_result(res) return res
- def get_opt(self, name, mandatory=False, opt_type="", default=None): - try: - option = self._command["options"][name] - except KeyError: - if mandatory: - raise TestOptionMissing - return default - - value = option["value"] + def _get_val(self, value, opt_type, default): if opt_type == "addr": ''' If address type is specified do "slashcut" ''' - value = re.sub(r'/.*', r'', value) + return re.sub(r'/.*', r'', value)
if default != None: ''' In case a default value is passed, retype value by the default value type. ''' - value = (type(default))(value) + return (type(default))(value) + + return value + + def get_opt(self, name, multi=False, mandatory=False, opt_type="", default=None): + try: + option = self._command["options"][name] + except KeyError: + if mandatory: + raise TestOptionMissing + if multi: + return [default] + else: + return default + + if multi: + value = [] + for op in option: + value.append(self._get_val(op["value"], opt_type, default)) + else: + value = self._get_val(option[0]["value"], opt_type, default)
return value
@@ -99,3 +111,16 @@ class TestGeneric(NetTestCommandGeneric): This should be used to get mandatory options ''' return self.get_opt(name, mandatory=True, opt_type=opt_type) + + def get_multi_opt(self, name, mandatory=False, opt_type="", default=None): + ''' + This should be used to get multi options (array of values) + ''' + return self.get_opt(name, multi=True, mandatory=mandatory, + opt_type=opt_type, default=default) + + def get_multi_mopt(self, name, opt_type=""): + ''' + This should be used to get mandatory multi options (array of values) + ''' + return self.get_multi_opt(name, mandatory=True, opt_type=opt_type) diff --git a/NetTest/NetTestParse.py b/NetTest/NetTestParse.py index 414bc40..f0be155 100644 --- a/NetTest/NetTestParse.py +++ b/NetTest/NetTestParse.py @@ -113,7 +113,9 @@ class NetTestParse: option["type"] = option_type if orig_value: option["orig_value"] = orig_value - options[name] = option + if not name in options: + options[name] = [] + options[name].append(option)
def _parse_command(self, dom_command): logging.debug("Parsing command")
lnst-developers@lists.fedorahosted.org