Commit 3c273848 authored by Brett Cannon's avatar Brett Cannon

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.
parent 0a49c58f
...@@ -348,19 +348,27 @@ class BadBytecodeFailureTests(unittest.TestCase): ...@@ -348,19 +348,27 @@ class BadBytecodeFailureTests(unittest.TestCase):
# A bad magic number should lead to an ImportError. # A bad magic number should lead to an ImportError.
name = 'mod' name = 'mod'
bad_magic = b'\x00\x00\x00\x00' bad_magic = b'\x00\x00\x00\x00'
mock = PyPycLoaderMock({}, {name: {'path': os.path.join('path', 'to', bc = {name:
'mod'), {'path': os.path.join('path', 'to', 'mod'),
'magic': bad_magic}}) 'magic': bad_magic}}
mock = PyPycLoaderMock({name: None}, bc)
with util.uncache(name), self.assertRaises(ImportError): with util.uncache(name), self.assertRaises(ImportError):
mock.load_module(name) 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): 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' name = 'mod'
mock = PyPycLoaderMock({}, {name: {'path': os.path.join('path', 'to', bc = {name: {'path': os.path.join('path', 'to', 'mod'), 'bc': b'XXX'}}
'mod'), mock = PyPycLoaderMock({name: None}, bc)
'bc': b''}}) with util.uncache(name), self.assertRaises(ValueError):
with util.uncache(name), self.assertRaises(ImportError):
mock.load_module(name) mock.load_module(name)
......
...@@ -88,6 +88,10 @@ Build ...@@ -88,6 +88,10 @@ Build
Tests 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 - Removed importlib's custom test discovery code and switched to
unittest.TestLoader.discover(). unittest.TestLoader.discover().
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment