summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-07-20 00:14:29 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-07-20 00:14:29 (GMT)
commit3c2738488ab893017c26e529ee2ebedd41bbb263 (patch)
treea14bf9cf73241e7c883ef5a7fb953185cb91a6ca /Lib/importlib
parent0a49c58fb0534af4c7754d17d1a1e959fc196878 (diff)
downloadcpython-3c2738488ab893017c26e529ee2ebedd41bbb263.zip
cpython-3c2738488ab893017c26e529ee2ebedd41bbb263.tar.gz
cpython-3c2738488ab893017c26e529ee2ebedd41bbb263.tar.bz2
Some tests in importlib.test.source.test_abc_loader were testing what happens
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.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/test/source/test_abc_loader.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/Lib/importlib/test/source/test_abc_loader.py b/Lib/importlib/test/source/test_abc_loader.py
index 6c17d6a..6465d26 100644
--- a/Lib/importlib/test/source/test_abc_loader.py
+++ b/Lib/importlib/test/source/test_abc_loader.py
@@ -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)