summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hp.com>2015-08-06 22:22:54 (GMT)
committerRobert Collins <rbtcollins@hp.com>2015-08-06 22:22:54 (GMT)
commitd84b29f8050f96b981dc13b2e63f7a91358c74a3 (patch)
tree6f9796b115978f800e863c5b1191ca2383935389 /Lib
parent159fbdd805e23e54ba7830ec2c492a511a6d8e89 (diff)
downloadcpython-d84b29f8050f96b981dc13b2e63f7a91358c74a3.zip
cpython-d84b29f8050f96b981dc13b2e63f7a91358c74a3.tar.gz
cpython-d84b29f8050f96b981dc13b2e63f7a91358c74a3.tar.bz2
Issue #4395: Better testing and documentation of binary operators.
Patch by Martin Panter.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_binop.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/test/test_binop.py b/Lib/test/test_binop.py
index 9c4c18e..963aa01 100644
--- a/Lib/test/test_binop.py
+++ b/Lib/test/test_binop.py
@@ -3,6 +3,7 @@
import unittest
from test import support
from operator import eq, ne, lt, gt, le, ge
+from abc import ABCMeta
def gcd(a, b):
"""Greatest common divisor using Euclid's algorithm."""
@@ -332,7 +333,7 @@ class A(OperationLogger):
self.log_operation('A.__ge__')
return NotImplemented
-class B(OperationLogger):
+class B(OperationLogger, metaclass=ABCMeta):
def __eq__(self, other):
self.log_operation('B.__eq__')
return NotImplemented
@@ -354,6 +355,20 @@ class C(B):
self.log_operation('C.__ge__')
return NotImplemented
+class V(OperationLogger):
+ """Virtual subclass of B"""
+ def __eq__(self, other):
+ self.log_operation('V.__eq__')
+ return NotImplemented
+ def __le__(self, other):
+ self.log_operation('V.__le__')
+ return NotImplemented
+ def __ge__(self, other):
+ self.log_operation('V.__ge__')
+ return NotImplemented
+B.register(V)
+
+
class OperationOrderTests(unittest.TestCase):
def test_comparison_orders(self):
self.assertEqual(op_sequence(eq, A, A), ['A.__eq__', 'A.__eq__'])
@@ -369,8 +384,14 @@ class OperationOrderTests(unittest.TestCase):
self.assertEqual(op_sequence(le, B, C), ['C.__ge__', 'B.__le__'])
self.assertEqual(op_sequence(le, C, B), ['C.__le__', 'B.__ge__'])
+ self.assertTrue(issubclass(V, B))
+ self.assertEqual(op_sequence(eq, B, V), ['B.__eq__', 'V.__eq__'])
+ self.assertEqual(op_sequence(le, B, V), ['B.__le__', 'V.__ge__'])
+
+
def test_main():
support.run_unittest(RatTestCase, OperationOrderTests)
+
if __name__ == "__main__":
test_main()