Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Unified Diff: Lib/test/test_binop.py

Issue 25958: Implicit ABCs have no means of "anti-registration"
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
--- a/Lib/test/test_binop.py Thu Jan 07 10:58:20 2016 -0800
+++ b/Lib/test/test_binop.py Thu Jan 07 12:55:43 2016 -0800
@@ -388,6 +388,54 @@
self.assertEqual(op_sequence(eq, B, V), ['B.__eq__', 'V.__eq__'])
self.assertEqual(op_sequence(le, B, V), ['B.__le__', 'V.__ge__'])
+class E(object):
+ """Class that can test equality"""
+ def __eq__(self, other):
+ return True
+
+class S(E):
+ """Subclass of E that should fail"""
+ __eq__ = None
+class F(object):
+ """Independent class that should fall back"""
+
+class X(object):
+ """Independent class that should fail"""
+ __eq__ = None
+
+class SN(E):
+ """Subclass of E that can test equality, but not non-equality"""
+ __ne__ = None
+
+class XN:
+ """Independent class that can test equality, but not non-equality"""
+ def __eq__(self, other):
+ return True
+ __ne__ = None
+
+class FallbackBlockingTests(unittest.TestCase):
+ """Unit tests for None method blocking"""
+
+ def test_fallback_rmethod_blocking(self):
+ e, f, s, x = E(), F(), S(), X()
Martin Panter 2016/01/09 02:34:57 Maybe move the classes into the test method, to av
abarnert 2016/01/18 20:28:42 Some of the classes are used in multiple test meth
Martin Panter 2016/02/02 03:10:13 Yes the common base class E is shared; that’s why
+ self.assertEqual(e, e)
+ self.assertEqual(e, f)
+ self.assertEqual(f, e)
+ # left operand is checked first
+ self.assertEqual(e, x)
+ self.assertRaises(TypeError, eq, x, e)
+ # S is a subclass, so it's always checked first
+ self.assertRaises(TypeError, eq, e, s)
+ self.assertRaises(TypeError, eq, s, e)
+
+ def test_fallback_ne_blocking(self):
+ e, sn, xn = E(), SN(), XN()
+ self.assertFalse(e != e)
+ self.assertRaises(TypeError, ne, e, sn)
+ self.assertRaises(TypeError, ne, sn, e)
+ self.assertFalse(e != xn)
+ self.assertRaises(TypeError, ne, xn, e)
+
if __name__ == "__main__":
unittest.main()

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+