ËÓùý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Óöµ½ÎÊÌâÐèÒª¹Ø±Õ¡£ÎÒÃǶԴËÒýÆðµÄ²»±ã±íʾ±§Ç¸ ......
ÎÒÏÖÔÚÊÇÕâÑùµÄ
¿ªÁËÒ»¸ö×ÓỊ̈߳¬¶ÁÈ¡ÏÂÃæµÄÏûÏ¢
±¾ÒâÊÇ
Python code:
while not self._stopevent.isSet( ):
re=¶ÁȡϲãÏûÏ¢
if re>0:
´¦Àí
else:
pass
¼ÙÈ ......
RT£¬Ã²ËÆPythonÖ®¸¸Ò²ËµÈç¹ûÄãÏÖÔÚ¿ªÊ¼ÐµÄÏîÄ¿µÄ»°£¬×îºÃÊÇÖ±½ÓʹÓÃPython3£¬¿ÉÊÇʵ¼ÊÉÏ´ó¼ÒʹÓõô󲿷ֻ¹ÊÇ2.5£¬¹À¼ÆÓÃ2.6µÄ¶¼²»ÊǺܶ࣬²¢ÇÒÏà¶ÔÓ¦µÄÐí¶àÀ©Õ¹¶¼Ã»ÓÐ3¶ÔÓ¦µÄ°æ±¾¡£
  ......
ÎÒÏëÓÃpythonд·þÎñ¶Ë£¬C#д¿Í»§¶Ë£¬ÁíÍâÏë°Ñ¿Í»§¶ËC#ÖеĶÔÏóÐòÁл¯ºó´«¸ø·þÎñ¶Ë£¬ÓÃpython·´ÐòÁл¯ºóÖØ½¨¶ÔÏ󣬲»ÖªµÀÓÐûÓÐÕâ¸ö¿ÉÄÜ£¿Èç¹ûÓпÉÄÜÄÜ·ñÌṩ¸ö˼·£¿
Ò»ÇнÔÓпÉÄÜ¡£
˼·ÄãÒѾ˵µÄͦÇå³þµÄÁË¡£ ......
ÎÒÏÖÔÚÒª´¦ÀíÊý°ÙÍòÌõÊý¾Ý£¬´¦Àí¹ý³ÌÊÇͨ¹ý±È½ÏÊý¾ÝÀïÊÇ·ñÓÐÖ¸¶¨µÄ×Ö·û´®£¬ÔÙ²åÈëµ½ÁíÍâµÄ±íÖУ¬ÇëÎÊÓÃPythonÈçºÎ¸ßЧÍê³É£¿ÏÈлл¸÷λÁË¡£
½¨Ò飺±ðÖ±½Ó¸úÊý¾Ý¿â±È½Ï¡£Ì«ºÄ·ÑIO¡£
°ÑÄãÐèÒª±È½ÏµÄ×ֶδÓÊý¾Ý ......