Source code

Revision control

Copy as Markdown

Other Tools

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at
import json
import unittest
from urllib.error import URLError
from urllib.request import urlopen
from compare_locales import plurals
class TestPlural(unittest.TestCase):
'''Integration test for plural forms and l10n-central.
Having more plural forms than in l10n-central is OK, missing or
mismatching ones isn't.
Depends on Transvision.
maxDiff = None
def test_valid_forms(self):
reference_form_map = self._load_transvision()
# Strip matches from dicts, to make diff for test small
locales = list(reference_form_map)
cl_form_map = {}
for locale in locales:
cl_form = str(plurals.get_plural_rule(locale))
if cl_form == reference_form_map[locale]:
cl_form_map[locale] = cl_form
self.assertDictEqual(reference_form_map, cl_form_map)
def _load_transvision(self):
'''Use the Transvision API to load all values of pluralRule
Skip test on load failure.
data = urlopen(TRANSVISION_URL).read()
except URLError:
raise unittest.SkipTest("Couldn't load Transvision API.")
return json.loads(data)