diff -r 4617b7ac302a Lib/test/test_bisect.py --- a/Lib/test/test_bisect.py Tue Jan 08 11:27:18 2013 +0000 +++ b/Lib/test/test_bisect.py Tue Jan 08 15:40:27 2013 -0600 @@ -3,25 +3,8 @@ from test import support from collections import UserList -# We do a bit of trickery here to be able to test both the C implementation -# and the Python implementation of the module. - -# Make it impossible to import the C implementation anymore. -sys.modules['_bisect'] = 0 -# We must also handle the case that bisect was imported before. -if 'bisect' in sys.modules: - del sys.modules['bisect'] - -# Now we can import the module and get the pure Python implementation. -import bisect as py_bisect - -# Restore everything to normal. -del sys.modules['_bisect'] -del sys.modules['bisect'] - -# This is now the module with the C implementation. -import bisect as c_bisect - +py_bisect = support.import_fresh_module('bisect', blocked=['_bisect']) +c_bisect = support.import_fresh_module('bisect', fresh=['_bisect']) class Range(object): """A trivial range()-like object without any integer width limitations.""" @@ -45,9 +28,7 @@ self.last_insert = idx, item -class TestBisect(unittest.TestCase): - module = None - +class TestBisect: def setUp(self): self.precomputedCases = [ (self.module.bisect_right, [], 1, 0), @@ -218,17 +199,15 @@ self.module.insort(a=data, x=25, lo=1, hi=3) self.assertEqual(data, [10, 20, 25, 25, 25, 30, 40, 50]) -class TestBisectPython(TestBisect): +class TestBisectPython(TestBisect, unittest.TestCase): module = py_bisect -class TestBisectC(TestBisect): +class TestBisectC(TestBisect, unittest.TestCase): module = c_bisect #============================================================================== -class TestInsort(unittest.TestCase): - module = None - +class TestInsort: def test_vsBuiltinSort(self, n=500): from random import choice for insorted in (list(), UserList()): @@ -255,10 +234,10 @@ self.module.insort_right(lst, 5) self.assertEqual([5, 10], lst.data) -class TestInsortPython(TestInsort): +class TestInsortPython(TestInsort, unittest.TestCase): module = py_bisect -class TestInsortC(TestInsort): +class TestInsortC(TestInsort, unittest.TestCase): module = c_bisect #============================================================================== @@ -284,9 +263,7 @@ __eq__ = __lt__ __ne__ = __lt__ -class TestErrorHandling(unittest.TestCase): - module = None - +class TestErrorHandling: def test_non_sequence(self): for f in (self.module.bisect_left, self.module.bisect_right, self.module.insort_left, self.module.insort_right): @@ -313,10 +290,10 @@ self.module.insort_left, self.module.insort_right): self.assertRaises(TypeError, f, 10) -class TestErrorHandlingPython(TestErrorHandling): +class TestErrorHandlingPython(TestErrorHandling, unittest.TestCase): module = py_bisect -class TestErrorHandlingC(TestErrorHandling): +class TestErrorHandlingC(TestErrorHandling, unittest.TestCase): module = c_bisect #==============================================================================