]> granicus.if.org Git - python/commitdiff
Some tests in importlib.test.source.test_abc_loader were testing what happens
authorBrett Cannon <bcannon@gmail.com>
Mon, 20 Jul 2009 00:14:29 +0000 (00:14 +0000)
committerBrett Cannon <bcannon@gmail.com>
Mon, 20 Jul 2009 00:14:29 +0000 (00:14 +0000)
when a loader is given missing or bad code object bytecode. Unfortunately an
exception related to source paths was masking what the proper exception to test
should be. Making the test explicitly set the environment fixed the test.

The code being test was not affected.

Lib/importlib/test/source/test_abc_loader.py
Misc/NEWS

index 6c17d6ac0314b76513effeb86193ea14f47bb2d0..6465d261b7dec721f7bd37b4a085bc1c09e47c09 100644 (file)
@@ -348,19 +348,27 @@ class BadBytecodeFailureTests(unittest.TestCase):
         # A bad magic number should lead to an ImportError.
         name = 'mod'
         bad_magic = b'\x00\x00\x00\x00'
-        mock = PyPycLoaderMock({}, {name: {'path': os.path.join('path', 'to',
-                                                                'mod'),
-                                            'magic': bad_magic}})
+        bc = {name:
+                {'path': os.path.join('path', 'to', 'mod'),
+                 'magic': bad_magic}}
+        mock = PyPycLoaderMock({name: None}, bc)
         with util.uncache(name), self.assertRaises(ImportError):
             mock.load_module(name)
 
+    def test_no_bytecode(self):
+        # Missing code object bytecode should lead to an EOFError.
+        name = 'mod'
+        bc = {name: {'path': os.path.join('path', 'to', 'mod'), 'bc': b''}}
+        mock = PyPycLoaderMock({name: None}, bc)
+        with util.uncache(name), self.assertRaises(EOFError):
+            mock.load_module(name)
+
     def test_bad_bytecode(self):
-        # Bad code object bytecode should lead to an ImportError.
+        # Malformed code object bytecode should lead to a ValueError.
         name = 'mod'
-        mock = PyPycLoaderMock({}, {name: {'path': os.path.join('path', 'to',
-                                                                'mod'),
-                                            'bc': b''}})
-        with util.uncache(name), self.assertRaises(ImportError):
+        bc = {name: {'path': os.path.join('path', 'to', 'mod'), 'bc': b'XXX'}}
+        mock = PyPycLoaderMock({name: None}, bc)
+        with util.uncache(name), self.assertRaises(ValueError):
             mock.load_module(name)
 
 
index cbe56078412266885a288668f49a7ebc3482dea3..4b94ede04d46f9181591a7e8a3d0c396e60c8a7d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -88,6 +88,10 @@ Build
 Tests
 -----
 
+- Fixed tests in importlib.test.source.test_abc_loader that were masking
+  the proper exceptions that should be raised for missing or improper code
+  object bytecode.
+
 - Removed importlib's custom test discovery code and switched to
     unittest.TestLoader.discover().