Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(20)

Unified Diff: Lib/test/test_modulefinder.py

Issue 20778: ModuleFinder.load_module skips incorrect number of bytes in pyc files
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Lib/modulefinder.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_modulefinder.py Tue Feb 25 16:46:41 2014 -0800
+++ b/Lib/test/test_modulefinder.py Wed Feb 26 10:41:32 2014 +0100
@@ -1,5 +1,7 @@
import os
import errno
+import imp
+import py_compile
import shutil
import unittest
import tempfile
@@ -208,6 +210,16 @@
from . import *
"""]
+load_pycompiled_module_test = [
+ "",
+ [],
+ [],
+ [],
+ """\
+a/__init__.py
+ foo = 1
+"""]
+
def open_file(path):
dirname = os.path.dirname(path)
@@ -288,6 +300,26 @@
def test_relative_imports_4(self):
self._do_test(relative_import_test_4)
+ def test_load_pycompiled_module(self):
+ # ModuleFinder.load_module will raise ValueError, if load_module
+ # shifts incorrect number of bytes before trying to marshal.load
+ # the bytecode itself
+ create_package(load_pycompiled_module_test[-1])
+ mf = modulefinder.ModuleFinder()
+ init_path = os.path.join(TEST_DIR, "a", "__init__.py")
+ init_compiled = py_compile.compile(init_path)
+
+ fp = open(init_compiled, "rb")
+ try:
+ # pass only the "important" values here
+ mf.load_module(None, fp, None, (None, None, imp.PY_COMPILED))
+ except ValueError as e:
+ self.fail('ModuleFinder.load_module failed with {0}: {1}.'.\
+ format(type(e).__name__, e))
+ finally:
+ fp.close()
+ shutil.rmtree(TEST_DIR)
+
def test_main():
support.run_unittest(ModuleFinderTest)
« no previous file with comments | « Lib/modulefinder.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+