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 /tests/regressiontests/cache | |
| parent | e9a56606e738c478373d052bbd876ff84afdb995 (diff) | |
Used catch_warnings instead of save/restore methods. Refs #17049.
Diffstat (limited to 'tests/regressiontests/cache')
| -rw-r--r-- | tests/regressiontests/cache/tests.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py index 16368c6fe9..f0e2977b31 100644 --- a/tests/regressiontests/cache/tests.py +++ b/tests/regressiontests/cache/tests.py @@ -466,20 +466,19 @@ class BaseCacheTests(object): old_func = self.cache.key_func self.cache.key_func = func - # On Python 2.6+ we could use the catch_warnings context - # manager to test this warning nicely. Since we can't do that - # yet, the cleanest option is to temporarily ask for - # CacheKeyWarning to be raised as an exception. - _warnings_state = get_warnings_state() - warnings.simplefilter("error", CacheKeyWarning) try: - # memcached does not allow whitespace or control characters in keys - self.assertRaises(CacheKeyWarning, self.cache.set, 'key with spaces', 'value') - # memcached limits key length to 250 - self.assertRaises(CacheKeyWarning, self.cache.set, 'a' * 251, 'value') + with warnings.catch_warnings(record=True) as w: + # memcached does not allow whitespace or control characters in keys + self.cache.set('key with spaces', 'value') + self.assertEqual(len(w), 2) + self.assertTrue(isinstance(w[0].message, CacheKeyWarning)) + with warnings.catch_warnings(record=True) as w: + # memcached limits key length to 250 + self.cache.set('a' * 251, 'value') + self.assertEqual(len(w), 1) + self.assertTrue(isinstance(w[0].message, CacheKeyWarning)) finally: - restore_warnings_state(_warnings_state) self.cache.key_func = old_func def test_cache_versioning_get_set(self): @@ -1450,7 +1449,8 @@ class CacheMiddlewareTest(TestCase): self.default_cache = get_cache('default') self.other_cache = get_cache('other') self.save_warnings_state() - warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.views.decorators.cache') + warnings.filterwarnings('ignore', category=DeprecationWarning, + module='django.views.decorators.cache') def tearDown(self): self.restore_warnings_state() |
