Back to index

python3.2  3.2.2
Public Member Functions
test.test_contains.TestContains Class Reference

List of all members.

Public Member Functions

def test_common_tests
def test_builtin_sequence_types
def test_nonreflexive

Detailed Description

Definition at line 18 of file test_contains.py.


Member Function Documentation

Definition at line 39 of file test_contains.py.

00039 
00040     def test_builtin_sequence_types(self):
00041         # a collection of tests on builtin sequence types
00042         a = range(10)
00043         for i in a:
00044             self.assertIn(i, a)
00045         self.assertNotIn(16, a)
00046         self.assertNotIn(a, a)
00047 
00048         a = tuple(a)
00049         for i in a:
00050             self.assertIn(i, a)
00051         self.assertNotIn(16, a)
00052         self.assertNotIn(a, a)
00053 
00054         class Deviant1:
00055             """Behaves strangely when compared
00056 
00057             This class is designed to make sure that the contains code
00058             works when the list is modified during the check.
00059             """
00060             aList = list(range(15))
00061             def __eq__(self, other):
00062                 if other == 12:
00063                     self.aList.remove(12)
00064                     self.aList.remove(13)
00065                     self.aList.remove(14)
00066                 return 0
00067 
00068         self.assertNotIn(Deviant1(), Deviant1.aList)

Here is the call graph for this function:

Definition at line 19 of file test_contains.py.

00019 
00020     def test_common_tests(self):
00021         a = base_set(1)
00022         b = myset(1)
00023         c = seq(1)
00024         self.assertIn(1, b)
00025         self.assertNotIn(0, b)
00026         self.assertIn(1, c)
00027         self.assertNotIn(0, c)
00028         self.assertRaises(TypeError, lambda: 1 in a)
00029         self.assertRaises(TypeError, lambda: 1 not in a)
00030 
00031         # test char in string
00032         self.assertIn('c', 'abc')
00033         self.assertNotIn('d', 'abc')
00034 
00035         self.assertIn('', '')
00036         self.assertIn('', 'abc')
00037 
00038         self.assertRaises(TypeError, lambda: None in 'abc')

Here is the call graph for this function:

Definition at line 69 of file test_contains.py.

00069 
00070     def test_nonreflexive(self):
00071         # containment and equality tests involving elements that are
00072         # not necessarily equal to themselves
00073 
00074         class MyNonReflexive(object):
00075             def __eq__(self, other):
00076                 return False
00077             def __hash__(self):
00078                 return 28
00079 
00080         values = float('nan'), 1, None, 'abc', MyNonReflexive()
00081         constructors = list, tuple, dict.fromkeys, set, frozenset, deque
00082         for constructor in constructors:
00083             container = constructor(values)
00084             for elem in container:
00085                 self.assertIn(elem, container)
00086             self.assertTrue(container == constructor(values))
00087             self.assertTrue(container == container)
00088 

Here is the call graph for this function:


The documentation for this class was generated from the following file: