avocado.utils.params: Add code to access test params

Access test params through its internal dictionary, so
you can lookup

self.params.timeout

As well as

self.params['timeout']
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 9b490fd8
......@@ -144,7 +144,6 @@ class Test(unittest.TestCase):
# Apply what comes from the params dict
for key in sorted(self.params.keys()):
self.log.debug(' %s = %s', key, self.params.get(key))
setattr(self.params, key, self.params.get(key))
self.log.debug('')
# Apply what comes from the default_params dict
......@@ -157,7 +156,7 @@ class Test(unittest.TestCase):
self.log.debug('')
# If there's a timeout set, log a timeout reminder
if hasattr(self.params, 'timeout'):
if self.params.timeout:
self.log.info('Test timeout set. Will wait %.2f s for '
'PID %s to end',
float(self.params.timeout), os.getpid())
......@@ -205,7 +204,6 @@ class Test(unittest.TestCase):
self.params[key]
except Exception:
self.params[key] = default
setattr(self.params, key, default)
def get_deps_path(self, basename):
"""
......
......@@ -25,7 +25,10 @@ class Params(UserDict.IterableUserDict):
try:
value = UserDict.IterableUserDict.__getitem__(self, key)
vtype = UserDict.IterableUserDict.get(self, "%s_type" % key)
return settings.convert_value_type(value, vtype)
if vtype is not None:
return settings.convert_value_type(value, vtype)
else:
return value
except KeyError:
raise ParamNotFound("Mandatory parameter '%s' is missing. "
"Check your cfg files for typos/mistakes" %
......@@ -35,6 +38,15 @@ class Params(UserDict.IterableUserDict):
"convert to %s: %s" %
(key, value, vtype, details))
def __getattr__(self, attr):
try:
return UserDict.IterableUserDict.__getattr__(self, attr)
except AttributeError:
try:
return self.__getitem__(attr)
except ParamNotFound:
return None
def objects(self, key):
"""
Return the names of objects defined using a given key.
......@@ -59,7 +71,7 @@ class Params(UserDict.IterableUserDict):
"""
suffix = "_" + obj_name
self.lock.acquire()
new_dict = self.copy()
new_dict = self.data.copy()
self.lock.release()
for key in new_dict.keys():
if key.endswith(suffix):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册