11.1.1單元測試和測試用例
11.1.2可通過的測試self.assertequal
import unittest
from name_function import get_formatted_name
class namestestcase(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')
unittest.main()
#定義乙個問題,並建立乙個表示調查的anonymoussurvey物件
question = "what language did you first learn to speak?"
my_survey = anonymoussurvey(question)
#顯示問題並儲存答案
my_survey.show_question()
print("enter 'q' at any time to quit.\n")
while true:
response = input("language: ")
if response == 'q':
break
my_survey.store_response(response)
# 顯示調查結果
print("\nthank you to everyone who participated in the survey!")
my_survey.show_results()
11.2.3測試anonymoussurvey類 self.assertin('english', my_survey.responses)
# -*- coding: utf-8 -*-
import unittest
from survey import anonymoussurvey
class testanonmyoussurvey(unittest.testcase):
"""針對anonymoussurvey類的測試"""
def test_store_single_response(self):
"""測試單個答案會被妥善地儲存"""
question = "what language did you first learn to speak?"
my_survey = anonymoussurvey(question)
my_survey.store_response('english')
self.assertin('english', my_survey.responses)
unittest.main()
*****生成器===
yield:返回列表
decorator
11.2.4方法setup()
專案1 外星人入侵
武裝飛船
python教學筆記 python學習筆記(一)
1.eval 函式 eval是單詞evaluate的縮寫,就是 求.的值的意思。eval 函式的作用是把str轉換成list,dict,tuple.li 1 1,2,3 print eval li 1 di 1 print eval di 1 tu 1 2,4,6 print eval tu 1 執...
python學習筆記
coding utf 8 coding utf 8 應該像八股文一樣在每個指令碼的頭部宣告,這是個忠告 為了解決中文相容問題,同時你應該選擇支援 unicode 編碼的編輯器環境,保證在執行指令碼中的每個漢字都是使用 utf 8 編碼過的。cdays 5 exercise 3.py 求0 100之間...
Python 學習筆記
python 學習筆記 def run print running.def execute method method execute run result running.condition false test yes,is true if condition else no,is false ...