Mercurial > babel > old > babel-test
view babel/tests/core.py @ 534:e8da49740876
catch exception if environment contains an invalid locale setting (fixes #200)
author | fschwarz |
---|---|
date | Fri, 11 Mar 2011 16:20:57 +0000 |
parents | 85e1beadacb0 |
children |
line wrap: on
line source
# -*- coding: utf-8 -*- # # Copyright (C) 2007-2011 Edgewall Software # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://babel.edgewall.org/wiki/License. # # 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 doctest import os import unittest from babel import core from babel.core import default_locale class DefaultLocaleTest(unittest.TestCase): def setUp(self): self._old_locale_settings = self._current_locale_settings() def tearDown(self): self._set_locale_settings(self._old_locale_settings) def _current_locale_settings(self): settings = {} for name in ('LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LANG'): settings[name] = os.environ[name] return settings def _set_locale_settings(self, settings): for name, value in settings.items(): os.environ[name] = value 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 suite(): suite = unittest.TestSuite() suite.addTest(doctest.DocTestSuite(core)) suite.addTest(unittest.makeSuite(DefaultLocaleTest)) return suite if __name__ == '__main__': unittest.main(defaultTest='suite')