annotate babel/tests/core.py @ 534:c938dbfb8944 trunk

catch exception if environment contains an invalid locale setting (fixes #200)
author fschwarz
date Fri, 11 Mar 2011 16:20:57 +0000
parents ca203b2af83c
children 6f86d60dab56
rev   line source
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
2 #
530
ca203b2af83c Update the copyright line.
jruigrok
parents: 12
diff changeset
3 # Copyright (C) 2007-2011 Edgewall Software
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
4 # All rights reserved.
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
5 #
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
8 # are also available at http://babel.edgewall.org/wiki/License.
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
9 #
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
12 # history and logs, available at http://babel.edgewall.org/log/.
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
13
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
14 import doctest
534
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
15 import os
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
16 import unittest
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
17
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
18 from babel import core
534
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
19 from babel.core import default_locale
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
20
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
21 class DefaultLocaleTest(unittest.TestCase):
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
22
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
23 def setUp(self):
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
24 self._old_locale_settings = self._current_locale_settings()
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
25
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
26 def tearDown(self):
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
27 self._set_locale_settings(self._old_locale_settings)
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
28
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
29 def _current_locale_settings(self):
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
30 settings = {}
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
31 for name in ('LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LANG'):
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
32 settings[name] = os.environ[name]
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
33 return settings
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
34
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
35 def _set_locale_settings(self, settings):
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
36 for name, value in settings.items():
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
37 os.environ[name] = value
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
38
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
39 def test_ignore_invalid_locales_in_lc_ctype(self):
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
40 # This is a regression test specifically for a bad LC_CTYPE setting on
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
41 # MacOS X 10.6 (#200)
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
42 os.environ['LC_CTYPE'] = 'UTF-8'
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
43 # must not throw an exception
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
44 default_locale('LC_CTYPE')
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
45
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
46 def suite():
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
47 suite = unittest.TestSuite()
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
48 suite.addTest(doctest.DocTestSuite(core))
534
c938dbfb8944 catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents: 530
diff changeset
49 suite.addTest(unittest.makeSuite(DefaultLocaleTest))
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
50 return suite
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
51
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
52 if __name__ == '__main__':
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
53 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software