summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_super.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_super.py')
-rw-r--r--Lib/test/test_super.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/Lib/test/test_super.py b/Lib/test/test_super.py
new file mode 100644
index 0000000..fc303ea
--- /dev/null
+++ b/Lib/test/test_super.py
@@ -0,0 +1,79 @@
+"""Unit tests for new super() implementation."""
+
+import sys
+import unittest
+from test import test_support
+
+
+class A:
+ def f(self):
+ return 'A'
+ @classmethod
+ def cm(cls):
+ return (cls, 'A')
+
+class B(A):
+ def f(self):
+ return super().f() + 'B'
+ @classmethod
+ def cm(cls):
+ return (cls, super().cm(), 'B')
+
+class C(A):
+ def f(self):
+ return super().f() + 'C'
+ @classmethod
+ def cm(cls):
+ return (cls, super().cm(), 'C')
+
+class D(C, B):
+ def f(self):
+ return super().f() + 'D'
+ def cm(cls):
+ return (cls, super().cm(), 'D')
+
+class E(D):
+ pass
+
+class F(E):
+ f = E.f
+
+class G(A):
+ pass
+
+
+class TestSuper(unittest.TestCase):
+
+ def testBasicsWorking(self):
+ self.assertEqual(D().f(), 'ABCD')
+
+ def testClassGetattrWorking(self):
+ self.assertEqual(D.f(D()), 'ABCD')
+
+ def testSubclassNoOverrideWorking(self):
+ self.assertEqual(E().f(), 'ABCD')
+ self.assertEqual(E.f(E()), 'ABCD')
+
+ def testUnboundMethodTransferWorking(self):
+ self.assertEqual(F().f(), 'ABCD')
+ self.assertEqual(F.f(F()), 'ABCD')
+
+ def testClassMethodsStillWorking(self):
+ self.assertEqual(A.cm(), (A, 'A'))
+ self.assertEqual(A().cm(), (A, 'A'))
+ self.assertEqual(G.cm(), (G, 'A'))
+ self.assertEqual(G().cm(), (G, 'A'))
+
+ def testSuperInClassMethodsWorking(self):
+ d = D()
+ self.assertEqual(d.cm(), (d, (D, (D, (D, 'A'), 'B'), 'C'), 'D'))
+ e = E()
+ self.assertEqual(e.cm(), (e, (E, (E, (E, 'A'), 'B'), 'C'), 'D'))
+
+
+def test_main():
+ test_support.run_unittest(TestSuper)
+
+
+if __name__ == "__main__":
+ unittest.main()