summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bisect.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-09-27 22:48:40 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-09-27 22:48:40 (GMT)
commit63251781d12e9adca741fc9296171b8f480be20e (patch)
tree985692110260bff297cd74f6728657f68c3c32d9 /Lib/test/test_bisect.py
parentb6aa856f258d118b0605a60874f33c398dee780f (diff)
downloadcpython-63251781d12e9adca741fc9296171b8f480be20e.zip
cpython-63251781d12e9adca741fc9296171b8f480be20e.tar.gz
cpython-63251781d12e9adca741fc9296171b8f480be20e.tar.bz2
Beef-up tests for greater coverage and refcount checking.
Diffstat (limited to 'Lib/test/test_bisect.py')
-rw-r--r--Lib/test/test_bisect.py60
1 files changed, 59 insertions, 1 deletions
diff --git a/Lib/test/test_bisect.py b/Lib/test/test_bisect.py
index 6bb2112..0cda1d8 100644
--- a/Lib/test/test_bisect.py
+++ b/Lib/test/test_bisect.py
@@ -151,6 +151,47 @@ class TestInsort(unittest.TestCase):
#==============================================================================
+
+class LenOnly:
+ "Dummy sequence class defining __len__ but not __getitem__."
+ def __len__(self):
+ return 10
+
+class GetOnly:
+ "Dummy sequence class defining __getitem__ but not __len__."
+ def __getitem__(self, ndx):
+ return 10
+
+class CmpErr:
+ "Dummy element that always raises an error during comparison"
+ def __cmp__(self, other):
+ raise ZeroDivisionError
+
+class TestErrorHandling(unittest.TestCase):
+
+ def test_non_sequence(self):
+ for f in (bisect_left, bisect_right, insort_left, insort_right):
+ self.assertRaises(TypeError, f, 10, 10)
+
+ def test_len_only(self):
+ for f in (bisect_left, bisect_right, insort_left, insort_right):
+ self.assertRaises(AttributeError, f, LenOnly(), 10)
+
+ def test_get_only(self):
+ for f in (bisect_left, bisect_right, insort_left, insort_right):
+ self.assertRaises(AttributeError, f, GetOnly(), 10)
+
+ def test_get_only(self):
+ seq = [CmpErr(), CmpErr(), CmpErr()]
+ for f in (bisect_left, bisect_right, insort_left, insort_right):
+ self.assertRaises(ZeroDivisionError, f, seq, 10)
+
+ def test_arg_parsing(self):
+ for f in (bisect_left, bisect_right, insort_left, insort_right):
+ self.assertRaises(TypeError, f, 10)
+
+#==============================================================================
+
libreftest = """
Example from the Library Reference: Doc/lib/libbisect.tex
@@ -178,8 +219,25 @@ __test__ = {'libreftest' : libreftest}
def test_main(verbose=None):
from test import test_bisect
- test_support.run_unittest(TestBisect, TestInsort)
+ from types import BuiltinFunctionType
+ import sys
+
+ test_classes = [TestBisect, TestInsort]
+ if isinstance(bisect_left, BuiltinFunctionType):
+ test_classes.append(TestErrorHandling)
+
+ test_support.run_unittest(*test_classes)
test_support.run_doctest(test_bisect, verbose)
+ # verify reference counting
+ if verbose and hasattr(sys, "gettotalrefcount"):
+ import gc
+ counts = [None] * 5
+ for i in xrange(len(counts)):
+ test_support.run_unittest(*test_classes)
+ gc.collect()
+ counts[i] = sys.gettotalrefcount()
+ print counts
+
if __name__ == "__main__":
test_main(verbose=True)