diff options
author | Georg Brandl <georg@python.org> | 2005-08-24 09:08:57 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2005-08-24 09:08:57 (GMT) |
commit | be3856dcd41b444642a77c93e1f94367741692e7 (patch) | |
tree | b58160911b4b5eb2c4ddeee85c4ba3ef301cb763 /Lib/test/seq_tests.py | |
parent | 52715f69e7d57e189109a6092f093c8ce9d70abc (diff) | |
download | cpython-be3856dcd41b444642a77c93e1f94367741692e7.zip cpython-be3856dcd41b444642a77c93e1f94367741692e7.tar.gz cpython-be3856dcd41b444642a77c93e1f94367741692e7.tar.bz2 |
patch [ 1141428 ] more __contains__ tests
Diffstat (limited to 'Lib/test/seq_tests.py')
-rw-r--r-- | Lib/test/seq_tests.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Lib/test/seq_tests.py b/Lib/test/seq_tests.py index 89996a3..ae5bba3 100644 --- a/Lib/test/seq_tests.py +++ b/Lib/test/seq_tests.py @@ -207,6 +207,33 @@ class CommonTest(unittest.TestCase): self.assertRaises(TypeError, u.__contains__) + def test_contains_fake(self): + class AllEq: + # Sequences must use rich comparison against each item + # (unless "is" is true, or an earlier item answered) + # So instances of AllEq must be found in all non-empty sequences. + def __eq__(self, other): + return True + def __hash__(self): + raise NotImplemented + self.assert_(AllEq() not in self.type2test([])) + self.assert_(AllEq() in self.type2test([1])) + + def test_contains_order(self): + # Sequences must test in-order. If a rich comparison has side + # effects, these will be visible to tests against later members. + # In this test, the "side effect" is a short-circuiting raise. + class DoNotTestEq(Exception): + pass + class StopCompares: + def __eq__(self, other): + raise DoNotTestEq + + checkfirst = self.type2test([1, StopCompares()]) + self.assert_(1 in checkfirst) + checklast = self.type2test([StopCompares(), 1]) + self.assertRaises(DoNotTestEq, checklast.__contains__, 1) + def test_len(self): self.assertEqual(len(self.type2test()), 0) self.assertEqual(len(self.type2test([])), 0) |