Beispiel #1
0
 def test_message_invalid_parameter_syntax(self):
     with self.assertRaises(ICUError):
         icu_format_message("en",
                            "Hey {a b}!",
                            arguments={
                                "a": "you",
                                "b": "!"
                            })
Beispiel #2
0
 def test_icu_support(self):
     message = ("Hello {a}, you have {g, select,"
                "   male {{n, plural,"
                "       =0 {no boys} one {# boy} other {# boys}"
                "   }}"
                "   female {{n, plural,"
                "       =0 {no girls} one {# girl} other {# girls}"
                "   }}"
                "   other {{n, plural,"
                "       =0 {no children} one {# child} other {# children}"
                "   }}"
                "}")
     self.assertEqual(
         icu_format_message("en",
                            message,
                            arguments={
                                "a": "there",
                                "g": "male",
                                "n": 17
                            }),
         "Hello there, you have 17 boys",
     )
     self.assertEqual(
         icu_format_message("en",
                            message,
                            arguments={
                                "a": "there",
                                "g": "female",
                                "n": 18
                            }),
         "Hello there, you have 18 girls",
     )
     self.assertEqual(
         icu_format_message("en",
                            message,
                            arguments={
                                "a": "there",
                                "g": "other",
                                "n": 0
                            }),
         "Hello there, you have no children",
     )
     self.assertEqual(
         icu_format_message(
             "en",
             "Hello, it is {now, date, medium} at {now, time,kk:mm z}",
             arguments={"now": datetime(2020, 2, 11, 16, 51)},
         ),
         "Hello, it is Feb 11, 2020 at 16:51 UTC",
     )
Beispiel #3
0
 def test_no_html_escape(self):
     self.assertEqual(
         icu_format_message(
             "en",
             'Hello <a href="/you?a=n&b=e">you > {param_b}</a> my & friend',
             arguments={"param_b": "> there"},
         ),
         'Hello <a href="/you?a=n&b=e">you > > there</a> my & friend',
     )
Beispiel #4
0
 def test_message_different_arguments(self):
     self.assertEqual(
         icu_format_message("en",
                            "Hey {a} {0} {c}",
                            arguments={
                                "a": "you",
                                "b": "!"
                            }),
         "Hey you {0} {c}",
     )
Beispiel #5
0
 def test_message_numeric_parameter(self):
     self.assertEqual(
         icu_format_message("en",
                            "Hey {a} {0} {b}",
                            arguments={
                                "a": "you",
                                "b": "!",
                                "0": "there"
                            }),
         "Hey you there !",
     )
Beispiel #6
0
 def test_trans_params(self):
     self.assertEqual(
         icu_format_message(
             "en",
             "Hey {a} {param_b} {c}!",
             arguments={
                 "param_b": "there",
                 "a": "you",
                 "d": "tester"
             },
         ),
         "Hey you there {c}!",
     )
Beispiel #7
0
 def test_parameter_list(self):
     with self.assertRaises(InvalidArgsError):
         icu_format_message("en",
                            "Hey {0} {1}!",
                            arguments={"0": ["you ", "there"]})
Beispiel #8
0
 def test_arguments_tuple(self):
     with self.assertRaises(AttributeError):
         icu_format_message("en",
                            "Hey {0} {1}!",
                            arguments=("you", "there"))