PageRenderTime 161ms CodeModel.GetById 80ms app.highlight 5ms RepoModel.GetById 56ms app.codeStats 1ms

/tests/regressiontests/i18n/test_warnings.py

https://code.google.com/p/mango-py/
Python | 44 lines | 36 code | 7 blank | 1 comment | 1 complexity | 0dd0dafdad6e5fdb11b174a938be416b MD5 | raw file
 1from os.path import join, normpath, abspath, dirname
 2import warnings
 3
 4import django
 5from django.conf import settings
 6from django.test.utils import get_warnings_state, restore_warnings_state
 7from django.utils.translation import _trans
 8from django.utils.unittest import TestCase
 9
10
11class DeprecationWarningTests(TestCase):
12
13    def setUp(self):
14        self.warning_state = get_warnings_state()
15        self.old_settings_module = settings.SETTINGS_MODULE
16        settings.SETTINGS_MODULE = 'regressiontests'
17        self.old_locale_paths = settings.LOCALE_PATHS
18
19    def tearDown(self):
20        restore_warnings_state(self.warning_state)
21        settings.SETTINGS_MODULE = self.old_settings_module
22        settings.LOCALE_PATHS = self.old_locale_paths
23
24    def test_warn_if_project_has_locale_subdir(self):
25        """Test that PendingDeprecationWarning is generated when a deprecated project level locale/ subdir is present."""
26        project_path = join(dirname(abspath(__file__)), '..')
27        warnings.filterwarnings('error',
28                "Translations in the project directory aren't supported anymore\. Use the LOCALE_PATHS setting instead\.",
29                PendingDeprecationWarning)
30        _trans.__dict__ = {}
31        self.assertRaises(PendingDeprecationWarning, django.utils.translation.ugettext, 'Time')
32
33    def test_no_warn_if_project_and_locale_paths_overlap(self):
34        """Test that PendingDeprecationWarning isn't generated when a deprecated project level locale/ subdir is also included in LOCALE_PATHS."""
35        project_path = join(dirname(abspath(__file__)), '..')
36        settings.LOCALE_PATHS += (normpath(join(project_path, 'locale')),)
37        warnings.filterwarnings('error',
38                "Translations in the project directory aren't supported anymore\. Use the LOCALE_PATHS setting instead\.",
39                PendingDeprecationWarning)
40        _trans.__dict__ = {}
41        try:
42            django.utils.translation.ugettext('Time')
43        except PendingDeprecationWarning:
44            self.fail("PendingDeprecationWarning shouldn't be raised when settings/project locale and a LOCALE_PATHS member point to the same file system location.")