题目参照《python编程——从入门到实践》第十一章习题
11-1、11-2
city_functions.py
def city_name(city,country,population=''):
name=city+','+country
if population:
name+='-population '+str(population)
return name.title()
test_city.py
import unittest
from city_functions import city_name
class CityTest(unittest.TestCase):
def test_city_country(self):
name=city_name('santiago','chile')
self.assertEqual(name,'Santiago,Chile')
def test_city_country_population(self):
name=city_name('santiago','chile',population=5000000)
self.assertEqual(name,'Santiago,Chile-Population 5000000')
unittest.main()