1 from test_support
import TestFailed
5 def __init__(self
, el
):
10 def __contains__(self
, el
):
15 def __getitem__(self
, n
):
20 raise TestFailed
, " ".join(map(str, args
))
26 check(1 in b
, "1 not in set(1)")
27 check(0 not in b
, "0 in set(1)")
28 check(1 in c
, "1 not in seq(1)")
29 check(0 not in c
, "0 in seq(1)")
33 check(0, "in base_set did not raise error")
34 except AttributeError:
39 check(0, "not in base_set did not raise error")
40 except AttributeError:
45 check('c' in 'abc', "'c' not in 'abc'")
46 check('d' not in 'abc', "'d' in 'abc'")
50 check(0, "'' in 'abc' did not raise error")
56 check(0, "'ab' in 'abc' did not raise error")
62 check(0, "None in 'abc' did not raise error")
66 # Test char in Unicode
68 check('c' in u
'abc', "'c' not in u'abc'")
69 check('d' not in u
'abc', "'d' in u'abc'")
73 check(0, "'' in u'abc' did not raise error")
79 check(0, "'ab' in u'abc' did not raise error")
85 check(0, "None in u'abc' did not raise error")
89 # Test Unicode char in Unicode
91 check(u
'c' in u
'abc', "u'c' not in u'abc'")
92 check(u
'd' not in u
'abc', "u'd' in u'abc'")
96 check(0, "u'' in u'abc' did not raise error")
102 check(0, "u'ab' in u'abc' did not raise error")
106 # Test Unicode char in string
108 check(u
'c' in 'abc', "u'c' not in 'abc'")
109 check(u
'd' not in 'abc', "u'd' in 'abc'")
113 check(0, "u'' in 'abc' did not raise error")
119 check(0, "u'ab' in 'abc' did not raise error")
123 # A collection of tests on builtin sequence types
126 check(i
in a
, "%s not in %s" % (`i`
, `a`
))
127 check(16 not in a
, "16 not in %s" % `a`
)
128 check(a
not in a
, "%s not in %s" % (`a`
, `a`
))
132 check(i
in a
, "%s not in %s" % (`i`
, `a`
))
133 check(16 not in a
, "16 not in %s" % `a`
)
134 check(a
not in a
, "%s not in %s" % (`a`
, `a`
))
137 """Behaves strangely when compared
139 This class is designed to make sure that the contains code
140 works when the list is modified during the check.
145 def __cmp__(self
, other
):
147 self
.aList
.remove(12)
148 self
.aList
.remove(13)
149 self
.aList
.remove(14)
152 check(Deviant1() not in Deviant1
.aList
, "Deviant1 failed")
155 """Behaves strangely when compared
157 This class raises an exception during comparison. That in
158 turn causes the comparison to fail with a TypeError.
161 def __cmp__(self
, other
):
163 raise RuntimeError, "gotcha"
166 check(Deviant2() not in a
, "oops")