Mercurial > babel > mirror
annotate babel/tests/core.py @ 590:6f86d60dab56 trunk
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
author | fschwarz |
---|---|
date | Thu, 09 Aug 2012 06:56:23 +0000 |
parents | c938dbfb8944 |
children | d1618dfaf114 |
rev | line source |
---|---|
1 | 1 # -*- coding: utf-8 -*- |
2 # | |
530 | 3 # Copyright (C) 2007-2011 Edgewall Software |
1 | 4 # All rights reserved. |
5 # | |
6 # This software is licensed as described in the file COPYING, which | |
7 # you should have received as part of this distribution. The terms | |
8 # are also available at http://babel.edgewall.org/wiki/License. | |
9 # | |
10 # This software consists of voluntary contributions made by many | |
11 # individuals. For the exact contribution history, see the revision | |
12 # history and logs, available at http://babel.edgewall.org/log/. | |
13 | |
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 | 16 import unittest |
17 | |
18 from babel import core | |
590
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
19 from babel.core import default_locale, Locale |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
20 |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
21 |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
22 class LocaleTest(unittest.TestCase): |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
23 |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
24 def test_locale_provides_access_to_cldr_locale_data(self): |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
25 locale = Locale('en', 'US') |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
26 self.assertEqual(u'English (United States)', locale.display_name) |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
27 self.assertEqual(u'.', locale.number_symbols['decimal']) |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
28 |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
29 def test_repr(self): |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
30 self.assertEqual("Locale('de', territory='DE')", |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
31 repr(Locale('de', 'DE'))) |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
32 self.assertEqual("Locale('zh', territory='CN', script='Hans')", |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
33 repr(Locale('zh', 'CN', script='Hans'))) |
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
34 |
534
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
35 |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
36 class DefaultLocaleTest(unittest.TestCase): |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
37 |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
38 def setUp(self): |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
39 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
|
40 |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
41 def tearDown(self): |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
42 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
|
43 |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
44 def _current_locale_settings(self): |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
45 settings = {} |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
46 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
|
47 settings[name] = os.environ[name] |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
48 return settings |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
49 |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
50 def _set_locale_settings(self, settings): |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
51 for name, value in settings.items(): |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
52 os.environ[name] = value |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
53 |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
54 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
|
55 # 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
|
56 # MacOS X 10.6 (#200) |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
57 os.environ['LC_CTYPE'] = 'UTF-8' |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
58 # must not throw an exception |
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
59 default_locale('LC_CTYPE') |
1 | 60 |
590
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
61 |
1 | 62 def suite(): |
63 suite = unittest.TestSuite() | |
64 suite.addTest(doctest.DocTestSuite(core)) | |
590
6f86d60dab56
change repr output for babel.Locale so all attributes (territory, script, variant) are shown by itself. This should help identifying bad usage of the Locale class (e.g. Locale('de_DE') instead of Locale('de', 'DE'), #279
fschwarz
parents:
534
diff
changeset
|
65 suite.addTest(unittest.makeSuite(LocaleTest)) |
534
c938dbfb8944
catch exception if environment contains an invalid locale setting (fixes #200)
fschwarz
parents:
530
diff
changeset
|
66 suite.addTest(unittest.makeSuite(DefaultLocaleTest)) |
1 | 67 return suite |
68 | |
69 if __name__ == '__main__': | |
70 unittest.main(defaultTest='suite') |