summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-04-27 21:40:08 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-04-27 21:40:08 (GMT)
commit035a07e263edd2ebb24c07862d9de6488d8bb203 (patch)
tree9a9e12cac2e2cd4431b9d89e3ee9465e2fcb34ef /Lib
parent638ae9d0bbc1f1f4132e2f71f52a9db4ebe42779 (diff)
downloadcpython-035a07e263edd2ebb24c07862d9de6488d8bb203.zip
cpython-035a07e263edd2ebb24c07862d9de6488d8bb203.tar.gz
cpython-035a07e263edd2ebb24c07862d9de6488d8bb203.tar.bz2
add some more contains tests on the builtin types
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_contains.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/Lib/test/test_contains.py b/Lib/test/test_contains.py
index 31f3473..715fbbf 100644
--- a/Lib/test/test_contains.py
+++ b/Lib/test/test_contains.py
@@ -119,3 +119,50 @@ try:
check(0, "u'ab' in 'abc' did not raise error")
except TypeError:
pass
+
+# A collection of tests on builtin sequence types
+a = range(10)
+for i in a:
+ check(i in a, "%s not in %s" % (`i`, `a`))
+check(16 not in a, "16 not in %s" % `a`)
+check(a not in a, "%s not in %s" % (`a`, `a`))
+
+a = tuple(a)
+for i in a:
+ check(i in a, "%s not in %s" % (`i`, `a`))
+check(16 not in a, "16 not in %s" % `a`)
+check(a not in a, "%s not in %s" % (`a`, `a`))
+
+class Deviant1:
+ """Behaves strangely when compared
+
+ This class is designed to make sure that the contains code
+ works when the list is modified during the check.
+ """
+
+ aLongList = range(15)
+ aShortList = range(5)
+ aList = aLongList
+
+ def __cmp__(self, other):
+ if other == 12:
+ self.aList = self.aShortList
+ return 1
+
+check(Deviant1() not in Deviant1.aList, "Deviant1 failed")
+
+class Deviant2:
+ """Behaves strangely when compared
+
+ This class raises an exception during comparison. That in
+ turn causes the comparison to fail with a TypeError.
+ """
+
+ def __cmp__(self, other):
+ if other == 4:
+ raise RuntimeError, "gotcha"
+
+try:
+ check(Deviant2() not in a, "oops")
+except TypeError:
+ pass