def test_function_errors(self): """ Test function errors :return: void """ sentence_filler = SentenceFiller() data = [ ('nl_BE', 'This is an invalid function --plura l__option 1__option 2__--.', {}), ('bo', 'This is an invalid function --plu(ral__option 1__option 2__--.', {}), ('ar', 'This is an invalid function --plu-ral__option 1__option 2__--.', {}), ('nl_BE', 'This is an invalid function --plura*l__option 1__option 2__--.', {}), ('bo', 'This is an invalid function --plu2ral__option 1__option 2__--.', {}), ('ar', 'This is an invalid function --pl^ural__option 1__option 2__--.', {}), ] for locale_str, given, params in data: locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') number = Number(locale) time_instance = Time(locale, time_zone) localization = Localization(locale, number, time_instance) with self.assert_raises_regexp(SentenceFillerError, 'Function ".*?" was not valid.'): sentence_filler.fill_in(localization, given, params=params) data = [ ('nl_BE', 'This is an invalid function --plurale__option 1__option 2__--.', {}), ('bo', 'This is an invalid function --plura__option 1__option 2__--.', {}), ('ar', 'This is an invalid function --plur_al__option 1__option 2__--.', {}), ] for locale_str, given, params in data: locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') number = Number(locale) time_instance = Time(locale, time_zone) localization = Localization(locale, number, time_instance) with self.assert_raises_regexp( SentenceFillerError, 'Using non-existing function "\w+".'): sentence_filler.fill_in(localization, given, params=params)
def test_param_errors(self): """ Test param errors :return: void """ sentence_filler = SentenceFiller() data = [ ('nl_BE', 'Have an invalid parameter: {param}.', { 'param': { 'value': 1 } }), ('bo', 'Have another invalid parameter: {param}.', { 'param': (1, 2, 3) }), ] for locale_str, given, params in data: locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') number = Number(locale) time_instance = Time(locale, time_zone) localization = Localization(locale, number, time_instance) with self.assert_raises_regexp( SentenceFillerError, 'Invalid param type .*? found for "\w+"'): sentence_filler.fill_in(localization, given, params=params) data = [ ('ar', 'Irreplaceable parameter: {param}.', { 'param_a': { 'value': 1 } }), ('bo', 'Have another irreplaceable parameter: {param}.', { 'param_b': (1, 2, 3) }), ] for locale_str, given, params in data: locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') number = Number(locale) time_instance = Time(locale, time_zone) localization = Localization(locale, number, time_instance) with self.assert_raises_regexp( SentenceFillerError, 'Param "param" could not be replaced.'): sentence_filler.fill_in(localization, given, params=params)
def test_date(self): """ Test date :return: void """ locale = Locale.parse('nl_BE', sep='_') time_zone = get_timezone('Europe/Brussels') time_obj = Time(locale=locale, time_zone=time_zone) data = [ ('9/05/92', date(1992, 5, 9), Time.SHORT), ('3 apr. 2004', date(2004, 4, 3), Time.MEDIUM), ('18 februari 2016', date(2016, 2, 18), Time.LONG), ('zondag 30 juli 2017', date(2017, 7, 30), Time.FULL), ] for expected, given_date, given_format in data: self.assert_equal( expected, Encoding.normalize(time_obj.date(given_date, given_format)))
def test_general(self): """ Test general :return: void """ locale = Locale.parse('nl_BE', sep='_') time_zone = get_timezone('Europe/Brussels') time_obj = Time(locale=locale, time_zone=time_zone) self.assert_is_instance(time_obj.time_zone, DstTzInfo)
def test_time(self): """ Test time :return: void """ locale = Locale.parse('nl_BE', sep='_') time_zone = get_timezone('Europe/Brussels') time_obj = Time(locale=locale, time_zone=time_zone) data = [ ('05:26', time(5, 26, 13), Time.SHORT), ('05:06:07', time(5, 6, 7), Time.MEDIUM), ('14:26:57 CET', time(14, 26, 57), Time.LONG), ('01:02:03 Midden-Europese standaardtijd', time(1, 2, 3), Time.FULL), ] for expected, given_time, given_format in data: self.assert_equal( expected, Encoding.normalize(time_obj.time(given_time, given_format)))
def test_interval(self): """ Test interval :return: void """ locale = Locale.parse('nl_BE', sep='_') time_zone = get_timezone('Europe/Brussels') time_obj = Time(locale=locale, time_zone=time_zone) data = [ ('09:05:23 - 14:05:06', time(9, 5, 23), time(14, 5, 6)), ('3 apr. 2004 07:06:07 - 30 jul. 2017 03:02:03', datetime(2004, 4, 3, 5, 6, 7), datetime(2017, 7, 30, 1, 2, 3)), ('18 feb. 2016 15:26:57 - 30 jul. 2017 02:00:00', datetime(2016, 2, 18, 14, 26, 57), date(2017, 7, 30)), ('9 mei 1992 - 30 jul. 2017', date(1992, 5, 9), date(2017, 7, 30)), ] for expected, given_start, given_end in data: self.assert_equal( expected, Encoding.normalize(time_obj.interval(given_start, given_end)))
def test_rtl(self): """ Test rtl :return: void """ locale = Locale.parse('nl_BE', sep='_') time_zone = get_timezone('Europe/Brussels') time_obj = Time(locale=locale, time_zone=time_zone) number_obj = Number(locale=locale) localization_obj = Localization(locale=locale, number=number_obj, time=time_obj) self.assert_false(localization_obj.rtl) locale = Locale.parse('ar_DZ', sep='_') time_zone = get_timezone('Europe/Brussels') time_obj = Time(locale=locale, time_zone=time_zone) number_obj = Number(locale=locale) localization_obj = Localization(locale=locale, number=number_obj, time=time_obj) self.assert_true(localization_obj.rtl)
def __init__(self, app, most_accurate_locale, supported_locale, fallback_locale, translator, time_zone): """ Constructor :param app: The app :type app: edmunds.application.Application :param most_accurate_locale: The most accurate locale :type most_accurate_locale: babel.core.Locale :param supported_locale: The supported locale :type supported_locale: babel.core.Locale :param fallback_locale: The fallback locale :type fallback_locale: babel.core.Locale :param translator: The translator :type translator: edmunds.localization.translations.drivers.basedriver.BaseDriver :param time_zone: The time zone :type time_zone: pytz.tzinfo.DstTzInfo """ self._app = app self._translator = translator most_accurate_number = Number(most_accurate_locale) most_accurate_time = Time(most_accurate_locale, time_zone) self._most_accurate_localization = Localization( most_accurate_locale, most_accurate_number, most_accurate_time) supported_number = Number(supported_locale) supported_time = Time(supported_locale, time_zone) self._supported_localization = Localization(supported_locale, supported_number, supported_time) fallback_number = Number(fallback_locale) fallback_time = Time(fallback_locale, time_zone) self._fallback_localization = Localization(fallback_locale, fallback_number, fallback_time)
def test_datetime(self): """ Test datetime :return: void """ locale = Locale.parse('nl_BE', sep='_') time_zone = get_timezone('Europe/Brussels') time_obj = Time(locale=locale, time_zone=time_zone) data = [ ('9/05/92 07:26', datetime(1992, 5, 9, 5, 26, 13), Time.SHORT), ('3 apr. 2004 07:06:07', datetime(2004, 4, 3, 5, 6, 7), Time.MEDIUM), ('18 februari 2016 15:26:57 CET', datetime(2016, 2, 18, 14, 26, 57), Time.LONG), ('zondag 30 juli 2017 03:02:03 Midden-Europese zomertijd', datetime(2017, 7, 30, 1, 2, 3), Time.FULL), ] for expected, given_datetime, given_format in data: self.assert_equal( expected, Encoding.normalize( time_obj.datetime(given_datetime, given_format)))
def test_localization(self): """ Test localization :return: void """ locale = Locale.parse('nl_BE', sep='_') time_zone = get_timezone('Europe/Brussels') time_obj = Time(locale=locale, time_zone=time_zone) number_obj = Number(locale=locale) localization_obj = Localization(locale=locale, number=number_obj, time=time_obj) self.assert_is_instance(localization_obj.locale, Locale) self.assert_is_instance(localization_obj.number, Number) self.assert_is_instance(localization_obj.time, Time) self.assert_is_instance(localization_obj.rtl, bool)
def test_get_errors(self): """ Test get errors :return: void """ rule = '/' + self.rand_str(20) # Write config and create app self.write_config(self.config) app = self.create_application() data = [ ('en', 'unknownkey1', {}), ('nl', 'unknownkey2', {}), ('nl_BE', 'unknownkey3', {}), ('bo', 'unknownkey1', {}), ('ar', 'unknownkey2', {}), ('nl', 'smashing', {}), ('nl_BE', 'smashing', {}), ('nl_BE', 'beautiful', { 'name': 'Steve' }), ] for locale_str, key, params in data: with app.test_request_context(rule): locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') time_obj = Time(locale=locale, time_zone=time_zone) number_obj = Number(locale=locale) localization_obj = Localization(locale=locale, number=number_obj, time=time_obj) # Fetch driver driver = app.localization().translator() self.assert_is_instance(driver, ConfigTranslator) with self.assert_raises_regexp( TranslationError, 'Could not find the sentence for locale "%s" and key "%s".' % (locale_str, key)): driver.get(localization_obj, key, params)
def test_gender_function(self): """ Test gender function :return: void """ sentence_filler = SentenceFiller() data = [ ('nl_BE', 'He wrote some code today.', '--gender:{gender}__He wrote__She wrote-- some code today.', { 'gender': 'M' }), ('nl_BE', 'She wrote some code today.', '--gender:{gender}__He wrote__She wrote-- some code today.', { 'gender': 'F' }), ('bo', 'What does this have to do with him?', 'What does this have to do with --gender:{gender}__him__her--?', { 'gender': 'M' }), ('bo', 'What does this have to do with her?', 'What does this have to do with --gender:{gender}__him__her--?', { 'gender': 'F' }), ('ar', 'The cat is a he.', 'The cat is a --gender:{gender}__he__she--.', { 'gender': 'M' }), ('ar', 'The cat is a she.', 'The cat is a --gender:{gender}__he__she--.', { 'gender': 'F' }), ] for locale_str, expected, given, params in data: locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') number = Number(locale) time_instance = Time(locale, time_zone) localization = Localization(locale, number, time_instance) self.assert_equal( expected, sentence_filler.fill_in(localization, given, params=params))
def test_get(self): """ Test get :return: void """ rule = '/' + self.rand_str(20) # Write config and create app self.write_config(self.config) app = self.create_application() data = [ ('en', 'A smashing sentence!', 'smashing', {}), ('en', 'This is a beautiful translation. Is it not, Steve?', 'beautiful', { 'name': 'Steve' }), ('nl', 'Dit is een prachtige vertaling. Nietwaar, Steve?', 'beautiful', { 'name': 'Steve' }), ] for locale_str, expected, key, params in data: with app.test_request_context(rule): locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') time_obj = Time(locale=locale, time_zone=time_zone) number_obj = Number(locale=locale) localization_obj = Localization(locale=locale, number=number_obj, time=time_obj) # Fetch driver driver = app.localization().translator() self.assert_is_instance(driver, ConfigTranslator) self.assert_equal(expected, driver.get(localization_obj, key, params))
def test_get_unknown_key(self): """ Test get unknown key :return: void """ rule = '/' + self.rand_str(20) # Write config and create app self.write_config(self.config) app = self.create_application() data = [ ('en', 'beautiful', {}), ('nl', 'beautiful', {}), ] for locale_str, key, params in data: with app.test_request_context(rule): locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') time_obj = Time(locale=locale, time_zone=time_zone) number_obj = Number(locale=locale) localization_obj = Localization(locale=locale, number=number_obj, time=time_obj) # Fetch driver driver = app.localization().translator() self.assert_is_instance(driver, ConfigTranslator) with self.assert_raises_regexp( SentenceFillerError, 'Param "name" could not be replaced. \(locale "%s" and key "%s"\)' % (locale_str, key)): driver.get(localization_obj, key, params)
def test_gender_function_errors(self): """ Test gender function :return: void """ sentence_filler = SentenceFiller() data = [ ('nl_BE', '--gender__He wrote__She wrote-- some code today.', { 'gender': 'M' }), ('bo', 'What does this have to do with --gender:{gender},{gender}__him__her--?', { 'gender': 'F' }), ('ar', 'The cat is a --gender:{gender},{gender},{gender}__he__she--.', { 'gender': 'F' }), ] for locale_str, given, params in data: locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') number = Number(locale) time_instance = Time(locale, time_zone) localization = Localization(locale, number, time_instance) with self.assert_raises_regexp( SentenceFillerError, 'Gender-function requires exactly one argument.'): sentence_filler.fill_in(localization, given, params=params) data = [ ('nl_BE', '--gender:{gender}__He wrote-- some code today.', { 'gender': 'M' }), ('bo', 'What does this have to do with --gender:{gender}__him__her__it--?', { 'gender': 'M' }), ('ar', 'The cat is a --gender:{gender}__he--.', { 'gender': 'F' }), ] for locale_str, given, params in data: locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') number = Number(locale) time_instance = Time(locale, time_zone) localization = Localization(locale, number, time_instance) with self.assert_raises_regexp( SentenceFillerError, 'Gender-function requires exactly two options.'): sentence_filler.fill_in(localization, given, params=params) data = [ ('nl_BE', '--gender:{gender}__He wrote__She wrote-- some code today.', { 'gender': 'O' }), ('bo', 'What does this have to do with --gender:{gender}__him__her--?', { 'gender': 3 }), ('ar', 'The cat is a --gender:{gender}__he__she--.', { 'gender': 'Apache Helicopter' }), ] for locale_str, given, params in data: locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') number = Number(locale) time_instance = Time(locale, time_zone) localization = Localization(locale, number, time_instance) with self.assert_raises_regexp( SentenceFillerError, 'Using unknown gender "[\w\d\s]+".'): sentence_filler.fill_in(localization, given, params=params)
def test_plural_function_errors(self): """ Test plural function errors :return: void """ sentence_filler = SentenceFiller() data = [ ('nl_BE', 'I have got --plural:{eggs},{eggs}__{eggs} egg__{eggs} eggs-- in my hand.', { 'eggs': 0 }), ('bo', 'I have got --plural__{eggs} egg-- in my hand.', { 'eggs': 0 }), ('ar', 'I have got --plural:{eggs},{eggs},{eggs}__{eggs} egg__{eggs} eggs__{eggs} eggz__{eggs} eggk__{eggs} eggl__{eggs} eggo-- in my hand.', { 'eggs': 0 }), ] for locale_str, given, params in data: locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') number = Number(locale) time_instance = Time(locale, time_zone) localization = Localization(locale, number, time_instance) with self.assert_raises_regexp( SentenceFillerError, 'Plural-function requires exactly one argument.'): sentence_filler.fill_in(localization, given, params=params) data = [ ('nl_BE', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs-- in my hand.', { 'eggs': 'eggs' }), ('bo', 'I have got --plural:{eggs}__{eggs} egg-- in my hand.', { 'eggs': time(2, 5, 6) }), ('ar', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs__{eggs} eggz__{eggs} eggk__{eggs} eggl__{eggs} eggo-- in my hand.', { 'eggs': date(1992, 5, 9) }), ] for locale_str, given, params in data: locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') number = Number(locale) time_instance = Time(locale, time_zone) localization = Localization(locale, number, time_instance) with self.assert_raises_regexp( SentenceFillerError, 'Plural-function argument was not an integer.'): sentence_filler.fill_in(localization, given, params=params) data = [ ('nl_BE', 'I have got --plural:{eggs}__{eggs} egg-- in my hand.', { 'eggs': 0 }), ('bo', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs-- in my hand.', { 'eggs': 0 }), ('ar', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs__{eggs} eggz__{eggs}-- in my hand.', { 'eggs': 0 }), ] for locale_str, given, params in data: locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') number = Number(locale) time_instance = Time(locale, time_zone) localization = Localization(locale, number, time_instance) with self.assert_raises_regexp( SentenceFillerError, 'Plural-function requires exactly \d+ options for locale \w+.' ): sentence_filler.fill_in(localization, given, params=params)
def test_plural_function(self): """ Test plural function :return: void """ sentence_filler = SentenceFiller() data = [ ('nl_BE', 'I have got 0 eggs in my hand.', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs-- in my hand.', { 'eggs': 0 }), ('nl_BE', 'I have got 1 egg in my hand.', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs-- in my hand.', { 'eggs': 1 }), ('nl_BE', 'I have got 2 eggs in my hand.', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs-- in my hand.', { 'eggs': 2 }), ('nl_BE', 'I have got 3 eggs in my hand.', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs-- in my hand.', { 'eggs': 3 }), ('bo', 'I have got 0 egg in my hand.', 'I have got --plural:{eggs}__{eggs} egg-- in my hand.', { 'eggs': 0 }), ('bo', 'I have got 1 egg in my hand.', 'I have got --plural:{eggs}__{eggs} egg-- in my hand.', { 'eggs': 1 }), ('bo', 'I have got 2 egg in my hand.', 'I have got --plural:{eggs}__{eggs} egg-- in my hand.', { 'eggs': 2 }), ('bo', 'I have got 3 egg in my hand.', 'I have got --plural:{eggs}__{eggs} egg-- in my hand.', { 'eggs': 3 }), ('ar', 'I have got 0 egg in my hand.', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs__{eggs} eggz__{eggs} eggk__{eggs} eggl__{eggs} eggo-- in my hand.', { 'eggs': 0 }), ('ar', 'I have got 1 eggs in my hand.', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs__{eggs} eggz__{eggs} eggk__{eggs} eggl__{eggs} eggo-- in my hand.', { 'eggs': 1 }), ('ar', 'I have got 2 eggz in my hand.', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs__{eggs} eggz__{eggs} eggk__{eggs} eggl__{eggs} eggo-- in my hand.', { 'eggs': 2 }), ('ar', 'I have got 3 eggk in my hand.', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs__{eggs} eggz__{eggs} eggk__{eggs} eggl__{eggs} eggo-- in my hand.', { 'eggs': 3 }), ('ar', 'I have got 101 eggl in my hand.', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs__{eggs} eggz__{eggs} eggk__{eggs} eggl__{eggs} eggo-- in my hand.', { 'eggs': 101 }), ('ar', 'I have got 11 eggo in my hand.', 'I have got --plural:{eggs}__{eggs} egg__{eggs} eggs__{eggs} eggz__{eggs} eggk__{eggs} eggl__{eggs} eggo-- in my hand.', { 'eggs': 11 }), ] for locale_str, expected, given, params in data: locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone('Europe/Brussels') number = Number(locale) time_instance = Time(locale, time_zone) localization = Localization(locale, number, time_instance) self.assert_equal( expected, sentence_filler.fill_in(localization, given, params=params))
def test_fill_in(self): """ Test fill in :return: void """ sentence_filler = SentenceFiller() utc_tz = get_timezone('UTC') data = [ ('nl_BE', '', '', None, 'Europe/Brussels'), ('nl_BE', '', '', {}, 'Europe/Brussels'), # Params ('nl_BE', 'This is a sentence without any params.', 'This is a sentence without any params.', {}, 'Europe/Brussels'), ('nl_BE', 'This is a sentence with 1 param.', 'This is a sentence with {count} param.', { 'count': 1 }, 'Europe/Brussels'), ('nl_BE', 'The sum of 5 and 9 is 14.', 'The {operation} of {a} and {b} is {result}.', { 'operation': 'sum', 'a': 5, 'b': 9, 'result': 14 }, 'Europe/Brussels'), # Boolean ('nl_BE', 'Previous statement is True.', 'Previous statement is {bool}.', { 'bool': True }, 'Europe/Brussels'), # Float ('nl_BE', 'Divide that by 4 and you get 3,5.', 'Divide that by 4 and you get {float}.', { 'float': 3.5 }, 'Europe/Brussels'), ('en', 'Divide that by 4 and you get 3.5.', 'Divide that by 4 and you get {float}.', { 'float': 3.5 }, 'Europe/Brussels'), ('nl_BE', 'A very large number is 1.345.687,512.', 'A very large number is {float}.', { 'float': 1345687.512 }, 'Europe/Brussels'), ('en', 'A very large number is 1,345,687.512.', 'A very large number is {float}.', { 'float': 1345687.512 }, 'Europe/Brussels'), # Integer ('nl_BE', 'Multiply that by 2 and you get 7.', 'Multiply that by 2 and you get {integer}.', { 'integer': 7 }, 'Europe/Brussels'), ('en', 'Multiply that by 2 and you get 7.', 'Multiply that by 2 and you get {integer}.', { 'integer': 7 }, 'Europe/Brussels'), ('nl_BE', 'A very large number is 1.345.687.', 'A very large number is {integer}.', { 'integer': 1345687 }, 'Europe/Brussels'), ('en', 'A very large number is 1,345,687.', 'A very large number is {integer}.', { 'integer': 1345687 }, 'Europe/Brussels'), # Date ('nl_BE', 'Next appointment is 7 jun. 1992.', 'Next appointment is {date}.', { 'date': date(1992, 6, 7) }, 'Europe/Brussels'), ('en', 'Next appointment is Jun 7, 1992.', 'Next appointment is {date}.', { 'date': date(1992, 6, 7) }, 'Europe/Brussels'), ('nl_BE', 'Next appointment is 7 jun. 1992.', 'Next appointment is {date}.', { 'date': date(1992, 6, 7) }, 'Asia/Chongqing'), ('en', 'Next appointment is Jun 7, 1992.', 'Next appointment is {date}.', { 'date': date(1992, 6, 7) }, 'Asia/Chongqing'), # DateTime ('nl_BE', 'Next appointment is 9 mei 1992 07:26:13.', 'Next appointment is {datetime}.', { 'datetime': datetime(1992, 5, 9, 5, 26, 13, tzinfo=utc_tz) }, 'Europe/Brussels'), ('en', 'Next appointment is May 9, 1992, 7:26:13 AM.', 'Next appointment is {datetime}.', { 'datetime': datetime(1992, 5, 9, 5, 26, 13, tzinfo=utc_tz) }, 'Europe/Brussels'), ('nl_BE', 'Next appointment is 9 mei 1992 13:26:13.', 'Next appointment is {datetime}.', { 'datetime': datetime(1992, 5, 9, 5, 26, 13, tzinfo=utc_tz) }, 'Asia/Chongqing'), ('en', 'Next appointment is May 9, 1992, 1:26:13 PM.', 'Next appointment is {datetime}.', { 'datetime': datetime(1992, 5, 9, 5, 26, 13, tzinfo=utc_tz) }, 'Asia/Chongqing'), # Time ('nl_BE', 'Next appointment is 05:26:13.', 'Next appointment is {time}.', { 'time': time(5, 26, 13, tzinfo=utc_tz) }, 'Europe/Brussels'), ('en', 'Next appointment is 5:26:13 AM.', 'Next appointment is {time}.', { 'time': time(5, 26, 13, tzinfo=utc_tz) }, 'Europe/Brussels'), ('nl_BE', 'Next appointment is 05:26:13.', 'Next appointment is {time}.', { 'time': time(5, 26, 13, tzinfo=utc_tz) }, 'Asia/Chongqing'), ('en', 'Next appointment is 5:26:13 AM.', 'Next appointment is {time}.', { 'time': time(5, 26, 13, tzinfo=utc_tz) }, 'Asia/Chongqing'), # Strings ('nl_BE', 'Divide that by 4 and you get 3.5.', 'Divide that by 4 and you get {float}.', { 'float': '3.5' }, 'Europe/Brussels'), ('en', 'Divide that by 4 and you get 3.5.', 'Divide that by 4 and you get {float}.', { 'float': '3.5' }, 'Europe/Brussels'), ('nl_BE', 'A very large number is 1345687.512.', 'A very large number is {float}.', { 'float': '1345687.512' }, 'Europe/Brussels'), ('en', 'A very large number is 1345687.512.', 'A very large number is {float}.', { 'float': '1345687.512' }, 'Europe/Brussels'), ('nl_BE', 'Multiply that by 2 and you get 7.', 'Multiply that by 2 and you get {integer}.', { 'integer': '7' }, 'Europe/Brussels'), ('en', 'Multiply that by 2 and you get 7.', 'Multiply that by 2 and you get {integer}.', { 'integer': '7' }, 'Europe/Brussels'), ('nl_BE', 'A very large number is 1345687.', 'A very large number is {integer}.', { 'integer': '1345687' }, 'Europe/Brussels'), ('en', 'A very large number is 1345687.', 'A very large number is {integer}.', { 'integer': '1345687' }, 'Europe/Brussels'), ] for locale_str, expected, given, params, time_zone_str in data: locale = Locale.parse(locale_str, sep='_') time_zone = get_timezone(time_zone_str) number = Number(locale) time_instance = Time(locale, time_zone) localization = Localization(locale, number, time_instance) self.assert_equal( expected, sentence_filler.fill_in(localization, given, params=params))