[pypy-svn] r76361 - in pypy/trunk/pypy/translator/goal: . test2
antocuni at codespeak.net
antocuni at codespeak.net
Tue Jul 27 14:05:57 CEST 2010
Author: antocuni
Date: Tue Jul 27 14:05:49 2010
New Revision: 76361
Modified:
pypy/trunk/pypy/translator/goal/app_main.py
pypy/trunk/pypy/translator/goal/test2/test_app_main.py
Log:
(Alex Morega, Andrei Laza, antocuni)
don't import a site.py that it's in the current directory
Modified: pypy/trunk/pypy/translator/goal/app_main.py
==============================================================================
--- pypy/trunk/pypy/translator/goal/app_main.py (original)
+++ pypy/trunk/pypy/translator/goal/app_main.py Tue Jul 27 14:05:49 2010
@@ -223,7 +223,6 @@
path = os.getenv('PYTHONPATH')
if path:
newpath = path.split(os.pathsep) + newpath
- newpath.insert(0, '')
# remove duplicates
_seen = {}
del sys.path[:]
@@ -327,6 +326,10 @@
except:
print >> sys.stderr, "'import site' failed"
+ # update sys.path *after* loading site.py, in case there is a
+ # "site.py" file in the script's directory.
+ sys.path.insert(0, '')
+
if warnoptions:
sys.warnoptions.append(warnoptions)
from warnings import _processoptions
Modified: pypy/trunk/pypy/translator/goal/test2/test_app_main.py
==============================================================================
--- pypy/trunk/pypy/translator/goal/test2/test_app_main.py (original)
+++ pypy/trunk/pypy/translator/goal/test2/test_app_main.py Tue Jul 27 14:05:49 2010
@@ -5,6 +5,7 @@
import sys, os, re
import autopath
from pypy.tool.udir import udir
+from contextlib import contextmanager
banner = sys.version.splitlines()[0]
@@ -326,8 +327,9 @@
class TestNonInteractive:
def run(self, cmdline, senddata='', expect_prompt=False,
- expect_banner=False):
- cmdline = '%s "%s" %s' % (sys.executable, app_main, cmdline)
+ expect_banner=False, python_flags=''):
+ cmdline = '%s %s "%s" %s' % (sys.executable, python_flags,
+ app_main, cmdline)
print 'POPEN:', cmdline
child_in, child_out_err = os.popen4(cmdline)
child_in.write(senddata)
@@ -449,6 +451,43 @@
assert data == '\x00(STDOUT)\n\x00' # from stdout
child_out_err.close()
+ def test_proper_sys_path(self, tmpdir):
+
+ @contextmanager
+ def chdir_and_unset_pythonpath(new_cwd):
+ old_cwd = new_cwd.chdir()
+ old_pythonpath = os.getenv('PYTHONPATH')
+ os.unsetenv('PYTHONPATH')
+ try:
+ yield
+ finally:
+ old_cwd.chdir()
+ os.putenv('PYTHONPATH', old_pythonpath)
+
+ tmpdir.join('site.py').write('print "SHOULD NOT RUN"')
+ runme_py = tmpdir.join('runme.py')
+ runme_py.write('print "some text"')
+
+ cmdline = str(runme_py)
+
+ with chdir_and_unset_pythonpath(tmpdir):
+ data = self.run(cmdline, python_flags='-S')
+
+ assert data == "some text\n"
+
+ runme2_py = tmpdir.mkdir('otherpath').join('runme2.py')
+ runme2_py.write('print "some new text"\n'
+ 'import sys\n'
+ 'print sys.path\n')
+
+ cmdline2 = str(runme2_py)
+
+ with chdir_and_unset_pythonpath(tmpdir):
+ data = self.run(cmdline2, python_flags='-S')
+
+ assert data.startswith("some new text\n")
+ assert repr(str(tmpdir.join('otherpath'))) in data
+
class AppTestAppMain:
More information about the Pypy-commit
mailing list