[test-API PATCH 3/5] proxy: generalize function get_optionalfunc_call_dict

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



   *make get_optionalfunc_call_dict work for both testcase_check()
    and testcase_clean()
   *imporve the code readability
---
 proxy.py |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/proxy.py b/proxy.py
index 49a0420..32a8eb2 100644
--- a/proxy.py
+++ b/proxy.py
@@ -21,10 +21,10 @@
 import exception
 
 class Proxy(object):
-    """ The Proxy class is used for getting real function call reference """
+    """ The Proxy class is used for getting function reference """
 
     def __init__(self, testcases_names):
-        """ Argument case_list is test case list """
+        """ initialize a list of references to testcases module """
         self.testcases_names = testcases_names
         self.testcase_ref_dict = {}
 
@@ -73,8 +73,8 @@ class Proxy(object):
                                               (func, modcase))
         return func_dict
 
-    def get_clearfunc_call_dict(self):
-        """ Return a clearing function reference dictionary. """
+    def get_optionalfunc_call_dict(self, suffix):
+        """ get optional function that is present in testcase"""
         func_dict = {}
         for testcase_name in self.testcases_names:
             # Get module, casename
@@ -85,14 +85,15 @@ class Proxy(object):
 
             module = elements[0]
             casename = elements[1]
-            func = casename + '_clean'
+            func = casename + '_' + suffix
 
-            casemod_ref = self.testcase_ref_dict[testcase_name]
-            var_func_names = dir(casemod_ref)
+            modcase = module + ':' + casename
+            key = modcase + ':' + casename
 
-            key = module + ':' + casename + ':' + func
+            casemod_ref = self.testcase_ref_dict[modcase]
+            var_func_names = dir(casemod_ref)
 
-            # the clean function is optional, we get its reference
+            # function is optional, we get its reference
             # only if it exists in testcases
             if func in var_func_names:
                 func_ref = getattr(casemod_ref, func)
@@ -114,16 +115,17 @@ class Proxy(object):
             module = elements[0]
             casename = elements[1]
 
-            casemod_ref = self.testcase_ref_dict[testcase_name]
+            modcase = module + ':' + casename
+            casemod_ref = self.testcase_ref_dict[modcase]
             var_func_names = dir(casemod_ref)
 
             if 'required_params' in var_func_names \
                and 'optional_params' in var_func_names:
-                case_params[testcase_name] = \
+                case_params[modcase] = \
                     [casemod_ref.required_params, casemod_ref.optional_params]
             else:
                 raise exception.TestCaseError\
-                      ("required_params or optional_params not found in %s" % testcase_name)
+                      ("required_params or optional_params not found in %s" % modcase)
         return case_params
 
     def has_clean_function(self, testcase_name):
-- 
1.7.7.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]