Python编程从入门到实践第十一章-测试代码
11-1 def get_formatted_name(city,country): '''函数返回一个格式为City, Country 的字符串''' full_name = city + country return full_name.title() import unittest from city_functions import get_formatted_name class CityCountryTestCase(unittest.TestCase): def test_city_country(self): formatted_name =get_formatted_name('santiago ', 'chile') self.assertEqual(formatted_name,'Santiago Chile') unittest.main() 11-2 def get_formatted_name(city,country,population=''): full_name = city + country + '-population' + str(population) return full_name.title() import unittest from city_functions import get_formatted_name class