2
from os.path import join, normpath, abspath, dirname
5
from django.conf import settings
6
from django.test.utils import get_warnings_state, restore_warnings_state
7
from django.utils.translation import _trans
8
from django.utils.unittest import TestCase
11
class DeprecationWarningTests(TestCase):
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
20
restore_warnings_state(self.warning_state)
21
settings.SETTINGS_MODULE = self.old_settings_module
22
settings.LOCALE_PATHS = self.old_locale_paths
24
def test_warn_if_project_has_locale_subdir(self):
25
"""Test that DeprecationWarning 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\.",
31
self.assertRaises(DeprecationWarning, django.utils.translation.ugettext, 'Time')
33
def test_no_warn_if_project_and_locale_paths_overlap(self):
34
"""Test that DeprecationWarning 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\.",
42
django.utils.translation.ugettext('Time')
43
except DeprecationWarning:
44
self.fail("DeprecationWarning shouldn't be raised when settings/project locale and a LOCALE_PATHS member point to the same file system location.")