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/utils | |
| parent | e9a56606e738c478373d052bbd876ff84afdb995 (diff) | |
Used catch_warnings instead of save/restore methods. Refs #17049.
Diffstat (limited to 'tests/regressiontests/utils')
| -rw-r--r-- | tests/regressiontests/utils/text.py | 39 |
1 files changed, 18 insertions, 21 deletions
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...</a></p>', 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'<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', - text.truncate_html_words('<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', 10)) - 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)) - 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, '....')) - 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)) + with warnings.catch_warnings(record=True) as w: + self.assertEqual(u'<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', + text.truncate_html_words('<p><strong><em>The quick brown fox jumped over the lazy dog.</em></strong></p>', 10)) + 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)) + 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, '....')) + 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) def test_wrap(self): digits = '1234 67 9' |
