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的方 ...
随机推荐
- Apollo与ROS
Apollo项目基于ROS,但是对其进行了改造,主要包括下面三个方面: 通信性能优化 去中心化网络拓扑 数据兼容性扩展 通信性能优化 自动驾驶车辆中包含了大量的传感器,这些传感器可能以非常高频的速度产 ...
- LightOJ 1372 (枚举 + 树状数组)
题目 Link 输出序列中有多少个组合 {a1,a2,a3,a4,a5,a6}可以构成一个六边形. 分析 序列每个数都不相等. 所以可以设 a1<a2<a3<a4<a5< ...
- css 生成图片添加的十字
<span class="add" title="继续上传"></span> .add { display: inline-block; ...
- 解决SecureCRT中文版"数据库里没找到防火墙'无'"的错误提示
问题描述: 最近从同事那拷贝到一个中文版的SecureCRT,但是每次打开都会有个防火墙的错误提示,“数据库里没找到防火墙“无”.此会话将尝试不通过防火墙进行连接. 出现这个错误的原因是在Secure ...
- VIM 编辑器
可视化模块 进入vi/vim编辑器,按CTRL+V进入可视化模式(VISUAL BLOCK) 2 移动光标上移或者下移,选中多行的开头,如下图所示 3 选择完毕后,按大写的的I键,此时下方会提示进入“ ...
- MySQL 慢查询日志分析工具(pt-query-digest)
1. 慢查询命令: 是否开启和日志路径:show variables like '%slow_query_log%'; 最大查询时间:show variables like '%query_time% ...
- 图像识别与OpenCV——Mat类与Mat_类的内存管理
Mat_类是对Mat类的一个包装,其定义如下: template<typename _Tp> class Mat_ : public Mat { public: //只定义了几个方法 // ...
- 在GNU/Linux下制作Windows 10安装U盘
今年春节回家期间,我需要将家里的一台安装了Debian Stretch的ZaReason笔记本电脑更换为Windows 10系统,好让爸妈从老台式机上的XP系统升级到新的平台上来.回家前,小仙女已在微 ...
- Intellij IDEA 从数据库生成 JPA Entity
首先,需要从调用 Database 窗口 View>Tool Windows>Database 添加到数据库的连接 选择数据的表,然后右击 选择 Scripted Extensions & ...
- js监听用户思否在当前页面
(function () { var t var hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in docume ...