[pypy-svn] r12438 - in pypy/dist/pypy: documentation interpreter/test module/sys2 module/test

hpk at codespeak.net hpk at codespeak.net
Wed May 18 15:28:57 CEST 2005


Author: hpk
Date: Wed May 18 15:28:56 2005
New Revision: 12438

Modified:
   pypy/dist/pypy/documentation/coding-guide.txt
   pypy/dist/pypy/interpreter/test/test_py.py
   pypy/dist/pypy/module/sys2/state.py
   pypy/dist/pypy/module/test/test_import.py
Log:
issue51 testing 

finalizing the module documentation for M0.5 and fixing
a wart for it:  we used to include the contents of 
intepreter level sys.path.  Now the implementation 
correctly uses PYTHONPATH contents to look up app-level 
modules.  The exact import order is now reflected  
in the documentation.  

Please read/cross-check the new "Modules in PyPy" chapter 
in the coding guide.  Putting this issue to testing 
to indicate this request.  Note that i introduced 
a public query "M0.5-testing" which you can use to 
see which issues are currently being tested and how
you can help. 



Modified: pypy/dist/pypy/documentation/coding-guide.txt
==============================================================================
--- pypy/dist/pypy/documentation/coding-guide.txt	(original)
+++ pypy/dist/pypy/documentation/coding-guide.txt	Wed May 18 15:28:56 2005
@@ -461,13 +461,15 @@
     mixed interpreter/app-level builtin modules, such as 
     the sys and builtin module. 
 
+*contents of PYTHONPATH* 
+    
+    lookup application level modules in each of the ``:`` separated 
+    list of directories, specified in the ``PYTHONPATH`` environment 
+    variable. 
+
 *pypy/lib/*
 
-    Used ONLY for complete pure Python reimplementation of modules.
-    The test2 subdirectory contains regular tests for these.
-    These tests run on top of CPython, i.e. at PyPy interpreter 
-    level and are meant to *quickly* check that the reimplementations 
-    are correct, independently of PyPy.
+    contains pure Python reimplementation of modules.
 
 *lib-python/modified-2.3.4/*
 

Modified: pypy/dist/pypy/interpreter/test/test_py.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_py.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_py.py	Wed May 18 15:28:56 2005
@@ -4,39 +4,39 @@
 import py
 import sys
 
-pypath = str(py.path.local(pypy.interpreter.py.__file__).new(basename='py.py'))
+pypypath = str(py.path.local(pypy.interpreter.py.__file__).new(basename='py.py'))
 
 def test_executable():
     """Ensures sys.executable points to the py.py script"""
-    # TODO : watch out for spaces/special chars in pypath
+    # TODO : watch out for spaces/special chars in pypypath
     output = py.process.cmdexec( '''"%s" "%s" -c "import sys;print sys.executable" ''' %
-                                 (sys.executable, pypath) )
-    assert output.splitlines()[-1] == pypath
+                                 (sys.executable, pypypath) )
+    assert output.splitlines()[-1] == pypypath
 
 def test_prefix():
     """Make sure py.py sys.prefix and exec_prefix are the same as C Python's"""
     output = py.process.cmdexec( '''"%s" "%s" -c "import sys;print sys.prefix" ''' %
-                                 (sys.executable, pypath) )
+                                 (sys.executable, pypypath) )
     assert output.splitlines()[-1] == sys.prefix
     output = py.process.cmdexec( '''"%s" "%s" -c "import sys;print sys.exec_prefix" ''' %
-                                 (sys.executable, pypath) )
+                                 (sys.executable, pypypath) )
     assert output.splitlines()[-1] == sys.exec_prefix
 
 def test_argv_command():
     """Some tests on argv"""
     # test 1 : no arguments
     output = py.process.cmdexec( '''"%s" "%s" -c "import sys;print sys.argv" ''' %
-                                 (sys.executable, pypath) )
+                                 (sys.executable, pypypath) )
     assert output.splitlines()[-1] == str(['-c'])
 
     # test 2 : some arguments after
     output = py.process.cmdexec( '''"%s" "%s" -c "import sys;print sys.argv" hello''' %
-                                 (sys.executable, pypath) )
+                                 (sys.executable, pypypath) )
     assert output.splitlines()[-1] == str(['-c','hello'])
     
     # test 3 : additionnal pypy parameters
     output = py.process.cmdexec( '''"%s" "%s" -O -c "import sys;print sys.argv" hello''' %
-                                 (sys.executable, pypath) )
+                                 (sys.executable, pypypath) )
     assert output.splitlines()[-1] == str(['-c','hello'])
 
 SCRIPT_1 = """
@@ -51,17 +51,17 @@
 
     # test 1 : no arguments
     output = py.process.cmdexec( '''"%s" "%s" "%s" ''' %
-                                 (sys.executable, pypath, tmpfilepath) )
+                                 (sys.executable, pypypath, tmpfilepath) )
     assert output.splitlines()[-1] == str([tmpfilepath])
     
     # test 2 : some arguments after
     output = py.process.cmdexec( '''"%s" "%s" "%s" hello''' %
-                                 (sys.executable, pypath, tmpfilepath) )
+                                 (sys.executable, pypypath, tmpfilepath) )
     assert output.splitlines()[-1] == str([tmpfilepath,'hello'])
     
     # test 3 : additionnal pypy parameters
     output = py.process.cmdexec( '''"%s" "%s" -O "%s" hello''' %
-                                 (sys.executable, pypath, tmpfilepath) )
+                                 (sys.executable, pypypath, tmpfilepath) )
     assert output.splitlines()[-1] == str([tmpfilepath,'hello'])
     
 
@@ -84,7 +84,7 @@
     e = None
     try:
         output = py.process.cmdexec( '''"%s" "%s" "%s" ''' %
-                                     (sys.executable, pypath, tmpfilepath) )
+                                     (sys.executable, pypypath, tmpfilepath) )
     except py.process.cmdexec.Error, e:
         pass
     assert e," expected failure"

Modified: pypy/dist/pypy/module/sys2/state.py
==============================================================================
--- pypy/dist/pypy/module/sys2/state.py	(original)
+++ pypy/dist/pypy/module/sys2/state.py	Wed May 18 15:28:56 2005
@@ -66,12 +66,12 @@
         pypy_lib = os.path.join(autopath.pypydir, 'lib') 
         assert os.path.exists(python_std_lib) 
         assert os.path.exists(python_std_lib_modified)
-        self.w_path = space.newlist([space.wrap(''), 
-                               space.wrap(pypy_lib), 
-                               space.wrap(python_std_lib_modified),
-                               space.wrap(python_std_lib), 
-                               ] +
-                               [space.wrap(p) for p in sys.path if p!= srcdir])
+        importlist = ['']
+        for p in os.environ.get('PYTHONPATH', '').split(':'): 
+            if p: 
+                importlist.append(p) 
+        importlist.extend([pypy_lib, python_std_lib_modified, python_std_lib])
+        self.w_path = space.newlist([space.wrap(x) for x in importlist])
 
 def get(space): 
     return space.fromcache(State)

Modified: pypy/dist/pypy/module/test/test_import.py
==============================================================================
--- pypy/dist/pypy/module/test/test_import.py	(original)
+++ pypy/dist/pypy/module/test/test_import.py	Wed May 18 15:28:56 2005
@@ -1,6 +1,7 @@
-import autopath
+import py
 from pypy.interpreter import gateway
-import os
+from pypy.tool.udir import udir 
+import sys, os
 
 def _setup(space): 
     dn=os.path.abspath(os.path.join(os.path.dirname(__file__), 'impsubdir'))
@@ -151,4 +152,17 @@
         def imp_b():
             import pkg.pkg2.b
         raises(ImportError,imp_b)
-        
+       
+def test_PYTHONPATH_takes_precedence(space): 
+    from pypy.interpreter.test.test_py import pypypath 
+    extrapath = udir.ensure("pythonpath", dir=1) 
+    extrapath.join("urllib.py").write("print 42\n")
+    old = os.environ.get('PYTHONPATH', None)
+    try: 
+        os.environ['PYTHONPATH'] = str(extrapath)
+        output = py.process.cmdexec('''"%s" "%s" -c "import urllib"''' % 
+                                 (sys.executable, pypypath) )
+        assert output.strip() == '42' 
+    finally: 
+        if old: 
+            os.environ['PYTHONPATH'] = old 



More information about the Pypy-commit mailing list