1 from test
.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'")
48 check('' in '', "'' not in ''")
49 check('' in 'abc', "'' not in 'abc'")
53 check(0, "None in 'abc' did not raise error")
60 # Test char in Unicode
62 check('c' in unicode('abc'), "'c' not in u'abc'")
63 check('d' not in unicode('abc'), "'d' in u'abc'")
65 check('' in unicode(''), "'' not in u''")
66 check(unicode('') in '', "u'' not in ''")
67 check(unicode('') in unicode(''), "u'' not in u''")
68 check('' in unicode('abc'), "'' not in u'abc'")
69 check(unicode('') in 'abc', "u'' not in 'abc'")
70 check(unicode('') in unicode('abc'), "u'' not in u'abc'")
73 None in unicode('abc')
74 check(0, "None in u'abc' did not raise error")
78 # Test Unicode char in Unicode
80 check(unicode('c') in unicode('abc'), "u'c' not in u'abc'")
81 check(unicode('d') not in unicode('abc'), "u'd' in u'abc'")
83 # Test Unicode char in string
85 check(unicode('c') in 'abc', "u'c' not in 'abc'")
86 check(unicode('d') not in 'abc', "u'd' in 'abc'")
88 # A collection of tests on builtin sequence types
91 check(i
in a
, "%s not in %s" % (`i`
, `a`
))
92 check(16 not in a
, "16 not in %s" % `a`
)
93 check(a
not in a
, "%s not in %s" % (`a`
, `a`
))
97 check(i
in a
, "%s not in %s" % (`i`
, `a`
))
98 check(16 not in a
, "16 not in %s" % `a`
)
99 check(a
not in a
, "%s not in %s" % (`a`
, `a`
))
102 """Behaves strangely when compared
104 This class is designed to make sure that the contains code
105 works when the list is modified during the check.
110 def __cmp__(self
, other
):
112 self
.aList
.remove(12)
113 self
.aList
.remove(13)
114 self
.aList
.remove(14)
117 check(Deviant1() not in Deviant1
.aList
, "Deviant1 failed")
120 """Behaves strangely when compared
122 This class raises an exception during comparison. That in
123 turn causes the comparison to fail with a TypeError.
126 def __cmp__(self
, other
):
128 raise RuntimeError, "gotcha"
131 check(Deviant2() not in a
, "oops")