diff options
author | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-12-23 12:27:17 (GMT) |
---|---|---|
committer | Andrew Svetlov <andrew.svetlov@gmail.com> | 2012-12-23 12:27:17 (GMT) |
commit | 2cd8ce469021e851f4ab70106d696136ecddcd51 (patch) | |
tree | a746c3a249d77510a6aa033d2797106e9fd92d72 /Lib | |
parent | bf8f2f9528188ab370aea8698a9951ab0d14ea97 (diff) | |
download | cpython-2cd8ce469021e851f4ab70106d696136ecddcd51.zip cpython-2cd8ce469021e851f4ab70106d696136ecddcd51.tar.gz cpython-2cd8ce469021e851f4ab70106d696136ecddcd51.tar.bz2 |
Issue #9856: Replace deprecation warinigs to raising TypeError in object.__format__
Patch by Florent Xicluna.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_builtin.py | 14 | ||||
-rw-r--r-- | Lib/test/test_unicode.py | 8 |
2 files changed, 7 insertions, 15 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 1ae06a9..036f4f2 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1479,17 +1479,11 @@ class BuiltinTest(unittest.TestCase): # -------------------------------------------------------------------- # Issue #7994: object.__format__ with a non-empty format string is # deprecated - def test_deprecated_format_string(obj, fmt_str, should_raise_warning): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter("always", DeprecationWarning) - format(obj, fmt_str) - if should_raise_warning: - self.assertEqual(len(w), 1) - self.assertIsInstance(w[0].message, DeprecationWarning) - self.assertIn('object.__format__ with a non-empty format ' - 'string', str(w[0].message)) + def test_deprecated_format_string(obj, fmt_str, should_raise): + if should_raise: + self.assertRaises(TypeError, format, obj, fmt_str) else: - self.assertEqual(len(w), 0) + format(obj, fmt_str) fmt_strs = ['', 's'] diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index 6ac62fb..058c83a 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -842,11 +842,9 @@ class UnicodeTest(string_tests.CommonTest, self.assertEqual('{0:d}'.format(G('data')), 'G(data)') self.assertEqual('{0!s}'.format(G('data')), 'string is data') - msg = 'object.__format__ with a non-empty format string is deprecated' - with support.check_warnings((msg, DeprecationWarning)): - self.assertEqual('{0:^10}'.format(E('data')), ' E(data) ') - self.assertEqual('{0:^10s}'.format(E('data')), ' E(data) ') - self.assertEqual('{0:>15s}'.format(G('data')), ' string is data') + self.assertRaises(TypeError, '{0:^10}'.format, E('data')) + self.assertRaises(TypeError, '{0:^10s}'.format, E('data')) + self.assertRaises(TypeError, '{0:>15s}'.format, G('data')) self.assertEqual("{0:date: %Y-%m-%d}".format(I(year=2007, month=8, |