annotate Lib/test/test_bisect.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents e957b93571a8
children 8296b686c6de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
1 import sys
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
2 import unittest
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
3 from test import test_support
31353
ed20259a1ea5 SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents: 28917
diff changeset
4 from UserList import UserList
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
5
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
6 # We do a bit of trickery here to be able to test both the C implementation
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
7 # and the Python implementation of the module.
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
8
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
9 # Make it impossible to import the C implementation anymore.
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
10 sys.modules['_bisect'] = 0
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
11 # We must also handle the case that bisect was imported before.
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
12 if 'bisect' in sys.modules:
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
13 del sys.modules['bisect']
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
14
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
15 # Now we can import the module and get the pure Python implementation.
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
16 import bisect as py_bisect
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
17
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
18 # Restore everything to normal.
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
19 del sys.modules['_bisect']
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
20 del sys.modules['bisect']
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
21
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
22 # This is now the module with the C implementation.
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
23 import bisect as c_bisect
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
24
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
25
76994
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
26 class Range(object):
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
27 """A trivial xrange()-like object without any integer width limitations."""
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
28 def __init__(self, start, stop):
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
29 self.start = start
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
30 self.stop = stop
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
31 self.last_insert = None
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
32
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
33 def __len__(self):
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
34 return self.stop - self.start
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
35
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
36 def __getitem__(self, idx):
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
37 n = self.stop - self.start
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
38 if idx < 0:
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
39 idx += n
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
40 if idx >= n:
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
41 raise IndexError(idx)
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
42 return self.start + idx
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
43
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
44 def insert(self, idx, item):
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
45 self.last_insert = idx, item
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
46
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
47
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
48 class TestBisect(unittest.TestCase):
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
49 module = None
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
50
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
51 def setUp(self):
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
52 self.precomputedCases = [
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
53 (self.module.bisect_right, [], 1, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
54 (self.module.bisect_right, [1], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
55 (self.module.bisect_right, [1], 1, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
56 (self.module.bisect_right, [1], 2, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
57 (self.module.bisect_right, [1, 1], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
58 (self.module.bisect_right, [1, 1], 1, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
59 (self.module.bisect_right, [1, 1], 2, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
60 (self.module.bisect_right, [1, 1, 1], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
61 (self.module.bisect_right, [1, 1, 1], 1, 3),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
62 (self.module.bisect_right, [1, 1, 1], 2, 3),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
63 (self.module.bisect_right, [1, 1, 1, 1], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
64 (self.module.bisect_right, [1, 1, 1, 1], 1, 4),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
65 (self.module.bisect_right, [1, 1, 1, 1], 2, 4),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
66 (self.module.bisect_right, [1, 2], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
67 (self.module.bisect_right, [1, 2], 1, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
68 (self.module.bisect_right, [1, 2], 1.5, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
69 (self.module.bisect_right, [1, 2], 2, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
70 (self.module.bisect_right, [1, 2], 3, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
71 (self.module.bisect_right, [1, 1, 2, 2], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
72 (self.module.bisect_right, [1, 1, 2, 2], 1, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
73 (self.module.bisect_right, [1, 1, 2, 2], 1.5, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
74 (self.module.bisect_right, [1, 1, 2, 2], 2, 4),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
75 (self.module.bisect_right, [1, 1, 2, 2], 3, 4),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
76 (self.module.bisect_right, [1, 2, 3], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
77 (self.module.bisect_right, [1, 2, 3], 1, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
78 (self.module.bisect_right, [1, 2, 3], 1.5, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
79 (self.module.bisect_right, [1, 2, 3], 2, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
80 (self.module.bisect_right, [1, 2, 3], 2.5, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
81 (self.module.bisect_right, [1, 2, 3], 3, 3),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
82 (self.module.bisect_right, [1, 2, 3], 4, 3),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
83 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
84 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
85 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1.5, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
86 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2, 3),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
87 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2.5, 3),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
88 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3, 6),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
89 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3.5, 6),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
90 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 4, 10),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
91 (self.module.bisect_right, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 5, 10),
15673
67b3ac439f64 Fred, THIS NEEDS DOCS! The function docstrings tell the tale.
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
92
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
93 (self.module.bisect_left, [], 1, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
94 (self.module.bisect_left, [1], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
95 (self.module.bisect_left, [1], 1, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
96 (self.module.bisect_left, [1], 2, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
97 (self.module.bisect_left, [1, 1], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
98 (self.module.bisect_left, [1, 1], 1, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
99 (self.module.bisect_left, [1, 1], 2, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
100 (self.module.bisect_left, [1, 1, 1], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
101 (self.module.bisect_left, [1, 1, 1], 1, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
102 (self.module.bisect_left, [1, 1, 1], 2, 3),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
103 (self.module.bisect_left, [1, 1, 1, 1], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
104 (self.module.bisect_left, [1, 1, 1, 1], 1, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
105 (self.module.bisect_left, [1, 1, 1, 1], 2, 4),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
106 (self.module.bisect_left, [1, 2], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
107 (self.module.bisect_left, [1, 2], 1, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
108 (self.module.bisect_left, [1, 2], 1.5, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
109 (self.module.bisect_left, [1, 2], 2, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
110 (self.module.bisect_left, [1, 2], 3, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
111 (self.module.bisect_left, [1, 1, 2, 2], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
112 (self.module.bisect_left, [1, 1, 2, 2], 1, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
113 (self.module.bisect_left, [1, 1, 2, 2], 1.5, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
114 (self.module.bisect_left, [1, 1, 2, 2], 2, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
115 (self.module.bisect_left, [1, 1, 2, 2], 3, 4),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
116 (self.module.bisect_left, [1, 2, 3], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
117 (self.module.bisect_left, [1, 2, 3], 1, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
118 (self.module.bisect_left, [1, 2, 3], 1.5, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
119 (self.module.bisect_left, [1, 2, 3], 2, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
120 (self.module.bisect_left, [1, 2, 3], 2.5, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
121 (self.module.bisect_left, [1, 2, 3], 3, 2),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
122 (self.module.bisect_left, [1, 2, 3], 4, 3),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
123 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 0, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
124 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1, 0),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
125 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 1.5, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
126 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2, 1),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
127 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 2.5, 3),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
128 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3, 3),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
129 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 3.5, 6),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
130 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 4, 6),
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
131 (self.module.bisect_left, [1, 2, 2, 3, 3, 3, 4, 4, 4, 4], 5, 10)
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
132 ]
15673
67b3ac439f64 Fred, THIS NEEDS DOCS! The function docstrings tell the tale.
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
133
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
134 def test_precomputed(self):
27269
dbe4f57e8bb2 Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents: 27268
diff changeset
135 for func, data, elem, expected in self.precomputedCases:
dbe4f57e8bb2 Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents: 27268
diff changeset
136 self.assertEqual(func(data, elem), expected)
31353
ed20259a1ea5 SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents: 28917
diff changeset
137 self.assertEqual(func(UserList(data), elem), expected)
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
138
47919
8e7383cbe56e Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents: 45484
diff changeset
139 def test_negative_lo(self):
8e7383cbe56e Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents: 45484
diff changeset
140 # Issue 3301
8e7383cbe56e Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents: 45484
diff changeset
141 mod = self.module
8e7383cbe56e Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents: 45484
diff changeset
142 self.assertRaises(ValueError, mod.bisect_left, [1, 2, 3], 5, -1, 3),
8e7383cbe56e Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents: 45484
diff changeset
143 self.assertRaises(ValueError, mod.bisect_right, [1, 2, 3], 5, -1, 3),
8e7383cbe56e Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents: 45484
diff changeset
144 self.assertRaises(ValueError, mod.insort_left, [1, 2, 3], 5, -1, 3),
8e7383cbe56e Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents: 45484
diff changeset
145 self.assertRaises(ValueError, mod.insort_right, [1, 2, 3], 5, -1, 3),
8e7383cbe56e Issue 3301: Bisect functions behaved badly when lo was negative.
Raymond Hettinger <python@rcn.com>
parents: 45484
diff changeset
146
76325
709af2d0e862 Issue 13496: Fix bisect.bisect overflow bug for large collections.
Mark Dickinson <mdickinson@enthought.com>
parents: 55002
diff changeset
147 def test_large_range(self):
709af2d0e862 Issue 13496: Fix bisect.bisect overflow bug for large collections.
Mark Dickinson <mdickinson@enthought.com>
parents: 55002
diff changeset
148 # Issue 13496
709af2d0e862 Issue 13496: Fix bisect.bisect overflow bug for large collections.
Mark Dickinson <mdickinson@enthought.com>
parents: 55002
diff changeset
149 mod = self.module
76994
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
150 n = sys.maxsize
76993
6c164d788140 Skip test under 64-bit Windows
Antoine Pitrou <solipsis@pitrou.net>
parents: 76325
diff changeset
151 try:
76994
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
152 data = xrange(n-1)
76993
6c164d788140 Skip test under 64-bit Windows
Antoine Pitrou <solipsis@pitrou.net>
parents: 76325
diff changeset
153 except OverflowError:
6c164d788140 Skip test under 64-bit Windows
Antoine Pitrou <solipsis@pitrou.net>
parents: 76325
diff changeset
154 self.skipTest("can't create a xrange() object of size `sys.maxsize`")
76994
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
155 self.assertEqual(mod.bisect_left(data, n-3), n-3)
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
156 self.assertEqual(mod.bisect_right(data, n-3), n-2)
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
157 self.assertEqual(mod.bisect_left(data, n-3, n-10, n), n-3)
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
158 self.assertEqual(mod.bisect_right(data, n-3, n-10, n), n-2)
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
159
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
160 def test_large_pyrange(self):
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
161 # Same as above, but without C-imposed limits on range() parameters
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
162 mod = self.module
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
163 n = sys.maxsize
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
164 data = Range(0, n-1)
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
165 self.assertEqual(mod.bisect_left(data, n-3), n-3)
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
166 self.assertEqual(mod.bisect_right(data, n-3), n-2)
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
167 self.assertEqual(mod.bisect_left(data, n-3, n-10, n), n-3)
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
168 self.assertEqual(mod.bisect_right(data, n-3, n-10, n), n-2)
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
169 x = n - 100
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
170 mod.insort_left(data, x, x - 50, x + 50)
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
171 self.assertEqual(data.last_insert, (x, x))
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
172 x = n - 200
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
173 mod.insort_right(data, x, x - 50, x + 50)
e957b93571a8 Issue #14829: Fix bisect issues under 64-bit Windows.
Antoine Pitrou <solipsis@pitrou.net>
parents: 76993
diff changeset
174 self.assertEqual(data.last_insert, (x + 1, x))
76325
709af2d0e862 Issue 13496: Fix bisect.bisect overflow bug for large collections.
Mark Dickinson <mdickinson@enthought.com>
parents: 55002
diff changeset
175
27269
dbe4f57e8bb2 Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents: 27268
diff changeset
176 def test_random(self, n=25):
27267
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
177 from random import randrange
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
178 for i in xrange(n):
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
179 data = [randrange(0, n, 2) for j in xrange(i)]
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
180 data.sort()
27269
dbe4f57e8bb2 Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents: 27268
diff changeset
181 elem = randrange(-1, n+1)
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
182 ip = self.module.bisect_left(data, elem)
27267
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
183 if ip < len(data):
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 49677
diff changeset
184 self.assertTrue(elem <= data[ip])
27267
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
185 if ip > 0:
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 49677
diff changeset
186 self.assertTrue(data[ip-1] < elem)
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
187 ip = self.module.bisect_right(data, elem)
27267
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
188 if ip < len(data):
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 49677
diff changeset
189 self.assertTrue(elem < data[ip])
27267
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
190 if ip > 0:
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 49677
diff changeset
191 self.assertTrue(data[ip-1] <= elem)
27267
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
192
27268
be3d1b7e62dc Test optional slice arguments.
Raymond Hettinger <python@rcn.com>
parents: 27267
diff changeset
193 def test_optionalSlicing(self):
27269
dbe4f57e8bb2 Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents: 27268
diff changeset
194 for func, data, elem, expected in self.precomputedCases:
dbe4f57e8bb2 Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents: 27268
diff changeset
195 for lo in xrange(4):
dbe4f57e8bb2 Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents: 27268
diff changeset
196 lo = min(len(data), lo)
dbe4f57e8bb2 Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents: 27268
diff changeset
197 for hi in xrange(3,8):
dbe4f57e8bb2 Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents: 27268
diff changeset
198 hi = min(len(data), hi)
dbe4f57e8bb2 Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents: 27268
diff changeset
199 ip = func(data, elem, lo, hi)
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 49677
diff changeset
200 self.assertTrue(lo <= ip <= hi)
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
201 if func is self.module.bisect_left and ip < hi:
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 49677
diff changeset
202 self.assertTrue(elem <= data[ip])
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
203 if func is self.module.bisect_left and ip > lo:
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 49677
diff changeset
204 self.assertTrue(data[ip-1] < elem)
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
205 if func is self.module.bisect_right and ip < hi:
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 49677
diff changeset
206 self.assertTrue(elem < data[ip])
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
207 if func is self.module.bisect_right and ip > lo:
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 49677
diff changeset
208 self.assertTrue(data[ip-1] <= elem)
27269
dbe4f57e8bb2 Let test_random cover the endpoints.
Raymond Hettinger <python@rcn.com>
parents: 27268
diff changeset
209 self.assertEqual(ip, max(lo, min(hi, expected)))
27268
be3d1b7e62dc Test optional slice arguments.
Raymond Hettinger <python@rcn.com>
parents: 27267
diff changeset
210
be3d1b7e62dc Test optional slice arguments.
Raymond Hettinger <python@rcn.com>
parents: 27267
diff changeset
211 def test_backcompatibility(self):
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
212 self.assertEqual(self.module.bisect, self.module.bisect_right)
27268
be3d1b7e62dc Test optional slice arguments.
Raymond Hettinger <python@rcn.com>
parents: 27267
diff changeset
213
35699
3572249c1e77 SF #1313496: bisect C replacement doesn't accept named args
Raymond Hettinger <python@rcn.com>
parents: 33602
diff changeset
214 def test_keyword_args(self):
3572249c1e77 SF #1313496: bisect C replacement doesn't accept named args
Raymond Hettinger <python@rcn.com>
parents: 33602
diff changeset
215 data = [10, 20, 30, 40, 50]
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
216 self.assertEqual(self.module.bisect_left(a=data, x=25, lo=1, hi=3), 2)
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
217 self.assertEqual(self.module.bisect_right(a=data, x=25, lo=1, hi=3), 2)
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
218 self.assertEqual(self.module.bisect(a=data, x=25, lo=1, hi=3), 2)
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
219 self.module.insort_left(a=data, x=25, lo=1, hi=3)
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
220 self.module.insort_right(a=data, x=25, lo=1, hi=3)
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
221 self.module.insort(a=data, x=25, lo=1, hi=3)
35699
3572249c1e77 SF #1313496: bisect C replacement doesn't accept named args
Raymond Hettinger <python@rcn.com>
parents: 33602
diff changeset
222 self.assertEqual(data, [10, 20, 25, 25, 25, 30, 40, 50])
3572249c1e77 SF #1313496: bisect C replacement doesn't accept named args
Raymond Hettinger <python@rcn.com>
parents: 33602
diff changeset
223
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
224 class TestBisectPython(TestBisect):
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
225 module = py_bisect
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
226
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
227 class TestBisectC(TestBisect):
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
228 module = c_bisect
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
229
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
230 #==============================================================================
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
231
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
232 class TestInsort(unittest.TestCase):
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
233 module = None
15673
67b3ac439f64 Fred, THIS NEEDS DOCS! The function docstrings tell the tale.
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
234
31353
ed20259a1ea5 SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents: 28917
diff changeset
235 def test_vsBuiltinSort(self, n=500):
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
236 from random import choice
31353
ed20259a1ea5 SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents: 28917
diff changeset
237 for insorted in (list(), UserList()):
ed20259a1ea5 SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents: 28917
diff changeset
238 for i in xrange(n):
ed20259a1ea5 SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents: 28917
diff changeset
239 digit = choice("0123456789")
ed20259a1ea5 SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents: 28917
diff changeset
240 if digit in "02468":
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
241 f = self.module.insort_left
31353
ed20259a1ea5 SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents: 28917
diff changeset
242 else:
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
243 f = self.module.insort_right
31353
ed20259a1ea5 SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents: 28917
diff changeset
244 f(insorted, digit)
ed20259a1ea5 SF Patch #864863: Bisect C implementation
Raymond Hettinger <python@rcn.com>
parents: 28917
diff changeset
245 self.assertEqual(sorted(insorted), insorted)
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
246
27268
be3d1b7e62dc Test optional slice arguments.
Raymond Hettinger <python@rcn.com>
parents: 27267
diff changeset
247 def test_backcompatibility(self):
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
248 self.assertEqual(self.module.insort, self.module.insort_right)
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
249
49677
82ccc7e77ec5 Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47919
diff changeset
250 def test_listDerived(self):
82ccc7e77ec5 Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47919
diff changeset
251 class List(list):
82ccc7e77ec5 Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47919
diff changeset
252 data = []
82ccc7e77ec5 Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47919
diff changeset
253 def insert(self, index, item):
82ccc7e77ec5 Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47919
diff changeset
254 self.data.insert(index, item)
82ccc7e77ec5 Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47919
diff changeset
255
82ccc7e77ec5 Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47919
diff changeset
256 lst = List()
82ccc7e77ec5 Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47919
diff changeset
257 self.module.insort_left(lst, 10)
82ccc7e77ec5 Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47919
diff changeset
258 self.module.insort_right(lst, 5)
82ccc7e77ec5 Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47919
diff changeset
259 self.assertEqual([5, 10], lst.data)
82ccc7e77ec5 Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents: 47919
diff changeset
260
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
261 class TestInsortPython(TestInsort):
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
262 module = py_bisect
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
263
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
264 class TestInsortC(TestInsort):
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
265 module = c_bisect
27268
be3d1b7e62dc Test optional slice arguments.
Raymond Hettinger <python@rcn.com>
parents: 27267
diff changeset
266
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
267 #==============================================================================
15673
67b3ac439f64 Fred, THIS NEEDS DOCS! The function docstrings tell the tale.
Tim Peters <tim.peters@gmail.com>
parents:
diff changeset
268
33601
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
269
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
270 class LenOnly:
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
271 "Dummy sequence class defining __len__ but not __getitem__."
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
272 def __len__(self):
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
273 return 10
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
274
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
275 class GetOnly:
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
276 "Dummy sequence class defining __getitem__ but not __len__."
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
277 def __getitem__(self, ndx):
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
278 return 10
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
279
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
280 class CmpErr:
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
281 "Dummy element that always raises an error during comparison"
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
282 def __cmp__(self, other):
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
283 raise ZeroDivisionError
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
284
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
285 class TestErrorHandling(unittest.TestCase):
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
286 module = None
33601
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
287
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
288 def test_non_sequence(self):
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
289 for f in (self.module.bisect_left, self.module.bisect_right,
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
290 self.module.insort_left, self.module.insort_right):
33601
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
291 self.assertRaises(TypeError, f, 10, 10)
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
292
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
293 def test_len_only(self):
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
294 for f in (self.module.bisect_left, self.module.bisect_right,
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
295 self.module.insort_left, self.module.insort_right):
33601
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
296 self.assertRaises(AttributeError, f, LenOnly(), 10)
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
297
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
298 def test_get_only(self):
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
299 for f in (self.module.bisect_left, self.module.bisect_right,
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
300 self.module.insort_left, self.module.insort_right):
33601
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
301 self.assertRaises(AttributeError, f, GetOnly(), 10)
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
302
33602
7d6679ee39f9 Rename test for comparision errors.
Raymond Hettinger <python@rcn.com>
parents: 33601
diff changeset
303 def test_cmp_err(self):
33601
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
304 seq = [CmpErr(), CmpErr(), CmpErr()]
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
305 for f in (self.module.bisect_left, self.module.bisect_right,
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
306 self.module.insort_left, self.module.insort_right):
33601
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
307 self.assertRaises(ZeroDivisionError, f, seq, 10)
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
308
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
309 def test_arg_parsing(self):
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
310 for f in (self.module.bisect_left, self.module.bisect_right,
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
311 self.module.insort_left, self.module.insort_right):
33601
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
312 self.assertRaises(TypeError, f, 10)
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
313
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
314 class TestErrorHandlingPython(TestErrorHandling):
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
315 module = py_bisect
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
316
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
317 class TestErrorHandlingC(TestErrorHandling):
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
318 module = c_bisect
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
319
33601
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
320 #==============================================================================
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
321
27267
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
322 libreftest = """
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
323 Example from the Library Reference: Doc/library/bisect.rst
27267
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
324
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
325 The bisect() function is generally useful for categorizing numeric data.
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
326 This example uses bisect() to look up a letter grade for an exam total
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
327 (say) based on a set of ordered numeric breakpoints: 85 and up is an `A',
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
328 75..84 is a `B', etc.
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
329
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
330 >>> grades = "FEDCBA"
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
331 >>> breakpoints = [30, 44, 66, 75, 85]
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
332 >>> from bisect import bisect
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
333 >>> def grade(total):
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
334 ... return grades[bisect(breakpoints, total)]
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
335 ...
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
336 >>> grade(66)
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
337 'C'
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
338 >>> map(grade, [33, 99, 77, 44, 12, 88])
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
339 ['E', 'A', 'B', 'D', 'F', 'A']
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
340
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
341 """
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
342
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
343 #------------------------------------------------------------------------------
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
344
27267
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
345 __test__ = {'libreftest' : libreftest}
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
346
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
347 def test_main(verbose=None):
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
348 from test import test_bisect
33601
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
349
45484
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
350 test_classes = [TestBisectPython, TestBisectC,
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
351 TestInsortPython, TestInsortC,
8531f88b578e In test_heapq and test_bisect, test both the Python and the C implementation.
Georg Brandl <georg@python.org>
parents: 35699
diff changeset
352 TestErrorHandlingPython, TestErrorHandlingC]
33601
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
353
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
354 test_support.run_unittest(*test_classes)
27267
b744508d5b12 Added doctest for examples in the library reference.
Raymond Hettinger <python@rcn.com>
parents: 27266
diff changeset
355 test_support.run_doctest(test_bisect, verbose)
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
356
33601
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
357 # verify reference counting
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
358 if verbose and hasattr(sys, "gettotalrefcount"):
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
359 import gc
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
360 counts = [None] * 5
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
361 for i in xrange(len(counts)):
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
362 test_support.run_unittest(*test_classes)
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
363 gc.collect()
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
364 counts[i] = sys.gettotalrefcount()
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
365 print counts
7511585f2e6a Beef-up tests for greater coverage and refcount checking.
Raymond Hettinger <python@rcn.com>
parents: 31436
diff changeset
366
27266
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
367 if __name__ == "__main__":
a9ddadf789ea Convert to unittest format so that more tests can be added cleanly.
Raymond Hettinger <python@rcn.com>
parents: 24442
diff changeset
368 test_main(verbose=True)