Removed warnings level handling code as per deprecation TL.

This commit is contained in:
Ramiro Morales 2013-06-28 13:10:34 -03:00
parent e1dd24d2f6
commit 4f6be9a0c4
3 changed files with 0 additions and 75 deletions

View File

@ -162,10 +162,6 @@ class SimpleTestCase(ut2.TestCase):
# Can be overridden in derived classes. # Can be overridden in derived classes.
client_class = Client client_class = Client
_warn_txt = ("save_warnings_state/restore_warnings_state "
"django.test.*TestCase methods are deprecated. Use Python's "
"warnings.catch_warnings context manager instead.")
def __call__(self, result=None): def __call__(self, result=None):
""" """
Wrapper around default __call__ method to perform common Django test Wrapper around default __call__ method to perform common Django test
@ -225,21 +221,6 @@ class SimpleTestCase(ut2.TestCase):
settings.ROOT_URLCONF = self._old_root_urlconf settings.ROOT_URLCONF = self._old_root_urlconf
clear_url_caches() clear_url_caches()
def save_warnings_state(self):
"""
Saves the state of the warnings module
"""
warnings.warn(self._warn_txt, DeprecationWarning, stacklevel=2)
self._warnings_state = warnings.filters[:]
def restore_warnings_state(self):
"""
Restores the state of the warnings module to the state
saved by save_warnings_state()
"""
warnings.warn(self._warn_txt, DeprecationWarning, stacklevel=2)
warnings.filters = self._warnings_state[:]
def settings(self, **kwargs): def settings(self, **kwargs):
""" """
A context manager that temporarily sets a setting and reverts A context manager that temporarily sets a setting and reverts

View File

@ -124,31 +124,6 @@ def teardown_test_environment():
del mail.outbox del mail.outbox
warn_txt = ("get_warnings_state/restore_warnings_state functions from "
"django.test.utils are deprecated. Use Python's warnings.catch_warnings() "
"context manager instead.")
def get_warnings_state():
"""
Returns an object containing the state of the warnings module
"""
# There is no public interface for doing this, but this implementation of
# get_warnings_state and restore_warnings_state appears to work on Python
# 2.4 to 2.7.
warnings.warn(warn_txt, DeprecationWarning, stacklevel=2)
return warnings.filters[:]
def restore_warnings_state(state):
"""
Restores the state of the warnings module when passed an object that was
returned by get_warnings_state()
"""
warnings.warn(warn_txt, DeprecationWarning, stacklevel=2)
warnings.filters = state[:]
def get_runner(settings, test_runner_class=None): def get_runner(settings, test_runner_class=None):
if not test_runner_class: if not test_runner_class:
test_runner_class = settings.TEST_RUNNER test_runner_class = settings.TEST_RUNNER

View File

@ -270,37 +270,6 @@ class AssertTemplateUsedContextManagerTests(TestCase):
render_to_string('template_used/alternative.html') render_to_string('template_used/alternative.html')
class SaveRestoreWarningState(TestCase):
def test_save_restore_warnings_state(self):
"""
Ensure save_warnings_state/restore_warnings_state work correctly.
"""
# In reality this test could be satisfied by many broken implementations
# of save_warnings_state/restore_warnings_state (e.g. just
# warnings.resetwarnings()) , but it is difficult to test more.
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
self.save_warnings_state()
class MyWarning(Warning):
pass
# Add a filter that causes an exception to be thrown, so we can catch it
warnings.simplefilter("error", MyWarning)
self.assertRaises(Warning, lambda: warnings.warn("warn", MyWarning))
# Now restore.
self.restore_warnings_state()
# After restoring, we shouldn't get an exception. But we don't want a
# warning printed either, so we have to silence the warning.
warnings.simplefilter("ignore", MyWarning)
warnings.warn("warn", MyWarning)
# Remove the filter we just added.
self.restore_warnings_state()
class HTMLEqualTests(TestCase): class HTMLEqualTests(TestCase):
def test_html_parser(self): def test_html_parser(self):
element = parse_html('<div><p>Hello</p></div>') element = parse_html('<div><p>Hello</p></div>')