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的方 ...
随机推荐
- Django --- Django下载和APP创建 ORM (大概步骤)
1,下载: 命令行: pip install django == 1.11.15 pip install -i或 源 django == 1.11.15 pycharm settings 解释器 点 ...
- .Net ABP 框架 service 无法访问
最近在看ABP框架,按照文档写好service后,怎么也访问不到,后来发现,忘记把service类设置为public的了! 不写public ABP框架就不能将这个service映射为controll ...
- python正则表达式--分组、后向引用、前(后)向断言
无名.有名分组 (1)正则表达式—无名分组 从正则表 达式的左边开始看,看到的第一个左括号“(”表示表示第一个分组,第二个表示第二个分组, 依次类推. 需要注意的是,有一个隐含的全局分组(就是索引号为 ...
- Razor Page 文件
Razor Pages 所有的Razor文件都以 .cshtml 结尾.大部分Razor文件都是可浏览的,包含客户端代码和服务器端代码的混合,处理后会将HTML发送到浏览器.这些页面通常被称为“内容页 ...
- http 四大特征
- 【原创】用python连接thrift Server 去执行sql的问题总汇
场景:python和现有产品的结合和应用——python的前瞻性调研 环境:centos7 0.首先确保安装了python和pyhive,下面是连接代码: #!/usr/bin/env python ...
- git pull命令的用法
git pull用法: git pull命令的作用是:取回远程主机某个分支的更新,再与本地的指定分支合并. 一句话总结git pull和git fetch的区别: git pull = git fet ...
- ThoughtWorks的面试总结
今天有幸到ThoughtWorks去面试.我觉得自己的能力与他们的需要有些距离(还不知道面试结果如何). 逻辑测试部分,不是很难,是语言问题.几乎用了1个小时去理解一句表达.在Pair Program ...
- 【玩转开源】BananaPi R2 —— 第三篇 基于Openwrt开发一个简单的路由器
上一篇讲解了R2的网口配置,这一篇我们以BananaPi R2为例子来实现一个简单的路由器:那么一个简单的路由器应该具备什么样的功能呢?最简单的说就是wan+lan+ap这三个功能. 首先wan+la ...
- Linq to Object原理
using System; using System.Collections.Generic; using System.Linq; using System.Threading; namespace ...