python测试驱动开发实例

yipeiwu_com5年前Python基础

本文实例讲述了python测试驱动开发的方法,分享给大家供大家参考。具体方法如下:

import unittest 
from main import Sample 
class SampleTest(unittest.TestCase): 
 
  def setUp(self): 
    print "create a new Sample" 
    self._sample = Sample("b64e5843ca7db8199c405be565fa7f57") 
  def tearDown(self): 
    print "Destory the sample" 
    self._sample = None 
 
  def test_GetVirusNameFromVT(self): 
    "this md5 has the VT info" 
    aSample = Sample("b64e5843ca7db8199c405be565fa7f57") 
    dict_virusName = aSample._GetVirusNameFromVT() 
    self.assertTrue(dict_virusName!=None) 
  def test_GetVirusNameFromVT2(self): 
    "this md5 has not the VT info" 
    aSample = Sample("2b666ffe98e465523e514d2b93b7666a") 
    dict_virusName = aSample._GetVirusNameFromVT () 
    self.assertTrue(len(dict_virusName) == 0) 
 
 
if __name__=="__main__": 
  #unittest.main() 
  suite = unittest.TestLoader().loadTestsFromTestCase(SampleTest) 
  unittest.TextTestRunner(verbosity=2).run(suite) 

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python采集腾讯新闻实例

Python采集腾讯新闻实例

目标是把腾讯新闻主页上所有新闻爬取下来,获得每一篇新闻的名称、时间、来源以及正文。 接下来分解目标,一步一步地做。 步骤1:将主页上所有链接爬取出来,写到文件里。 python在获取ht...

python实现探测socket和web服务示例

操作系统:linux软件环境:Python 2.7.3 用法:复制代码 代码如下:$ ./MonSocket.py # This is check the URI or Socket...

python中Genarator函数用法分析

本文实例讲述了python中Genarator函数用法。分享给大家供大家参考。具体如下: Generator函数的定义与普通函数的定义没有什么区别,只是在函数体内使用yield生成数据项...

python中PS 图像调整算法原理之亮度调整

亮度调整 非线性亮度调整: 对于R,G,B三个通道,每个通道增加相同的增量。 线性亮度调整: 利用HSL颜色空间,通过只对其L(亮度)部分调整,可达到图像亮度的线性调整。但是,RGB和H...

详解解决Python memory error的问题(四种解决方案)

昨天在用用Pycharm读取一个200+M的CSV的过程中,竟然出现了Memory Error!简直让我怀疑自己买了个假电脑,毕竟是8G内存i7处理器,一度怀疑自己装了假的内存条。。。。...