Made warning assertions work with or without -Wall python switch

This commit is contained in:
Claude Paroz 2012-05-03 20:18:05 +02:00
parent 10cf3c6427
commit 00c0d3c44e
5 changed files with 7 additions and 6 deletions

View File

@ -302,6 +302,7 @@ class CacheDBSessionTests(SessionTestsMixin, TestCase):
def test_load_overlong_key(self): def test_load_overlong_key(self):
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
self.session._session_key = (string.ascii_letters + string.digits) * 20 self.session._session_key = (string.ascii_letters + string.digits) * 20
self.assertEqual(self.session.load(), {}) self.assertEqual(self.session.load(), {})
self.assertEqual(len(w), 1) self.assertEqual(len(w), 1)

View File

@ -469,11 +469,13 @@ class BaseCacheTests(object):
try: try:
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
# memcached does not allow whitespace or control characters in keys # memcached does not allow whitespace or control characters in keys
self.cache.set('key with spaces', 'value') self.cache.set('key with spaces', 'value')
self.assertEqual(len(w), 2) self.assertEqual(len(w), 2)
self.assertTrue(isinstance(w[0].message, CacheKeyWarning)) self.assertTrue(isinstance(w[0].message, CacheKeyWarning))
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
# memcached limits key length to 250 # memcached limits key length to 250
self.cache.set('a' * 251, 'value') self.cache.set('a' * 251, 'value')
self.assertEqual(len(w), 1) self.assertEqual(len(w), 1)

View File

@ -122,7 +122,7 @@ class DecoratorsTest(TestCase):
""" """
def my_view(request): def my_view(request):
return "response" return "response"
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True):
my_view_cached = cache_page(my_view, 123) my_view_cached = cache_page(my_view, 123)
self.assertEqual(my_view_cached(HttpRequest()), "response") self.assertEqual(my_view_cached(HttpRequest()), "response")
my_view_cached2 = cache_page(my_view, 123, key_prefix="test") my_view_cached2 = cache_page(my_view, 123, key_prefix="test")
@ -131,7 +131,6 @@ class DecoratorsTest(TestCase):
self.assertEqual(my_view_cached3(HttpRequest()), "response") self.assertEqual(my_view_cached3(HttpRequest()), "response")
my_view_cached4 = cache_page()(my_view) my_view_cached4 = cache_page()(my_view)
self.assertEqual(my_view_cached4(HttpRequest()), "response") self.assertEqual(my_view_cached4(HttpRequest()), "response")
self.assertEqual(len(w), 4)
def test_require_safe_accepts_only_safe_methods(self): def test_require_safe_accepts_only_safe_methods(self):
""" """

View File

@ -397,9 +397,8 @@ class RequestsTests(unittest.TestCase):
'wsgi.input': StringIO(payload) 'wsgi.input': StringIO(payload)
}) })
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True):
self.assertEqual(request.body, request.raw_post_data) self.assertEqual(request.body, request.raw_post_data)
self.assertEqual(len(w), 1)
def test_POST_connection_error(self): def test_POST_connection_error(self):
""" """

View File

@ -79,7 +79,7 @@ class TestUtilsText(SimpleTestCase):
text.truncate_words('The quick brown fox jumped over the lazy dog.', 4)) text.truncate_words('The quick brown fox jumped over the lazy dog.', 4))
self.assertEqual(u'The quick brown fox ....', self.assertEqual(u'The quick brown fox ....',
text.truncate_words('The quick brown fox jumped over the lazy dog.', 4, '....')) text.truncate_words('The quick brown fox jumped over the lazy dog.', 4, '....'))
self.assertEqual(len(w), 3) self.assertGreater(len(w), 0)
def test_old_truncate_html_words(self): def test_old_truncate_html_words(self):
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
@ -91,7 +91,7 @@ class TestUtilsText(SimpleTestCase):
text.truncate_html_words('<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', 4, '....')) text.truncate_html_words('<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', 4, '....'))
self.assertEqual(u'<p><strong><em>The quick brown fox</em></strong></p>', self.assertEqual(u'<p><strong><em>The quick brown fox</em></strong></p>',
text.truncate_html_words('<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', 4, None)) text.truncate_html_words('<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', 4, None))
self.assertEqual(len(w), 4) self.assertGreater(len(w), 0)
def test_wrap(self): def test_wrap(self):
digits = '1234 67 9' digits = '1234 67 9'