谁用过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写一个程序,总是异常退出,但是却没法用try..except来捕捉
由于没法发图片,所以把相关的信息打印出来
异常的信息大致如下:
python.exe遇到问题需要关闭。我们对此引起的不便表示抱歉 ......
RT,貌似Python之父也说如果你现在开始新的项目的话,最好是直接使用Python3,可是实际上大家使用得大部分还是2.5,估计用2.6的都不是很多,并且相对应的许多扩展都没有3对应的版本。
  ......
刚刚开始学python 请教一个问题:
用 def n in range(100):
开始循环
用 % 方法来判断 制循环4次就 打印 '*' * 25个 .
谢谢!在线等....
for i in range(100):
if i%4 == 0:
......
我的mp3标签信息是通过Tag&Rename 软件来修改的
修改的信息如下
Album Title ISRC
77 66 99
---python读取mp3的id3的代码----
from mutagen.mp3 import MP3
import mutagen.id3
......