summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_class.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py
index b88c4d1..7720cf1 100644
--- a/Lib/test/test_class.py
+++ b/Lib/test/test_class.py
@@ -503,6 +503,56 @@ class ClassTests(unittest.TestCase):
self.assertRaises(TypeError, hash, C2())
+ def testPredefinedAttrs(self):
+ o = object()
+
+ class Custom:
+ pass
+
+ c = Custom()
+
+ methods = (
+ '__class__', '__delattr__', '__dir__', '__eq__', '__format__',
+ '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__',
+ '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__',
+ '__new__', '__reduce__', '__reduce_ex__', '__repr__',
+ '__setattr__', '__sizeof__', '__str__', '__subclasshook__'
+ )
+ for name in methods:
+ with self.subTest(name):
+ self.assertTrue(callable(getattr(object, name, None)))
+ self.assertTrue(callable(getattr(o, name, None)))
+ self.assertTrue(callable(getattr(Custom, name, None)))
+ self.assertTrue(callable(getattr(c, name, None)))
+
+ not_defined = [
+ '__abs__', '__aenter__', '__aexit__', '__aiter__', '__anext__',
+ '__await__', '__bool__', '__bytes__', '__ceil__',
+ '__complex__', '__contains__', '__del__', '__delete__',
+ '__delitem__', '__divmod__', '__enter__', '__exit__',
+ '__float__', '__floor__', '__get__', '__getattr__', '__getitem__',
+ '__index__', '__int__', '__invert__', '__iter__', '__len__',
+ '__length_hint__', '__missing__', '__neg__', '__next__',
+ '__objclass__', '__pos__', '__rdivmod__', '__reversed__',
+ '__round__', '__set__', '__setitem__', '__trunc__'
+ ]
+ augment = (
+ 'add', 'and', 'floordiv', 'lshift', 'matmul', 'mod', 'mul', 'pow',
+ 'rshift', 'sub', 'truediv', 'xor'
+ )
+ not_defined.extend(map("__{}__".format, augment))
+ not_defined.extend(map("__r{}__".format, augment))
+ not_defined.extend(map("__i{}__".format, augment))
+ for name in not_defined:
+ with self.subTest(name):
+ self.assertFalse(hasattr(object, name))
+ self.assertFalse(hasattr(o, name))
+ self.assertFalse(hasattr(Custom, name))
+ self.assertFalse(hasattr(c, name))
+
+ # __call__() is defined on the metaclass but not the class
+ self.assertFalse(hasattr(o, "__call__"))
+ self.assertFalse(hasattr(c, "__call__"))
def testSFBug532646(self):
# Test for SF bug 532646