mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Issue #9856: Replace deprecation warinigs to raising TypeError in object.__format__
Patch by Florent Xicluna.
This commit is contained in:
parent
bf8f2f9528
commit
2cd8ce4690
3 changed files with 11 additions and 28 deletions
|
@ -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']
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue