Skip to content

Commit

Permalink
Made warning assertions work with or without -Wall python switch
Browse files Browse the repository at this point in the history
  • Loading branch information
claudep committed May 3, 2012
1 parent 10cf3c6 commit 00c0d3c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions django/contrib/sessions/tests.py
Expand Up @@ -302,6 +302,7 @@ def test_exists_searches_cache_first(self):

def test_load_overlong_key(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
self.session._session_key = (string.ascii_letters + string.digits) * 20
self.assertEqual(self.session.load(), {})
self.assertEqual(len(w), 1)
Expand Down
2 changes: 2 additions & 0 deletions tests/regressiontests/cache/tests.py
Expand Up @@ -469,11 +469,13 @@ def func(key, *args):

try:
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
# 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:
warnings.simplefilter("always")
# memcached limits key length to 250
self.cache.set('a' * 251, 'value')
self.assertEqual(len(w), 1)
Expand Down
3 changes: 1 addition & 2 deletions tests/regressiontests/decorators/tests.py
Expand Up @@ -122,7 +122,7 @@ def test_cache_page_old_style(self):
"""
def my_view(request):
return "response"
with warnings.catch_warnings(record=True) as w:
with warnings.catch_warnings(record=True):
my_view_cached = cache_page(my_view, 123)
self.assertEqual(my_view_cached(HttpRequest()), "response")
my_view_cached2 = cache_page(my_view, 123, key_prefix="test")
Expand All @@ -131,7 +131,6 @@ def my_view(request):
self.assertEqual(my_view_cached3(HttpRequest()), "response")
my_view_cached4 = cache_page()(my_view)
self.assertEqual(my_view_cached4(HttpRequest()), "response")
self.assertEqual(len(w), 4)

def test_require_safe_accepts_only_safe_methods(self):
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/regressiontests/requests/tests.py
Expand Up @@ -397,9 +397,8 @@ def test_raw_post_data_returns_body(self):
'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(len(w), 1)

def test_POST_connection_error(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/regressiontests/utils/text.py
Expand Up @@ -79,7 +79,7 @@ def test_old_truncate_words(self):
text.truncate_words('The quick brown fox jumped over the lazy dog.', 4))
self.assertEqual(u'The quick brown fox ....',
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):
with warnings.catch_warnings(record=True) as w:
Expand All @@ -91,7 +91,7 @@ def test_old_truncate_html_words(self):
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>',
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):
digits = '1234 67 9'
Expand Down

0 comments on commit 00c0d3c

Please sign in to comment.