[pypy-svn] r50175 - in pypy/dist/pypy: interpreter/test module/__builtin__
arigo at codespeak.net
arigo at codespeak.net
Sat Dec 29 18:34:08 CET 2007
Author: arigo
Date: Sat Dec 29 18:34:07 2007
New Revision: 50175
Modified:
pypy/dist/pypy/interpreter/test/test_compiler.py
pypy/dist/pypy/module/__builtin__/importing.py
Log:
issue315 testing
Test and fix: the import logic should not inherit the flags from the
caller while compile()ing the imported module.
Modified: pypy/dist/pypy/interpreter/test/test_compiler.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_compiler.py (original)
+++ pypy/dist/pypy/interpreter/test/test_compiler.py Sat Dec 29 18:34:07 2007
@@ -548,6 +548,40 @@
w_res = space.getitem(w_d, space.wrap('res'))
assert space.eq_w(w_res, space.wrap("var"))
+ def test_dont_inherit_flag(self):
+ space = self.space
+ s1 = str(py.code.Source("""
+ from __future__ import division
+ exec compile('x = 1/2', '?', 'exec', 0, 1)
+ """))
+ w_result = space.appexec([space.wrap(s1)], """(s1):
+ exec s1
+ return x
+ """)
+ assert space.float_w(w_result) == 0
+
+ def test_dont_inherit_across_import(self):
+ from pypy.tool.udir import udir
+ udir.join('test_dont_inherit_across_import.py').write('x = 1/2\n')
+ space = self.space
+ s1 = str(py.code.Source("""
+ from __future__ import division
+ from test_dont_inherit_across_import import x
+ """))
+ w_result = space.appexec([space.wrap(str(udir)), space.wrap(s1)],
+ """(udir, s1):
+ import sys
+ copy = sys.path[:]
+ sys.path.insert(0, udir)
+ try:
+ exec s1
+ finally:
+ sys.path[:] = copy
+ return x
+ """)
+ assert space.float_w(w_result) == 0
+
+
class TestECCompiler(BaseTestCompiler):
def setup_method(self, method):
self.compiler = self.space.getexecutioncontext().compiler
Modified: pypy/dist/pypy/module/__builtin__/importing.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/importing.py (original)
+++ pypy/dist/pypy/module/__builtin__/importing.py Sat Dec 29 18:34:07 2007
@@ -431,12 +431,8 @@
def parse_source_module(space, pathname, source):
""" Parse a source file and return the corresponding code object """
- w = space.wrap
- w_source = w(source)
- w_mode = w("exec")
- w_pathname = w(pathname)
- w_code = space.builtin.call('compile', w_source, w_pathname, w_mode)
- pycode = space.interp_w(Code, w_code)
+ ec = space.getexecutioncontext()
+ pycode = ec.compiler.compile(source, pathname, 'exec', 0)
return pycode
def load_source_module(space, w_modulename, w_mod, pathname, source,
More information about the Pypy-commit
mailing list