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的方 ...
随机推荐
- 【interview】卡特兰数
涉及卡特兰数的题目列举,也是组合数学中一些例子: 详解链接 https://zh.wikipedia.org/wiki/%E5%8D%A1%E5%A1%94%E5%85%B0%E6%95%B0 1. ...
- ASP.NET 异步返回的Action (编辑中。。。)
新学.net,最近用到了ABP框架,发现了如下代码: public override async Task<UserDto> Get(EntityDto<long> input ...
- 初识C语言 (四)
分支结构 if语句 C语言中的分支结构语句中的if条件语句,简单if语句的基本结构如下: 其语义是:如果表达式的值为真,则执行其后的语句,否则不执行该语句. 其过程可表示为下图 实例: if(resu ...
- python_urllib2:urlerror和httperror
urllib2的异常错误处理 在我们用urlopen或opener.open方法发出一个请求时,如果urlopen或opener.open不能处理这个response,就产生错误. 这里主要说的是UR ...
- UWP Acrylic Material
文档:https://docs.microsoft.com/en-us/windows/uwp/design/style/acrylic Acrylic 能带来类似 win7 的毛玻璃效果 要使用 A ...
- JVM调优入门之初探
JVM:程序计数器,jvm栈,本地方法栈,堆,方法区 JVM:虚拟机内存又分有:年轻代(eden,servivor s0,servivor s1),年老代(tenured),永久代() 问题1:如何查 ...
- 研究比对搞定博客 canvas-nest.js
经过比对网站源码,发现大的差异,复制代码添加成功. 参考:https://www.cnblogs.com/kexing/p/7264767.html 申请js权限 编辑 具体编辑请自行实验, 附上 ...
- VScode加文件头的方式
在VScode中添加文件头,设置文件编辑者的方式,在软件中查询到file-header插件: 安装好,此时通过是可以生成默认的文件头.如果需要修改配置,在文件=>首选项=>设置中修改: 查 ...
- Pycharm下同一目录的py文件不能相互调用的原因分析
1.首先确保所在目录是Python Package而不是一般的New Stratch File Python Package下有__init___.py或自己建空的__init___.py 2.pyc ...
- 使用SQL-Front启动MySQL8.0报错
这学期学习数据库,电脑上分别装有phpStudy(自带的MySQL版本为5.5)和MySQL8.0.11,于是想用phpStudy中的SQL Front连接到8.0的数据库.手动开启8.0的MySQL ...