diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-05-03 18:19:18 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-05-03 18:30:07 +0200 |
| commit | 10cf3c64273db407402ea9723569dfc8d059e186 (patch) | |
| tree | 09278a014019f628169ec4774a3ad6fb13650fb4 /django | |
| parent | e9a56606e738c478373d052bbd876ff84afdb995 (diff) | |
Used catch_warnings instead of save/restore methods. Refs #17049.
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/formtools/tests/__init__.py | 27 | ||||
| -rw-r--r-- | django/contrib/sessions/tests.py | 23 |
2 files changed, 22 insertions, 28 deletions
diff --git a/django/contrib/formtools/tests/__init__.py b/django/contrib/formtools/tests/__init__.py index 96d1dda625..88828e8a38 100644 --- a/django/contrib/formtools/tests/__init__.py +++ b/django/contrib/formtools/tests/__init__.py @@ -7,16 +7,12 @@ from django.conf import settings from django.contrib.formtools import preview, utils from django.contrib.formtools.wizard import FormWizard from django.test import TestCase -from django.test.utils import get_warnings_state, restore_warnings_state from django.test.utils import override_settings from django.utils import unittest from django.contrib.formtools.tests.wizard import * from django.contrib.formtools.tests.forms import * -warnings.filterwarnings('ignore', category=PendingDeprecationWarning, - module='django.contrib.formtools.wizard') - success_string = "Done was called!" class TestFormPreview(preview.FormPreview): @@ -41,20 +37,12 @@ class PreviewTests(TestCase): def setUp(self): super(PreviewTests, self).setUp() - self.save_warnings_state() - warnings.filterwarnings('ignore', category=DeprecationWarning, - module='django.contrib.formtools.wizard.legacy') - # Create a FormPreview instance to share between tests self.preview = preview.FormPreview(TestForm) input_template = '<input type="hidden" name="%s" value="%s" />' self.input = input_template % (self.preview.unused_name('stage'), "%d") self.test_data = {'field1':u'foo', 'field1_':u'asdf'} - def tearDown(self): - super(PreviewTests, self).tearDown() - self.restore_warnings_state() - def test_unused_name(self): """ Verifies name mangling to get uniue field name. @@ -130,8 +118,9 @@ class PreviewTests(TestCase): self.test_data.update({'stage':2}) hash = self.preview.security_hash(None, TestForm(self.test_data)) self.test_data.update({'hash':hash, 'bool1':u'False'}) - response = self.client.post('/preview/', self.test_data) - self.assertEqual(response.content, success_string) + with warnings.catch_warnings(record=True): + response = self.client.post('/preview/', self.test_data) + self.assertEqual(response.content, success_string) def test_form_submit_good_hash(self): """ @@ -241,6 +230,16 @@ class WizardTests(TestCase): } ) + def setUp(self): + super(WizardTests, self).setUp() + self.save_warnings_state() + warnings.filterwarnings('ignore', category=DeprecationWarning, + module='django.contrib.formtools.wizard') + + def tearDown(self): + super(WizardTests, self).tearDown() + self.restore_warnings_state() + def test_step_starts_at_zero(self): """ step should be zero for the first form diff --git a/django/contrib/sessions/tests.py b/django/contrib/sessions/tests.py index dbcaea2874..f31c056e65 100644 --- a/django/contrib/sessions/tests.py +++ b/django/contrib/sessions/tests.py @@ -12,11 +12,10 @@ from django.contrib.sessions.backends.file import SessionStore as FileSession from django.contrib.sessions.backends.signed_cookies import SessionStore as CookieSession from django.contrib.sessions.models import Session from django.contrib.sessions.middleware import SessionMiddleware -from django.core.cache.backends.base import CacheKeyWarning from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation from django.http import HttpResponse from django.test import TestCase, RequestFactory -from django.test.utils import override_settings, get_warnings_state, restore_warnings_state +from django.test.utils import override_settings from django.utils import timezone from django.utils import unittest @@ -302,12 +301,10 @@ class CacheDBSessionTests(SessionTestsMixin, TestCase): self.assertTrue(self.session.exists(self.session.session_key)) def test_load_overlong_key(self): - warnings_state = get_warnings_state() - warnings.filterwarnings('ignore', - category=CacheKeyWarning) - self.session._session_key = (string.ascii_letters + string.digits) * 20 - self.assertEqual(self.session.load(), {}) - restore_warnings_state(warnings_state) + with warnings.catch_warnings(record=True) as w: + self.session._session_key = (string.ascii_letters + string.digits) * 20 + self.assertEqual(self.session.load(), {}) + self.assertEqual(len(w), 1) @override_settings(USE_TZ=True) @@ -353,12 +350,10 @@ class CacheSessionTests(SessionTestsMixin, unittest.TestCase): backend = CacheSession def test_load_overlong_key(self): - warnings_state = get_warnings_state() - warnings.filterwarnings('ignore', - category=CacheKeyWarning) - self.session._session_key = (string.ascii_letters + string.digits) * 20 - self.assertEqual(self.session.load(), {}) - restore_warnings_state(warnings_state) + with warnings.catch_warnings(record=True) as w: + self.session._session_key = (string.ascii_letters + string.digits) * 20 + self.assertEqual(self.session.load(), {}) + self.assertEqual(len(w), 1) class SessionMiddlewareTests(unittest.TestCase): |
