summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_builtin.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-10-30 17:37:46 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-10-30 17:37:46 (GMT)
commit7984bff52a9952219a3c15b88ff6514244dd7498 (patch)
treebcf67bde15ab80a95d773d75b6400082ca5e492b /Lib/test/test_builtin.py
parenta1fd5e4bc744bc972691f1d5c23130395e1e306a (diff)
parentd1af5effc214f474bcb1df62eb2089c48f657ee5 (diff)
downloadcpython-7984bff52a9952219a3c15b88ff6514244dd7498.zip
cpython-7984bff52a9952219a3c15b88ff6514244dd7498.tar.gz
cpython-7984bff52a9952219a3c15b88ff6514244dd7498.tar.bz2
Issue #28385: An error message when non-empty format spec is passed to
object.__format__ now contains the name of actual type.
Diffstat (limited to 'Lib/test/test_builtin.py')
-rw-r--r--Lib/test/test_builtin.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index e0cffe1..a792099 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -11,6 +11,7 @@ import os
import pickle
import platform
import random
+import re
import sys
import traceback
import types
@@ -1447,21 +1448,14 @@ 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):
- if should_raise:
- self.assertRaises(TypeError, format, obj, fmt_str)
- else:
- format(obj, fmt_str)
-
- fmt_strs = ['', 's']
-
+ # disallowed
class A:
def __format__(self, fmt_str):
return format('', fmt_str)
- for fmt_str in fmt_strs:
- test_deprecated_format_string(A(), fmt_str, False)
+ self.assertEqual(format(A()), '')
+ self.assertEqual(format(A(), ''), '')
+ self.assertEqual(format(A(), 's'), '')
class B:
pass
@@ -1470,8 +1464,12 @@ class BuiltinTest(unittest.TestCase):
pass
for cls in [object, B, C]:
- for fmt_str in fmt_strs:
- test_deprecated_format_string(cls(), fmt_str, len(fmt_str) != 0)
+ obj = cls()
+ self.assertEqual(format(obj), str(obj))
+ self.assertEqual(format(obj, ''), str(obj))
+ with self.assertRaisesRegex(TypeError,
+ r'\b%s\b' % re.escape(cls.__name__)):
+ format(obj, 's')
# --------------------------------------------------------------------
# make sure we can take a subclass of str as a format spec