2011-02-12 19:12:36 +00:00
|
|
|
import warnings
|
2011-10-13 21:34:56 +00:00
|
|
|
from os.path import join, normpath, abspath, dirname
|
2011-02-12 19:12:36 +00:00
|
|
|
|
|
|
|
import django
|
|
|
|
from django.conf import settings
|
|
|
|
from django.test.utils import get_warnings_state, restore_warnings_state
|
2011-02-16 22:30:44 +00:00
|
|
|
from django.utils.translation import _trans
|
2011-02-12 19:12:36 +00:00
|
|
|
from django.utils.unittest import TestCase
|
|
|
|
|
|
|
|
|
|
|
|
class DeprecationWarningTests(TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.warning_state = get_warnings_state()
|
|
|
|
self.old_settings_module = settings.SETTINGS_MODULE
|
|
|
|
settings.SETTINGS_MODULE = 'regressiontests'
|
|
|
|
self.old_locale_paths = settings.LOCALE_PATHS
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
restore_warnings_state(self.warning_state)
|
|
|
|
settings.SETTINGS_MODULE = self.old_settings_module
|
|
|
|
settings.LOCALE_PATHS = self.old_locale_paths
|
|
|
|
|
2011-02-12 20:42:39 +00:00
|
|
|
def test_warn_if_project_has_locale_subdir(self):
|
2011-04-02 08:44:47 +00:00
|
|
|
"""Test that DeprecationWarning is generated when a deprecated project level locale/ subdir is present."""
|
2011-02-12 20:42:39 +00:00
|
|
|
project_path = join(dirname(abspath(__file__)), '..')
|
|
|
|
warnings.filterwarnings('error',
|
|
|
|
"Translations in the project directory aren't supported anymore\. Use the LOCALE_PATHS setting instead\.",
|
2011-04-02 08:44:47 +00:00
|
|
|
DeprecationWarning)
|
2011-02-16 22:30:44 +00:00
|
|
|
_trans.__dict__ = {}
|
2011-04-02 08:44:47 +00:00
|
|
|
self.assertRaises(DeprecationWarning, django.utils.translation.ugettext, 'Time')
|
2011-02-12 20:42:39 +00:00
|
|
|
|
2011-02-12 19:12:36 +00:00
|
|
|
def test_no_warn_if_project_and_locale_paths_overlap(self):
|
2011-04-02 08:44:47 +00:00
|
|
|
"""Test that DeprecationWarning isn't generated when a deprecated project level locale/ subdir is also included in LOCALE_PATHS."""
|
2011-02-12 19:12:36 +00:00
|
|
|
project_path = join(dirname(abspath(__file__)), '..')
|
|
|
|
settings.LOCALE_PATHS += (normpath(join(project_path, 'locale')),)
|
2011-02-12 20:42:39 +00:00
|
|
|
warnings.filterwarnings('error',
|
|
|
|
"Translations in the project directory aren't supported anymore\. Use the LOCALE_PATHS setting instead\.",
|
2011-04-02 08:44:47 +00:00
|
|
|
DeprecationWarning)
|
2011-02-16 22:30:44 +00:00
|
|
|
_trans.__dict__ = {}
|
2011-02-12 19:12:36 +00:00
|
|
|
try:
|
|
|
|
django.utils.translation.ugettext('Time')
|
2011-04-02 08:44:47 +00:00
|
|
|
except DeprecationWarning:
|
|
|
|
self.fail("DeprecationWarning shouldn't be raised when settings/project locale and a LOCALE_PATHS member point to the same file system location.")
|