Loading django/contrib/humanize/tests.py +1 −3 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ from django.conf import settings from django.contrib.humanize.templatetags import humanize from django.template import Template, Context, defaultfilters from django.test import TestCase from django.test.utils import override_settings from django.test.utils import override_settings, TransRealMixin from django.utils.html import escape from django.utils.timezone import utc from django.utils import translation Loading @@ -19,8 +19,6 @@ from django.utils.translation import ugettext as _ from django.utils import tzinfo from django.utils.unittest import skipIf from i18n import TransRealMixin # Mock out datetime in some tests so they don't fail occasionally when they # run too slow. Use a fixed datetime for datetime.now(). DST change in Loading django/test/utils.py +18 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ from contextlib import contextmanager import logging import re import sys from threading import local import time import warnings from functools import wraps Loading Loading @@ -441,6 +442,23 @@ def patch_logger(logger_name, log_level): setattr(logger, log_level, orig) class TransRealMixin(object): """This is the only way to reset the translation machinery. Otherwise the test suite occasionally fails because of global state pollution between tests.""" def flush_caches(self): from django.utils.translation import trans_real trans_real._translations = {} trans_real._active = local() trans_real._default = None trans_real._accepted = {} trans_real._checked_languages = {} def tearDown(self): self.flush_caches() super(TransRealMixin, self).tearDown() # On OSes that don't provide tzset (Windows), we can't set the timezone # in which the program runs. As a consequence, we must skip tests that # don't enforce a specific timezone (with timezone.override or equivalent), Loading tests/defaultfilters/tests.py +1 −2 Original line number Diff line number Diff line Loading @@ -6,13 +6,12 @@ import decimal from django.template.defaultfilters import * from django.test import TestCase from django.test.utils import TransRealMixin from django.utils import six from django.utils import unittest, translation from django.utils.safestring import SafeData from django.utils.encoding import python_2_unicode_compatible from i18n import TransRealMixin class DefaultFiltersTests(TestCase): Loading tests/forms_tests/tests/test_regressions.py +1 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ from django.test import TestCase from django.utils.translation import ugettext_lazy, override from forms_tests.models import Cheese from i18n import TransRealMixin from django.test.utils import TransRealMixin class FormsRegressionsTestCase(TransRealMixin, TestCase): Loading tests/i18n/__init__.py +0 −18 Original line number Diff line number Diff line from threading import local class TransRealMixin(object): """This is the only way to reset the translation machinery. Otherwise the test suite occasionally fails because of global state pollution between tests.""" def flush_caches(self): from django.utils.translation import trans_real trans_real._translations = {} trans_real._active = local() trans_real._default = None trans_real._accepted = {} trans_real._checked_languages = {} def tearDown(self): self.flush_caches() super(TransRealMixin, self).tearDown() Loading
django/contrib/humanize/tests.py +1 −3 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ from django.conf import settings from django.contrib.humanize.templatetags import humanize from django.template import Template, Context, defaultfilters from django.test import TestCase from django.test.utils import override_settings from django.test.utils import override_settings, TransRealMixin from django.utils.html import escape from django.utils.timezone import utc from django.utils import translation Loading @@ -19,8 +19,6 @@ from django.utils.translation import ugettext as _ from django.utils import tzinfo from django.utils.unittest import skipIf from i18n import TransRealMixin # Mock out datetime in some tests so they don't fail occasionally when they # run too slow. Use a fixed datetime for datetime.now(). DST change in Loading
django/test/utils.py +18 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ from contextlib import contextmanager import logging import re import sys from threading import local import time import warnings from functools import wraps Loading Loading @@ -441,6 +442,23 @@ def patch_logger(logger_name, log_level): setattr(logger, log_level, orig) class TransRealMixin(object): """This is the only way to reset the translation machinery. Otherwise the test suite occasionally fails because of global state pollution between tests.""" def flush_caches(self): from django.utils.translation import trans_real trans_real._translations = {} trans_real._active = local() trans_real._default = None trans_real._accepted = {} trans_real._checked_languages = {} def tearDown(self): self.flush_caches() super(TransRealMixin, self).tearDown() # On OSes that don't provide tzset (Windows), we can't set the timezone # in which the program runs. As a consequence, we must skip tests that # don't enforce a specific timezone (with timezone.override or equivalent), Loading
tests/defaultfilters/tests.py +1 −2 Original line number Diff line number Diff line Loading @@ -6,13 +6,12 @@ import decimal from django.template.defaultfilters import * from django.test import TestCase from django.test.utils import TransRealMixin from django.utils import six from django.utils import unittest, translation from django.utils.safestring import SafeData from django.utils.encoding import python_2_unicode_compatible from i18n import TransRealMixin class DefaultFiltersTests(TestCase): Loading
tests/forms_tests/tests/test_regressions.py +1 −1 Original line number Diff line number Diff line Loading @@ -8,7 +8,7 @@ from django.test import TestCase from django.utils.translation import ugettext_lazy, override from forms_tests.models import Cheese from i18n import TransRealMixin from django.test.utils import TransRealMixin class FormsRegressionsTestCase(TransRealMixin, TestCase): Loading
tests/i18n/__init__.py +0 −18 Original line number Diff line number Diff line from threading import local class TransRealMixin(object): """This is the only way to reset the translation machinery. Otherwise the test suite occasionally fails because of global state pollution between tests.""" def flush_caches(self): from django.utils.translation import trans_real trans_real._translations = {} trans_real._active = local() trans_real._default = None trans_real._accepted = {} trans_real._checked_languages = {} def tearDown(self): self.flush_caches() super(TransRealMixin, self).tearDown()