python从入门到实践-11章测试模块(测试函数出问题)
#!/user/bin/env python
# -*- coding:utf-8 -*-
# 用python中unittes中工具来测试代码
# 1.测试函数
import unittest
from name_function import get_formatted_name
class NamesTestCase(unittest.TestCase): # 必须继承unittest.TestCase这个类
# 测试name_function.py
def test_first_last_name(self): # 能够正确处理 janis joplin 这样的姓名吗?
formatted_name = get_formatted_name('janis', 'joplin')
self.assertEqual(formatted_name, 'Janis Joplin') # 断言方法:用来核实得到结果与期望是否一样
# def test_first_last_middle_name(self):
# formatted_name = get_formatted_name('wolfgang', 'mozart', 'amadeus')
# self.assertEqual(formatted_name, 'Wolfgang Amadeus Mozart')
unittest.main()
# 2.测试类
# ———————————————————————unittest Module 中的断言方法——————————————————————
# 方 法 用 途
# ------------------------------------------------------------------------
# assertEqual(a,b) 核实 a==b
# assertNotEqual(a,b) 核实 a!=b
# assertTure(x) 核实 x为Ture
# assertFalse(x) 核实 x为False
# assertIn(item, list) 核实item在list中
# assertNotIn(item, list) 核实item不在list中
# import unittest
# from survey import AnonymouseSurvey
#
#
# class TestAnonymouseSurvey(unittest.TestCase):
# # def test_store_single_response(self):
# # question = "What language did you first learn to speak?"
# # my_survey = AnonymouseSurvey(question)
# # my_survey.store_response('English')
# #
# # self.assertIn('English', my_survey.responses)
# #
# # def test_store_three_response(self):
# # question = "What language did you first learn to speak?"
# # my_survey = AnonymouseSurvey(question)
# # responses = ['English', 'Spanish', 'Chinese', ]
# # for response in responses:
# # my_survey.store_response(response)
# #
# # for response in responses:
# # self.assertIn(response, my_survey.responses)
#
# def setUp(self):
# question = "What language did you first learn to speak?"
# self.my_survey = AnonymouseSurvey(question)
# self.responses = ['English', 'Spanish', 'Chinese', ]
#
# def test_store_single_response(self):
# self.my_survey.store_response(self.responses[0])
# self.assertIn(self.responses[0], self.my_survey.responses)
#
# def test_store_three_respones(self):
# for response in self.responses:
# self.my_survey.store_response(response)
# for response in self.responses:
# self.assertIn(response, self.my_survey.responses)
#
#
# unittest.main
# 注意:每完成一个单元测试python都会打印一个字符;通过打印 . ;引发错误打印 E ;断言失败打印 F 。
python从入门到实践-11章测试模块(测试函数出问题)的更多相关文章
- python从入门到实践 第二章
python变量赋值: python的变量赋值 可以是单引号 也可以是双引号python 变量赋值的时候不能加()的 比如 name = "My Name is GF"变量赋值的时 ...
- python从入门到实践-10章文件和异常(括号问题)
#!/user/bin/env python# -*- coding:utf-8 -*- # 1.从文件中读取数据with open('pi_digits.txt') as file_object: ...
- python从入门到实践-9章类
#!/user/bin/env python# -*- coding:utf-8 -*- # 类名采用的是驼峰命名法,即将类名中每个单词的首字母大写,而不使用下划线.# 对于每个类,都应紧跟在类定义后 ...
- python从入门到实践-8章函数
#!/user/bin/env python# -*- coding:utf-8 -*- # 给形参指定默认值时,等号两边不要有空格 def function_name("parameter ...
- python从入门到实践-7章用户输入和while循环
#!/user/bin/env python# -*- coding:utf-8 -*- # input() 可以让程序暂停工作# int(input('please input something: ...
- python从入门到实践-6章字典
#!/user/bin/env python# -*- coding:utf-8 -*- # 前面不用空格,后面空格# 访问只能通过keyalien_0 = {'color': 'green', 'p ...
- python从入门到实践-5章if语句
#!/user/bin/env python cars = ['audi','bmw','subaru','toyota']for car in cars: if car == 'bmw': prin ...
- python从入门到实践-4章操作列表
magicians = ['alice','david','carolina']for magician in magicians: print(magician) print(magician.ti ...
- Python:从入门到实践--第九章-类--练习
#.餐馆:创建一个名为Restaurant的类,其方法_init_()设置两个属性:restaurant_name和cuisine_type. #创建一个名为describe_restaurant的方 ...
随机推荐
- 内地视频网站对各种浏览器HTML5的支持情况
实在闲得蛋疼 2017/10/1
- ASP.NET Core + Vue.js 开发
1.新建 项目文件夹 pro,在 VS CODE 打开终端,输入dotnet new mvc 命令,新建asp.net core项目. 2.在Startup.cs添加webpack的引用与配置 usi ...
- centOS设置开机自启
原文:https://blog.csdn.net/txz317/article/details/49683439 1.利用 chkconfig 来配置启动级别 在CentOS或者RedHat其他系统下 ...
- PADS Layout VX.2.3 制作PCB封装(Decal)时,导入DXF文件
操作系统:Windows 10 x64 工具1:PADS Layout VX.2.3 进入PCB封装编辑器(Decal Editor),点击Drafting Toolbar > Import D ...
- Java Swing 编程 JComboBox 实现模糊查找功能。
废话不多说,直接上代码.代码如下: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util ...
- JAVA BigDecimal 用法
一.BigDecimal 的加减乘除 BigDecimal bignum1 = new BigDecimal("10"); BigDecimal bignum2 = new Big ...
- 末学者笔记--NFS服务和DHCP服务讲解
NFS服务端概述 一.概念: NFS,是Network File System的简写,即网络文件系统.网络文件系统是FreeBSD支持的文件系统中的一种,也被称为NFS:NFS允许一个系统在网络上与他 ...
- angular/cli 常用指令
1.安装@angular/cli npm install -g @angular/cli 2.更新@angular/cli npm uninstall -g @angular/cli npm cach ...
- sqlserver给用户配置存储过程查看权限
对应的数据库->安全性->用户名右键属性-->安全对象-->指定所有对象-->选择服务器,里边有一个 查看定义(view any definition) 选项,勾上.
- unity 时间转换方式
第一种 计时器的写法 带有调用系统时间 using System; using System.Collections; using System.Collections.Generic; using ...