diff options
author | Alex Morega <alex@grep.ro> | 2013-07-06 15:31:24 +0200 |
---|---|---|
committer | Alex Morega <alex@grep.ro> | 2013-07-06 15:31:24 +0200 |
commit | e5d41b153696abea5a345d7d584307df08700304 (patch) | |
tree | d9812edc385d3fb08aa563d29062a7acc46e957e /tests/test_core.py | |
parent | 79945ebd708889be3e9a11c3f9258e8627756fbf (diff) | |
download | babel-e5d41b153696abea5a345d7d584307df08700304.tar.gz |
convert unittests to funcs; use os_environ fixture
Diffstat (limited to 'tests/test_core.py')
-rw-r--r-- | tests/test_core.py | 85 |
1 files changed, 29 insertions, 56 deletions
diff --git a/tests/test_core.py b/tests/test_core.py index 4046a30..32d4e2c 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -27,62 +27,35 @@ def os_environ(monkeypatch): return mock_environ -class LocaleEnvironmentTestMixin(object): - - def setUp(self): - self._old_locale_settings = self.current_locale_settings() - - def tearDown(self): - self.reset_locale_settings(self._old_locale_settings) - - def current_locale_settings(self): - settings = {} - for name in ('LC_MESSAGES', 'LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LANG'): - settings[name] = os.environ.get(name) - return settings - - def reset_locale_settings(self, settings): - for name, value in settings.items(): - if value is not None: - os.environ[name] = value - elif name in os.environ: - del os.environ[name] - - -class LocaleTest(LocaleEnvironmentTestMixin, unittest.TestCase): - - def test_locale_provides_access_to_cldr_locale_data(self): - locale = Locale('en', 'US') - self.assertEqual(u'English (United States)', locale.display_name) - self.assertEqual(u'.', locale.number_symbols['decimal']) - - def test_repr(self): - self.assertEqual("Locale('de', territory='DE')", - repr(Locale('de', 'DE'))) - self.assertEqual("Locale('zh', territory='CN', script='Hans')", - repr(Locale('zh', 'CN', script='Hans'))) - - def test_locale_comparison(self): - en_US = Locale('en', 'US') - self.assertEqual(en_US, en_US) - self.assertNotEqual(None, en_US) - - bad_en_US = Locale('en_US') - self.assertNotEqual(en_US, bad_en_US) - - def test_can_return_default_locale(self): - os.environ['LC_MESSAGES'] = 'fr_FR.UTF-8' - self.assertEqual(Locale('fr', 'FR'), Locale.default('LC_MESSAGES')) - - -class DefaultLocaleTest(LocaleEnvironmentTestMixin, unittest.TestCase): - - def test_ignore_invalid_locales_in_lc_ctype(self): - # This is a regression test specifically for a bad LC_CTYPE setting on - # MacOS X 10.6 (#200) - os.environ['LC_CTYPE'] = 'UTF-8' - # must not throw an exception - default_locale('LC_CTYPE') +def test_locale_provides_access_to_cldr_locale_data(): + locale = Locale('en', 'US') + assert u'English (United States)' == locale.display_name + assert u'.' == locale.number_symbols['decimal'] + +def test_locale_repr(): + assert ("Locale('de', territory='DE')" == repr(Locale('de', 'DE'))) + assert ("Locale('zh', territory='CN', script='Hans')" == + repr(Locale('zh', 'CN', script='Hans'))) + +def test_locale_comparison(): + en_US = Locale('en', 'US') + assert en_US == en_US + assert None != en_US + + bad_en_US = Locale('en_US') + assert en_US != bad_en_US + +def test_can_return_default_locale(os_environ): + os_environ['LC_MESSAGES'] = 'fr_FR.UTF-8' + assert Locale('fr', 'FR') == Locale.default('LC_MESSAGES') + + +def test_ignore_invalid_locales_in_lc_ctype(os_environ): + # This is a regression test specifically for a bad LC_CTYPE setting on + # MacOS X 10.6 (#200) + os_environ['LC_CTYPE'] = 'UTF-8' + # must not throw an exception + default_locale('LC_CTYPE') def test_get_global(): |