def test_converter_name(self): self.assertEqual(Country('US').name, 'UNITED STATES') self.assertEqual(Country.fromname('UNITED STATES'), Country('US')) self.assertEqual(Country.fromcode('UNITED STATES', 'name'), Country('US')) with self.assertRaises(CountryReverseError): Country.fromname('ZZZZZ') self.assertEqual(len(get_country_converter('name').codes), 249)
def get_country(self, language): country_match = re.search('\s*\((\w[\w\s]*\w)\)', language) if not country_match: return country_code = country_match.group(1) return Country(country_code) if len(country_code) == 2 else Country.fromcode(country_code, converter='name')
def test_converter_name(self): self.assertEqual(Country('US').name, 'UNITED STATES') self.assertEqual(Country.fromname('UNITED STATES'), Country('US')) self.assertEqual(Country.fromcode('UNITED STATES', 'name'), Country('US')) self.assertRaises(CountryReverseError, lambda: Country.fromname('ZZZZZ')) self.assertEqual(len(country_converters['name'].codes), 249)
def get_country(self, language): country_match = re.search('\s*\((\w[\w\s]*\w)\)', language) if not country_match: return country_code = country_match.group(1) return Country(country_code) if len( country_code) == 2 else Country.fromcode(country_code, converter='name')