下面的代码如何用于功能测试,在 foo 和 bar 上它工作正常。
import argparse
class Myclass(object):
def foo(self):
print 'foo'
def bar(self):
print 'bar'
def test(self,name,place):
print name, place
class Main(Myclass):
def __init__(self):
foo_parser = argparse.ArgumentParser()
foo_parser.add_argument('method')
self.args = foo_parser.parse_args()
def __call__(self, *args, **kws):
method = self.args.method
return getattr(self, method)(*args, **kws)
if __name__ == "__main__":
main = Main()
main()