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程序设计有所帮助。

相关文章

OpenCV python sklearn随机超参数搜索的实现

本文介绍了OpenCV python sklearn随机超参数搜索的实现,分享给大家,具体如下: """ 房价预测数据集 使用sklearn执行超参数搜索 """ import ma...

pyqt5 键盘监听按下enter 就登陆的实例

记得导入包,其他按键可类比 def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Enter:...

python3.3使用tkinter开发猜数字游戏示例

利用这个小游戏可以学习一下ython3.3中tkinter的使用方法复制代码 代码如下:# -*- coding: utf-8 -*-import tkinter as tkimport...

Jupyter notebook在mac:linux上的配置和远程访问的方法

upyter Notebook已经逐渐取代IDE成为了多平台上写简单Python脚本或应用的几家选择。 Jupyter Notebook可以通过pip/pip3安装: pip3 inst...

详解Python进阶之切片的误区与高级用法

众所周知,我们可以通过索引值(或称下标)来查找序列类型(如字符串、列表、元组...)中的单个元素,那么,如果要获取一个索引区间的元素该怎么办呢? 切片(slice)就是一种截取索引片段的...