个人答案,仅供参考
直接写出11-2
city_functions.py
def get_city_country(city,country,population=''):
if population:
full_name = city+','+country+'-population '+population
else:
full_name = city+','+country
return full_name
test_cities.py
import unittest
from city_function import get_city_country
class CitiesTestCase(unittest.TestCase):
"""测试"""
def test_city_country(self):
"""无面积的测试"""
formatted_name = get_city_country('*','Chian')
self.assertEqual(formatted_name,'*,Chian')
def test_city_country_population(self):
formatted_name = get_city_country('*','Chian','13.95亿')
self.assertEqual(formatted_name,'*,Chian-population 13.95亿')
unittest.main()