1 from test_support
import TestFailed
, have_unicode
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")
39 check(0, "not in base_set did not raise error")
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")
69 # Test char in Unicode
71 check('c' in unicode('abc'), "'c' not in u'abc'")
72 check('d' not in unicode('abc'), "'d' in u'abc'")
76 check(0, "'' in u'abc' did not raise error")
81 'ab' in unicode('abc')
82 check(0, "'ab' in u'abc' did not raise error")
87 None in unicode('abc')
88 check(0, "None in u'abc' did not raise error")
92 # Test Unicode char in Unicode
94 check(unicode('c') in unicode('abc'), "u'c' not in u'abc'")
95 check(unicode('d') not in unicode('abc'), "u'd' in u'abc'")
98 unicode('') in unicode('abc')
99 check(0, "u'' in u'abc' did not raise error")
104 unicode('ab') in unicode('abc')
105 check(0, "u'ab' in u'abc' did not raise error")
109 # Test Unicode char in string
111 check(unicode('c') in 'abc', "u'c' not in 'abc'")
112 check(unicode('d') not in 'abc', "u'd' in 'abc'")
116 check(0, "u'' in 'abc' did not raise error")
121 unicode('ab') in 'abc'
122 check(0, "u'ab' in 'abc' did not raise error")
126 # A collection of tests on builtin sequence types
129 check(i
in a
, "%s not in %s" % (`i`
, `a`
))
130 check(16 not in a
, "16 not in %s" % `a`
)
131 check(a
not in a
, "%s not in %s" % (`a`
, `a`
))
135 check(i
in a
, "%s not in %s" % (`i`
, `a`
))
136 check(16 not in a
, "16 not in %s" % `a`
)
137 check(a
not in a
, "%s not in %s" % (`a`
, `a`
))
140 """Behaves strangely when compared
142 This class is designed to make sure that the contains code
143 works when the list is modified during the check.
148 def __cmp__(self
, other
):
150 self
.aList
.remove(12)
151 self
.aList
.remove(13)
152 self
.aList
.remove(14)
155 check(Deviant1() not in Deviant1
.aList
, "Deviant1 failed")
158 """Behaves strangely when compared
160 This class raises an exception during comparison. That in
161 turn causes the comparison to fail with a TypeError.
164 def __cmp__(self
, other
):
166 raise RuntimeError, "gotcha"
169 check(Deviant2() not in a
, "oops")