谁用过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
相关问答:
在Python for unix and linux System Administration这本书的第6章的Comparing Data一节提到用filecmp这个模块的cmp函数来判断2个文件是否相同。
如下所示:
Python code:
import filecmp
filecmp.c ......
我的mp3标签信息是通过Tag&Rename 软件来修改的
修改的信息如下
Album Title ISRC
77 66 99
---python读取mp3的id3的代码----
from mutagen.mp3 import MP3
import mutagen.id3
......
我现在要处理数百万条数据,处理过程是通过比较数据里是否有指定的字符串,再插入到另外的表中,请问用Python如何高效完成?先谢谢各位了。
建议:别直接跟数据库比较。太耗费IO。
把你需要比较的字段从数据 ......
喜欢Python的朋友请进.
详细信息请查看:
http://blog.csdn.net/lgg201/archive/2009/10/08/4643635.aspx
Let's-python-系列视频发布专贴 收藏
视频较早的时候就说是要录了, 这一周录了 ......
//下面的代码运行正常
tomstrs=re.findall(......)
mtxx=''
for tomstr in tomstrs:
tomstr=tomstr.strip()
if tomstr:
mtxx += tomstr ......