#!/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章测试模块(测试函数出问题)的更多相关文章

  1. python从入门到实践 第二章

    python变量赋值: python的变量赋值 可以是单引号 也可以是双引号python 变量赋值的时候不能加()的 比如 name = "My Name is GF"变量赋值的时 ...

  2. python从入门到实践-10章文件和异常(括号问题)

    #!/user/bin/env python# -*- coding:utf-8 -*- # 1.从文件中读取数据with open('pi_digits.txt') as file_object: ...

  3. python从入门到实践-9章类

    #!/user/bin/env python# -*- coding:utf-8 -*- # 类名采用的是驼峰命名法,即将类名中每个单词的首字母大写,而不使用下划线.# 对于每个类,都应紧跟在类定义后 ...

  4. python从入门到实践-8章函数

    #!/user/bin/env python# -*- coding:utf-8 -*- # 给形参指定默认值时,等号两边不要有空格 def function_name("parameter ...

  5. python从入门到实践-7章用户输入和while循环

    #!/user/bin/env python# -*- coding:utf-8 -*- # input() 可以让程序暂停工作# int(input('please input something: ...

  6. python从入门到实践-6章字典

    #!/user/bin/env python# -*- coding:utf-8 -*- # 前面不用空格,后面空格# 访问只能通过keyalien_0 = {'color': 'green', 'p ...

  7. python从入门到实践-5章if语句

    #!/user/bin/env python cars = ['audi','bmw','subaru','toyota']for car in cars: if car == 'bmw': prin ...

  8. python从入门到实践-4章操作列表

    magicians = ['alice','david','carolina']for magician in magicians: print(magician) print(magician.ti ...

  9. Python:从入门到实践--第九章-类--练习

    #.餐馆:创建一个名为Restaurant的类,其方法_init_()设置两个属性:restaurant_name和cuisine_type. #创建一个名为describe_restaurant的方 ...

随机推荐

  1. maven的配置-2019-4-13

    一.Maven的优点 1.  依赖管理 jar 包管理 2.一键构建 (编译-----测试------打包-----安装-----部署 ) 什么是项目构建? 指的是项目从编译-----测试------ ...

  2. 高可用Redis(三):Hash类型

    1.哈希类型键值结构 哈希类型也是key-value结构,key是字符串类型,其value分为两个部分:field和value 其中field部分代表属性,value代表属性对应的值 上面的图里,us ...

  3. oracle查看执行最慢与查询次数最多的sql语句及其执行速度很慢的问题分析

    oracle查看执行最慢与查询次数最多的sql语句 注:本文来源 于<oracle查看执行最慢与查询次数最多的sql语句> 前言 在ORACLE数据库应用调优中,一个SQL的执行次数/频率 ...

  4. axios 拦截器统一在接口增加时间戳参数,防止走缓存。

    request.interceptors.request.use( config => { if (config.method == 'post') { config.data = { ...c ...

  5. iOS开发之HTTP与HTTPS网络请求

    HTTP是互联网中应用最为广泛的一种网络协议,在进入正文之前,先解释什么是网络协议?网络协议为计算机网络中进行数据交换而建立的规则.标准或约定的集合.网络协议是由以下三个要素组成:语义.语法.时序.国 ...

  6. pta总结3

    7-1 抓老鼠啊~亏了还是赚了? (20 分) 某地老鼠成灾,现悬赏抓老鼠,每抓到一只奖励10元,于是开始跟老鼠斗智斗勇:每天在墙角可选择以下三个操作:放置一个带有一块奶酪的捕鼠夹(T),或者放置一块 ...

  7. DDD - 概述 - 模块 (二)

    首先,你必须知道以下DDD构建块: Entities - 实体 Value objects - 值对象 Aggregate roots - 聚合跟 Repositories - 仓储对象 Factor ...

  8. JS全角与半角转化小结

    最近在做PC端网站的页面的一个表单校验,需要把全角输入转化成半角符号.之前没有了解过这些编码的知识,还是得Google一下查查资料,故简单总结一下. 什么是全角.半角 传统上,英语或拉丁字母语言使用的 ...

  9. C++11 带来的新特性 (4)—— 匿名函数(Lambdas)

    1 语法 Lambdas并不是新概念,在其它语言中已经烂大街了.直接进入主题,先看语法: [ captures ] ( params ) specifiers exception attr -> ...

  10. 各种输出速度比较(小白应该来看看,dalao绕道)

    其实这个是修改之后测试的速度,因为之前测量方式有一点问题,经过@复杂的哈皮狗 的正确提醒后更正了一下 之前我一直以为各种输出速度比较是putchar>printf>cout; 但事实上并不 ...