1 from test
.test_support
import have_unicode
, run_unittest
6 def __init__(self
, el
):
10 def __contains__(self
, el
):
14 def __getitem__(self
, n
):
18 class TestContains(unittest
.TestCase
):
19 def test_common_tests(self
):
24 self
.assert_(0 not in b
)
26 self
.assert_(0 not in c
)
27 self
.assertRaises(TypeError, lambda: 1 in a
)
28 self
.assertRaises(TypeError, lambda: 1 not in a
)
31 self
.assert_('c' in 'abc')
32 self
.assert_('d' not in 'abc')
34 self
.assert_('' in '')
35 self
.assert_('' in 'abc')
37 self
.assertRaises(TypeError, lambda: None in 'abc')
40 def test_char_in_unicode(self
):
41 self
.assert_('c' in unicode('abc'))
42 self
.assert_('d' not in unicode('abc'))
44 self
.assert_('' in unicode(''))
45 self
.assert_(unicode('') in '')
46 self
.assert_(unicode('') in unicode(''))
47 self
.assert_('' in unicode('abc'))
48 self
.assert_(unicode('') in 'abc')
49 self
.assert_(unicode('') in unicode('abc'))
51 self
.assertRaises(TypeError, lambda: None in unicode('abc'))
53 # test Unicode char in Unicode
54 self
.assert_(unicode('c') in unicode('abc'))
55 self
.assert_(unicode('d') not in unicode('abc'))
57 # test Unicode char in string
58 self
.assert_(unicode('c') in 'abc')
59 self
.assert_(unicode('d') not in 'abc')
61 def test_builtin_sequence_types(self
):
62 # a collection of tests on builtin sequence types
66 self
.assert_(16 not in a
)
67 self
.assert_(a
not in a
)
72 self
.assert_(16 not in a
)
73 self
.assert_(a
not in a
)
76 """Behaves strangely when compared
78 This class is designed to make sure that the contains code
79 works when the list is modified during the check.
82 def __cmp__(self
, other
):
89 self
.assert_(Deviant1() not in Deviant1
.aList
)
92 """Behaves strangely when compared
94 This class raises an exception during comparison. That in
95 turn causes the comparison to fail with a TypeError.
97 def __cmp__(self
, other
):
99 raise RuntimeError, "gotcha"
102 self
.assert_(Deviant2() not in a
)
108 run_unittest(TestContains
)
110 if __name__
== '__main__':