summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_descr.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r--Lib/test/test_descr.py31
1 files changed, 29 insertions, 2 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 09eef8c..e37a984 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1614,10 +1614,14 @@ order (MRO) for bases """
with self.assertRaises(TypeError) as cm:
spam_cm(list)
- self.assertEqual(
- str(cm.exception),
+ expected_errmsg = (
"descriptor 'classmeth' requires a subtype of 'xxsubtype.spamlist' "
"but received 'list'")
+ self.assertEqual(str(cm.exception), expected_errmsg)
+
+ with self.assertRaises(TypeError) as cm:
+ spam_cm.__get__(None, list)
+ self.assertEqual(str(cm.exception), expected_errmsg)
def test_staticmethods(self):
# Testing static methods...
@@ -1952,6 +1956,29 @@ order (MRO) for bases """
self.assertEqual(E().foo.__func__, C.foo) # i.e., unbound
self.assertTrue(repr(C.foo.__get__(C(1))).startswith("<bound method "))
+ @support.impl_detail("testing error message from implementation")
+ def test_methods_in_c(self):
+ # This test checks error messages in builtin method descriptor.
+ # It is allowed that other Python implementations use
+ # different error messages.
+ set_add = set.add
+
+ expected_errmsg = "descriptor 'add' of 'set' object needs an argument"
+
+ with self.assertRaises(TypeError) as cm:
+ set_add()
+ self.assertEqual(cm.exception.args[0], expected_errmsg)
+
+ expected_errmsg = "descriptor 'add' for 'set' objects doesn't apply to a 'int' object"
+
+ with self.assertRaises(TypeError) as cm:
+ set_add(0)
+ self.assertEqual(cm.exception.args[0], expected_errmsg)
+
+ with self.assertRaises(TypeError) as cm:
+ set_add.__get__(0)
+ self.assertEqual(cm.exception.args[0], expected_errmsg)
+
def test_special_method_lookup(self):
# The lookup of special methods bypasses __getattr__ and
# __getattribute__, but they still can be descriptors.