From 10cf3c64273db407402ea9723569dfc8d059e186 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 3 May 2012 18:19:18 +0200 Subject: Used catch_warnings instead of save/restore methods. Refs #17049. --- tests/regressiontests/utils/text.py | 39 +++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'tests/regressiontests/utils') diff --git a/tests/regressiontests/utils/text.py b/tests/regressiontests/utils/text.py index bce7f99264..6457845c6f 100644 --- a/tests/regressiontests/utils/text.py +++ b/tests/regressiontests/utils/text.py @@ -8,13 +8,6 @@ class TestUtilsText(SimpleTestCase): # In Django 1.6 truncate_words() and truncate_html_words() will be removed # so these tests will need to be adapted accordingly - def setUp(self): - self.save_warnings_state() - warnings.filterwarnings('ignore', category=DeprecationWarning, module='django.utils.text') - - def tearDown(self): - self.restore_warnings_state() - def test_truncate_chars(self): truncator = text.Truncator( u'The quick brown fox jumped over the lazy dog.' @@ -79,22 +72,26 @@ class TestUtilsText(SimpleTestCase): 'id="mylink">brown...

', truncator.words(3, '...', html=True)) def test_old_truncate_words(self): - self.assertEqual(u'The quick brown fox jumped over the lazy dog.', - text.truncate_words(u'The quick brown fox jumped over the lazy dog.', 10)) - self.assertEqual(u'The quick brown fox ...', - 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, '....')) + with warnings.catch_warnings(record=True) as w: + self.assertEqual(u'The quick brown fox jumped over the lazy dog.', + text.truncate_words(u'The quick brown fox jumped over the lazy dog.', 10)) + self.assertEqual(u'The quick brown fox ...', + 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) def test_old_truncate_html_words(self): - self.assertEqual(u'

The quick brown fox jumped over the lazy dog.

', - text.truncate_html_words('

The quick brown fox jumped over the lazy dog.

', 10)) - self.assertEqual(u'

The quick brown fox ...

', - text.truncate_html_words('

The quick brown fox jumped over the lazy dog.

', 4)) - self.assertEqual(u'

The quick brown fox ....

', - text.truncate_html_words('

The quick brown fox jumped over the lazy dog.

', 4, '....')) - self.assertEqual(u'

The quick brown fox

', - text.truncate_html_words('

The quick brown fox jumped over the lazy dog.

', 4, None)) + with warnings.catch_warnings(record=True) as w: + self.assertEqual(u'

The quick brown fox jumped over the lazy dog.

', + text.truncate_html_words('

The quick brown fox jumped over the lazy dog.

', 10)) + self.assertEqual(u'

The quick brown fox ...

', + text.truncate_html_words('

The quick brown fox jumped over the lazy dog.

', 4)) + self.assertEqual(u'

The quick brown fox ....

', + text.truncate_html_words('

The quick brown fox jumped over the lazy dog.

', 4, '....')) + self.assertEqual(u'

The quick brown fox

', + text.truncate_html_words('

The quick brown fox jumped over the lazy dog.

', 4, None)) + self.assertEqual(len(w), 4) def test_wrap(self): digits = '1234 67 9' -- cgit v1.3