Author: Antonio Cuni <[email protected]>
Branch: app_main-refactor
Changeset: r55580:4812b1717c0e
Date: 2012-06-11 15:33 +0200
http://bitbucket.org/pypy/pypy/changeset/4812b1717c0e/

Log:    there is no need to use the real
        sys.pypy_{find_{executable,stdlib},resolvedirof} when testing.
        Instead, we simply code some minimal implementation which works when
        we call python app_main.py, for tests. This greatly helps the py3k
        branch, where we cannot import the pypy package because it's not
        compatible with python3

diff --git a/pypy/translator/goal/app_main.py b/pypy/translator/goal/app_main.py
--- a/pypy/translator/goal/app_main.py
+++ b/pypy/translator/goal/app_main.py
@@ -681,35 +681,28 @@
 
 
 if __name__ == '__main__':
-    import autopath
-    # we need to import pypy.translator.platform early, before we start to
-    # mess up the env variables. In particular, during the import we spawn a
-    # couple of processes which gets confused if PYTHONINSPECT is set (e.g.,
-    # hg to get the version and the hack in tool.runsubprocess to prevent
-    # out-of-memory for late os.fork())
-    import pypy.translator.platform
     # obscure! try removing the following line, see how it crashes, and
     # guess why...
     ImStillAroundDontForgetMe = sys.modules['__main__']
 
     # debugging only
     def pypy_find_executable(s):
-        from pypy.module.sys.initpath import find_executable
-        return find_executable(s)
+        import os
+        return os.path.abspath(s)
 
     def pypy_find_stdlib(s):
-        from pypy.module.sys.initpath import find_stdlib
-        path, prefix = find_stdlib(None, s)
-        if path is None:
-            return None
-        # contrarily to the interp-level version, we don't set sys.prefix
-        # here, else CPythno stops to work (and e.g. test_proper_sys_path
-        # fails)
-        return path
+        from os.path import abspath, join, dirname as dn
+        thisfile = abspath(__file__)
+        root = dn(dn(dn(dn(thisfile))))
+        return [join(root, 'lib-python', '2.7'),
+                join(root, 'lib_pypy')]
+    
+    def pypy_resolvedirof(s):
+        # we ignore the issue of symlinks; for tests, the executable is always
+        # translator/goal/app_main.py anyway
+        import os
+        return os.path.abspath(os.path.join(s, '..'))
 
-    def pypy_resolvedirof(s):
-        from pypy.module.sys.initpath import resolvedirof
-        return resolvedirof(s)
 
     # add an emulator for these pypy-only or 2.7-only functions
     # (for test_pyc_commandline_argument)
diff --git a/pypy/translator/goal/test2/test_app_main.py 
b/pypy/translator/goal/test2/test_app_main.py
--- a/pypy/translator/goal/test2/test_app_main.py
+++ b/pypy/translator/goal/test2/test_app_main.py
@@ -200,6 +200,11 @@
     http://pexpect.sourceforge.net/
     """
 
+    def setup_class(cls):
+        # some tests need to be able to import test2, change the cwd
+        goal_dir = os.path.abspath(os.path.join(autopath.this_dir, '..'))
+        os.chdir(goal_dir)
+
     def _spawn(self, *args, **kwds):
         try:
             import pexpect
@@ -418,7 +423,7 @@
         p = os.path.join(autopath.this_dir, 'mymodule.py')
         p = os.path.abspath(p)
         child = self.spawn(['-i',
-                            '-m', 'pypy.translator.goal.test2.mymodule',
+                            '-m', 'test2.mymodule',
                             'extra'])
         child.expect('mymodule running')
         child.expect('Name: __main__')
@@ -429,9 +434,9 @@
         child.expect(re.escape(repr("foobar")))
         child.expect('>>> ')
         child.sendline('import sys')
-        child.sendline('"pypy.translator.goal.test2" in sys.modules')
+        child.sendline('"test2" in sys.modules')
         child.expect('True')
-        child.sendline('"pypy.translator.goal.test2.mymodule" in sys.modules')
+        child.sendline('"test2.mymodule" in sys.modules')
         child.expect('False')
         child.sendline('sys.path[0]')
         child.expect("''")
@@ -522,7 +527,7 @@
         child = self.spawn(['-cprint "hel" + "lo"'])
         child.expect('hello')
 
-        child = self.spawn(['-mpypy.translator.goal.test2.mymodule'])
+        child = self.spawn(['-mtest2.mymodule'])
         child.expect('mymodule running')
 
     def test_ps1_only_if_interactive(self):
@@ -626,7 +631,7 @@
             skip("requires CPython >= 2.6")
         p = os.path.join(autopath.this_dir, 'mymodule.py')
         p = os.path.abspath(p)
-        data = self.run('-m pypy.translator.goal.test2.mymodule extra')
+        data = self.run('-m test2.mymodule extra')
         assert 'mymodule running' in data
         assert 'Name: __main__' in data
         # ignoring case for windows. abspath behaves different from autopath
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to