我的主要目的是测试session
是否从commit_proto_zk
方法调用。你知道吗
我已经读过 Assert that a method was called in a Python unit test ,但无法理解:
def session(self, flag = ''):
if flag == 1:
return True
return False
from zooKeeper import session
import sys
class EsxCollector():
def collectHW(self):
a1 = self.a()
b1 = self.b()
c1 = self.c()
hwInfo = self.writeProto(a1, b1, c1)
return hwInfo
def a(self):
return 'a'
def b(self):
return 'b'
def c(self):
return 'c'
def writeProto(self, a1, b1, c1):
return '{0} {1} {2}'.format(a1, b1, c1)
def commit_proto_zk(self, hwInfo):
flag = 1
zkSession = session(flag)
if not zkSession:
print "**no session**"
sys.exit(1)
else:
return zkSession
if isinstance(hwInfo,str):
print "*****", hwInfo
return True
else:
return False
def ab(self, l):
return l*2
def __main__():
esxCollector = EsxCollector()
hwInfo = esxCollector.collectHW()
print esxCollector.commit_proto_zk(hwInfo)
if __name__=='__main__':
__main__()
可以使用inspect模块获取函数的调用堆栈。你知道吗
输出:
就你而言
相关问题 更多 >
编程相关推荐