]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
plurals: Fix selection for chinese 249/head
authorMichael Birtwell <michael.birtwell@gmail.com>
Wed, 21 Oct 2015 21:01:59 +0000 (22:01 +0100)
committerMichael Birtwell <michael.birtwell@gmail.com>
Wed, 21 Oct 2015 21:01:59 +0000 (22:01 +0100)
Provide only one option in chinese. The 3 previous options where all the
same any how and I've checked with a chinese colleague she thinks that
applies to all variants on the chinese language.

Refactor the get_plural tests a bit so they are split up to test specific
things

babel/messages/plurals.py
tests/messages/test_plurals.py

index c00a211088bfbbcfa16ad1761da13a754b45d403..05f91102b01b641cb927361864d0349af7600630 100644 (file)
@@ -192,10 +192,8 @@ PLURALS = {
     'vi': (1, '0'),
     # Xhosa - From Pootle's PO's
     'xh': (2, '(n != 1)'),
-    # Chinese - From Pootle's PO's
-    'zh_CN': (1, '0'),
-    'zh_HK': (1, '0'),
-    'zh_TW': (1, '0'),
+    # Chinese - From Pootle's PO's (modified)
+    'zh': (1, '0'),
 }
 
 
index 9466decfc6f722241f2d0d45402c478d01c69226..8c11745ffc693575215ab0a685c9fa2acc679226 100644 (file)
 # This software consists of voluntary contributions made by many
 # individuals. For the exact contribution history, see the revision
 # history and logs, available at http://babel.edgewall.org/log/.
+import pytest
 
-import doctest
-import unittest
-
+from babel import Locale
 from babel.messages import plurals
 
 
-def test_get_plural():
-    assert plurals.get_plural(locale='en') == (2, '(n != 1)')
+@pytest.mark.parametrize(('locale', 'num_plurals', 'plural_expr'), [
+    (Locale('en'), 2, '(n != 1)'),
+    (Locale('en', 'US'), 2, '(n != 1)'),
+    (Locale('zh'), 1, '0'),
+    (Locale('zh', script='Hans'), 1, '0'),
+    (Locale('zh', script='Hant'), 1, '0'),
+    (Locale('zh', 'CN', 'Hans'), 1, '0'),
+    (Locale('zh', 'TW', 'Hant'), 1, '0'),
+])
+def test_get_plural_selection(locale, num_plurals, plural_expr):
+    assert plurals.get_plural(locale) == (num_plurals, plural_expr)
+
+
+def test_get_plural_accpets_strings():
     assert plurals.get_plural(locale='ga') == (3, '(n==1 ? 0 : n==2 ? 1 : 2)')
 
+
+def test_get_plural_falls_back_to_default():
+    assert plurals.get_plural('aa') == (2, '(n != 1)')
+
+
+def test_plural_tuple_attributes():
     tup = plurals.get_plural("ja")
     assert tup.num_plurals == 1
     assert tup.plural_expr == '0'