diff options
author | Jason Madden <jamadden@gmail.com> | 2017-12-16 11:09:37 -0600 |
---|---|---|
committer | Jason Madden <jamadden@gmail.com> | 2017-12-16 11:09:37 -0600 |
commit | b43a9b5abbb772c58a8b28b38802d0baac90a000 (patch) | |
tree | 5523b7f5ad590572ffdd5f1ca03d8951ce6d4f00 /src | |
parent | 4b63e96e9367f2a03dde559ebb51e90c436de3ec (diff) | |
download | zope-i18n-b43a9b5abbb772c58a8b28b38802d0baac90a000.tar.gz |
100% coverage for provider.py
Diffstat (limited to 'src')
-rw-r--r-- | src/zope/i18n/locales/provider.py | 17 | ||||
-rw-r--r-- | src/zope/i18n/locales/tests/test_locales.py | 6 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/zope/i18n/locales/provider.py b/src/zope/i18n/locales/provider.py index 391a130..3864b7a 100644 --- a/src/zope/i18n/locales/provider.py +++ b/src/zope/i18n/locales/provider.py @@ -26,33 +26,36 @@ class LoadLocaleError(Exception): @implementer(ILocaleProvider) class LocaleProvider(object): - """A locale provider that get's its data from the XML data.""" + """A locale provider that gets its data from the XML data.""" def __init__(self, locale_dir): self._locales = {} self._locale_dir = locale_dir - def loadLocale(self, language=None, country=None, variant=None): - """See zope.i18n.interfaces.locales.ILocaleProvider""" + def _compute_filename(self, language, country, variant): # Creating the filename - if language == None and country == None and variant == None: + if language is None and country is None and variant is None: filename = 'root.xml' else: filename = language if country is not None: - filename += '_'+country + filename += '_' + country if variant is not None: if '_' not in filename: filename += '_' - filename += '_'+variant + filename += '_' + variant filename += '.xml' + return filename + def loadLocale(self, language=None, country=None, variant=None): + """See zope.i18n.interfaces.locales.ILocaleProvider""" + filename = self._compute_filename(language, country, variant) # Making sure we have this locale path = os.path.join(self._locale_dir, filename) if not os.path.exists(path): raise LoadLocaleError( - 'The desired locale is not available.\nPath: %s' % path) + 'The desired locale is not available.\nPath: %s' % path) # Import here to avoid circular imports from zope.i18n.locales.xmlfactory import LocaleFactory diff --git a/src/zope/i18n/locales/tests/test_locales.py b/src/zope/i18n/locales/tests/test_locales.py index 97b8fe3..2b100b8 100644 --- a/src/zope/i18n/locales/tests/test_locales.py +++ b/src/zope/i18n/locales/tests/test_locales.py @@ -59,7 +59,7 @@ class AbstractTestILocaleProviderMixin(object): self.assertEqual(locale.id.variant, 'POSIX') -class TestLocaleProvider(AbstractTestILocaleProvider, TestCase): +class TestLocaleProvider(AbstractTestILocaleProviderMixin, TestCase): def _makeNewProvider(self): return LocaleProvider(datadir) @@ -75,6 +75,10 @@ class TestLocaleProvider(AbstractTestILocaleProvider, TestCase): def test_loadLocaleFailure(self): self.assertRaises(LoadLocaleError, self.locales.loadLocale, 'zzz') + def test_compute_filename_with_variant_no_country(self): + filename = self.locales._compute_filename('en', None, 'variant') + self.assertEqual('en__variant.xml', filename) + class TestLocaleAndProvider(TestCase): |