1
from collections import deque
2
from test.support import run_unittest
7
def __init__(self, el):
10
class myset(base_set):
11
def __contains__(self, el):
15
def __getitem__(self, n):
18
class TestContains(unittest.TestCase):
19
def test_common_tests(self):
24
self.assertNotIn(0, b)
26
self.assertNotIn(0, c)
27
self.assertRaises(TypeError, lambda: 1 in a)
28
self.assertRaises(TypeError, lambda: 1 not in a)
31
self.assertIn('c', 'abc')
32
self.assertNotIn('d', 'abc')
35
self.assertIn('', 'abc')
37
self.assertRaises(TypeError, lambda: None in 'abc')
39
def test_builtin_sequence_types(self):
40
# a collection of tests on builtin sequence types
44
self.assertNotIn(16, a)
45
self.assertNotIn(a, a)
50
self.assertNotIn(16, a)
51
self.assertNotIn(a, a)
54
"""Behaves strangely when compared
56
This class is designed to make sure that the contains code
57
works when the list is modified during the check.
59
aList = list(range(15))
60
def __eq__(self, other):
67
self.assertNotIn(Deviant1(), Deviant1.aList)
69
def test_nonreflexive(self):
70
# containment and equality tests involving elements that are
71
# not necessarily equal to themselves
73
class MyNonReflexive(object):
74
def __eq__(self, other):
79
values = float('nan'), 1, None, 'abc', MyNonReflexive()
80
constructors = list, tuple, dict.fromkeys, set, frozenset, deque
81
for constructor in constructors:
82
container = constructor(values)
83
for elem in container:
84
self.assertIn(elem, container)
85
self.assertTrue(container == constructor(values))
86
self.assertTrue(container == container)
90
run_unittest(TestContains)
92
if __name__ == '__main__':