码迷,mamicode.com
首页 > 其他好文 > 详细

测试代码(测试函数)

时间:2019-02-21 23:07:05      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:char   ast   main   cas   UNC   lease   quit   用例   sel   

 

测试函数:

name_function.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/2/21 21:54
# @Author  : solo
# @Site    : 
# @File    : name_function.py
# @Software: PyCharm

def get_formatted_name(first,middle,last,lll):
    full_name = first +   + middle +  + last + lllc
    return full_name.title()

 

names.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/2/21 21:56
# @Author  : solo
# @Site    : 
# @File    : names.py
# @Software: PyCharm

from  name_function import get_formatted_name

print("Enter ‘q‘ at any time to quit.")
while True:
    first = input("\nplease give me a first name:")
    if first == q:
        break
    last = input("\nplease give me a last name:")
    if last == q:
        break

    get_formatted_name = get_formatted_name(first,last)
    print("\tNeatly formatteb name: " + get_formatted_name + ".")

 

执行结果:

Enter q at any time to quit.

please give me a first name:jamea

please give me a last name:kason
    Neatly formatteb name: Jamea Kason.

please give me a first name:q

Process finished with exit code 0

 

 

 

单元测试和测试用例

 

代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/2/21 22:06
# @Author  : solo
# @Site    : 
# @File    : test_name_function.py
# @Software: PyCharm

import unittest
from name_function import get_formatted_name

class NamesTestCase(unittest.TestCase):
    """测试name_function.py"""
    def test_first_last_name(self):
        """能否正确的处理名字?"""
        formatted_name = get_formatted_name(janis,joplin)
        self.assertEqual(formatted_name,Janis Joplin)

unittest.main()

执行结果:

----------------------------------------------------------------------

Ran 0 tests in 0.000s

OK

 

测试代码(测试函数)

标签:char   ast   main   cas   UNC   lease   quit   用例   sel   

原文地址:https://www.cnblogs.com/aszeno/p/10415827.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!