谁用过python 的mock 做unit test
如果一段代码
Python code:
#!/usr/bin/python2.5
from urllib2 import Request,urlopen,URLError
def check():
req = Request('http://www.google.com')
try:
res = urlopen(req).read()
return res
except URLError, e:
if hasattr(e, 'reason'):
return('We failed to reach the server. Reason: %s' % e.reason)
elif hasattr(e, 'code'):
return('The server couldn\'t fulfill the request. Error code: %s' %
e.code)
if __name__ == '__main__':
print check()
现在我要做unit test 我怎么样能用mock 来做一些模拟的访问网络及异常处理?
友情帮顶
moke 能做什么?能在客户端执行js吗?
End_rbody_60020883//-->
该回复于2009-09-25 10:49:51被管理员删除
对我有用[0]
丢个板砖[0]
引用
举报
管理
TOP
相关问答:
RT,貌似Python之父也说如果你现在开始新的项目的话,最好是直接使用Python3,可是实际上大家使用得大部分还是2.5,估计用2.6的都不是很多,并且相对应的许多扩展都没有3对应的版本。
  ......
我用了def CreateMyDialog(self):
dlg = MyDialog(None, -1, ''.decode('utf8'), (300,300), (300,200), wx.DEFAULT_DIALOG_STYLE | wx.DIALOG_NO_PARENT )
&nbs ......
如题!
www.Portablepython.com
学习了
官网不就有吗
或者自己编译好了
Portablepython就是,你从它的官网上下载下来,可以把它安装到磁盘上(尤其是安装到U盘上,可以随身带着)
Portablepython ......
python和pyqt以及Eric4都已经配置好了,打开Eric4写个python程序比如简单的
print“hello,world”,怎么编译运行了,Start菜单的所有命令都出现和图中差不多的对话框,应当怎么运行了?
求大家指教
没有人用 ......
照着书上写的,执行时报错(Python2.6)
import wx
class InsertFrame(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'F ......