PageRenderTime 141ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/regressiontests/i18n/test_warnings.py

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