diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2009-04-11 14:30:59 +0000 |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2009-04-11 14:30:59 +0000 |
commit | fce769e73d05ec2e879a389320412f14ddb733ea (patch) | |
tree | ac3215914c4b036ece271ba4ede0189f68427924 /Lib/test/test_heapq.py | |
parent | 2d87e42921c3dbf0833ddc51d5690a4032c19b6d (diff) | |
download | cpython-git-fce769e73d05ec2e879a389320412f14ddb733ea.tar.gz |
Merged revisions 71465 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r71465 | nick.coghlan | 2009-04-11 23:31:31 +1000 (Sat, 11 Apr 2009) | 1 line
Issue 5354: Provide a standardised testing mechanism for doing fresh imports of modules, including the ability to block extension modules in order to test the pure Python fallbacks
........
Diffstat (limited to 'Lib/test/test_heapq.py')
-rw-r--r-- | Lib/test/test_heapq.py | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/Lib/test/test_heapq.py b/Lib/test/test_heapq.py index e1e7e9c8bd..bbb22bd1ea 100644 --- a/Lib/test/test_heapq.py +++ b/Lib/test/test_heapq.py @@ -7,23 +7,8 @@ import sys # 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['_heapq'] = 0 -# We must also handle the case that heapq was imported before. -if 'heapq' in sys.modules: - del sys.modules['heapq'] - -# Now we can import the module and get the pure Python implementation. -import heapq as py_heapq - -# Restore everything to normal. -del sys.modules['_heapq'] -del sys.modules['heapq'] - -# This is now the module with the C implementation. import heapq as c_heapq - +py_heapq = support.import_fresh_module('heapq', ['_heapq']) class TestHeap(unittest.TestCase): module = None @@ -194,6 +179,13 @@ class TestHeap(unittest.TestCase): class TestHeapPython(TestHeap): module = py_heapq + # As an early adopter, we sanity check the + # test.support.import_fresh_module utility function + def test_pure_python(self): + self.assertFalse(sys.modules['heapq'] is self.module) + self.assertTrue(hasattr(self.module.heapify, '__code__')) + + class TestHeapC(TestHeap): module = c_heapq @@ -219,6 +211,12 @@ class TestHeapC(TestHeap): self.assertEqual(hsort(data, LT), target) self.assertRaises(TypeError, data, LE) + # As an early adopter, we sanity check the + # test.support.import_fresh_module utility function + def test_accelerated(self): + self.assertTrue(sys.modules['heapq'] is self.module) + self.assertFalse(hasattr(self.module.heapify, '__code__')) + #============================================================================== |