On 04/16/2012 08:15 AM, Guannan Ren wrote: > *libvirt-test-api.py: initialize proxy module only once > *casecfgcheck.py: use proxy object rather than initialize it by > itself > *proxy.py: make get_func_call_dict more flexible > --- > casecfgcheck.py | 5 +---- > libvirt-test-api.py | 12 +++++------- > proxy.py | 22 ++++++++++++++-------- > 3 files changed, 20 insertions(+), 19 deletions(-) > > diff --git a/casecfgcheck.py b/casecfgcheck.py > index 40d7c6e..9a4f8e6 100644 > --- a/casecfgcheck.py > +++ b/casecfgcheck.py > @@ -18,13 +18,10 @@ import proxy > > class CaseCfgCheck(object): > """validate the options in testcase config file""" > - def __init__(self, unique_testcases, activities_list): > - self.unique_testcases = unique_testcases > - > + def __init__(self, proxy_obj, activities_list): > # XXX to check the first testcase list in activities_list > self.activity = activities_list[0] > > - proxy_obj = proxy.Proxy(self.unique_testcases) > self.case_params = proxy_obj.get_params_variables() > > def check(self): > diff --git a/libvirt-test-api.py b/libvirt-test-api.py > index 385b52d..7b38aaa 100644 > --- a/libvirt-test-api.py > +++ b/libvirt-test-api.py > @@ -112,20 +112,18 @@ class Main(object): > > unique_testcases = filterobj.unique_testcases() > > + # __import__ TESTCASE.py once for duplicate testcase names > + proxy_obj = proxy.Proxy(unique_testcases) > + > # check the options to each testcase in case config file > - casechk = CaseCfgCheck(unique_testcases, activities_list) > + casechk = CaseCfgCheck(proxy_obj, activities_list) > if casechk.check(): > return 1 > > # get a list of unique testcase > # with 'clean' flag appended to its previous testcase > unique_testcase_keys = filterobj.unique_testcase_cleansuffix() > - > - # call and initilize proxy component to > - # get a list of reference of testcases > - proxy_obj = proxy.Proxy(unique_testcase_keys) > - > - cases_func_ref_dict = proxy_obj.get_func_call_dict() > + cases_func_ref_dict = proxy_obj.get_func_call_dict(unique_testcase_keys) > > # create a null list, then, initilize generator to > # get the callable testcase function > diff --git a/proxy.py b/proxy.py > index bc82a84..49a0420 100644 > --- a/proxy.py > +++ b/proxy.py > @@ -1,6 +1,6 @@ > #!/usr/bin/env python > # > -# libvirt-test-API is copyright 2010 Red Hat, Inc. > +# libvirt-test-API is copyright 2010, 2012 Red Hat, Inc. > # > # libvirt-test-API is free software: you can redistribute it and/or modify it > # under the terms of the GNU General Public License as published by > @@ -37,12 +37,13 @@ class Proxy(object): > casename = elements[1] > > casemod_ref = self.get_call_dict(module, casename) > - self.testcase_ref_dict[testcase_name] = casemod_ref > + modcase = module + ':' + casename > + self.testcase_ref_dict[modcase] = casemod_ref > > - def get_func_call_dict(self): > - """Return running function reference dictionary """ > + def get_func_call_dict(self, unique_testcase_keys): > + """get reference to functions defined in testcase file """ > func_dict = {} > - for testcase_name in self.testcases_names: > + for testcase_name in unique_testcase_keys: > # Get module, casename > elements = testcase_name.split(':') > module = elements[0] > @@ -55,16 +56,21 @@ class Proxy(object): > flag = elements[2] > func = casename + flag > > - casemod_ref = self.testcase_ref_dict[testcase_name] > + # use modcase key to get the reference to corresponding > + # testcase module > + modcase = module + ':' + casename > + casemod_ref = self.testcase_ref_dict[modcase] > var_func_names = dir(casemod_ref) > > - key = module + ':' + casename + ':' + func > + key = modcase + ':' + func > + # check if the expected function is present in > + # the list of string name from dir() > if func in var_func_names: > func_ref = getattr(casemod_ref, func) > func_dict[key] = func_ref > else: > raise exception.TestCaseError("function %s not found in %s" % \ > - (func, testcase_name)) > + (func, modcase)) > return func_dict > > def get_clearfunc_call_dict(self): ACK both. Martin P.S.: This is very useful, I don't have to type it manually =) -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list