From 531f666c163cfa406dfcb6545027001018995051 Mon Sep 17 00:00:00 2001 From: Michael Birtwell Date: Wed, 21 Oct 2015 22:01:59 +0100 Subject: [PATCH] plurals: Fix selection for chinese 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 | 6 ++---- tests/messages/test_plurals.py | 27 ++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/babel/messages/plurals.py b/babel/messages/plurals.py index c00a2110..05f91102 100644 --- a/babel/messages/plurals.py +++ b/babel/messages/plurals.py @@ -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'), } diff --git a/tests/messages/test_plurals.py b/tests/messages/test_plurals.py index 9466decf..8c11745f 100644 --- a/tests/messages/test_plurals.py +++ b/tests/messages/test_plurals.py @@ -10,17 +10,34 @@ # 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' -- 2.47.2