python测试驱动开发实例

yipeiwu_com6年前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使用Qt界面以及逻辑实现方法

python使用Qt界面以及逻辑实现方法

用过Qt的朋友 特别是QtCreator的习惯在界面UI上面对应的CPP中写代码。但是在PyQt中不是这样的。pyQt只是个界面,只会生成界面即UI,就算是一个按钮也需要在python只...

python实现在函数中修改变量值的方法

和其他语言不一样,传递参数的时候,python不允许程序员选择采用传值还是传引用。Python参数传递采用的肯定是“传对象引用”的方式。 实际上,这种方式相当于传值和传引用的一种综合。如...

python 创建一个保留重复值的列表的补码

给定列表a = [1,2,2,3],其子列表b = [1,2]以这样一种排序(a)==排序(b补码)的方式找到一个补全b的列表.在上面的例子中,补码将是[2,3]的列表. 使用列表解析是...

python使用MQTT给硬件传输图片的实现方法

python使用MQTT给硬件传输图片的实现方法

最近因需要用python写一个微服务来用MQTT给硬件传输图片,其中python用的是flask框架,大概流程如下: 协议为: 需要将图片数据封装成多个消息进行传输,每个消息传输的数...

python计算两个矩形框重合百分比的实例

如下所示: def mat_inter(box1,box2): # 判断两个矩形是否相交 # box=(xA,yA,xB,yB) x01, y01, x02, y02 = bo...