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把ppt转换成pdf

ppt要想完美的转pdf,图片,还是需要在windows下面来操作。 1,安装python3.5.1 下载地址 Windows x86-64 executable installer,w...

opencv3/C++实现视频背景去除建模(BSM)

opencv3/C++实现视频背景去除建模(BSM)

视频背景建模主要使用到: 高斯混合模型(Mixture Of Gauss,MOG) createBackgroundSubtractorMOG2(int history=500, d...

pytorch对可变长度序列的处理方法详解

pytorch对可变长度序列的处理方法详解

主要是用函数torch.nn.utils.rnn.PackedSequence()和torch.nn.utils.rnn.pack_padded_sequence()以及torch.nn...

python实现斐波那契数列的方法示例

python实现斐波那契数列的方法示例

介绍 斐波那契数列,又称黄金分割数列,指的是这样一个数列:0、1、1、2、3、5、8、13、21、……在数学上,斐波纳契数列以如下递归的方法定义: F(0)=0,F(1)=1,F(n)=...

Python实现Linux的find命令实例分享

Python实现Linux的find命令实例分享

使用Python实现简单Linux的find命令 代码如下: #!/usr/bin/python #*-*coding:utf8*-* from optparse import...