[pypy-commit] pypy py3.5: kill the one app_main test that requires it to be importable at interp-level and simplify code

rlamy pypy.commits at gmail.com
Sat Jan 26 22:47:05 EST 2019


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r95734:cc45a45ea346
Date: 2019-01-27 03:46 +0000
http://bitbucket.org/pypy/pypy/changeset/cc45a45ea346/

Log:	kill the one app_main test that requires it to be importable at
	interp-level and simplify code

diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -3,7 +3,6 @@
 # See test/test_app_main.
 
 # Missing vs CPython: -b, -d, -x
-from __future__ import print_function, unicode_literals
 USAGE1 = __doc__ = """\
 Options and arguments (and corresponding environment variables):
 -B     : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
@@ -334,7 +333,7 @@
             del encerr
 
 def create_stdio(fd, writing, name, encoding, errors, unbuffered):
-    import io
+    import _io
     # stdin is always opened in buffered mode, first because it
     # shouldn't make a difference in common use cases, second because
     # TextIOWrapper depends on the presence of a read1() method which
@@ -342,7 +341,7 @@
     buffering = 0 if unbuffered and writing else -1
     mode = 'w' if writing else 'r'
     try:
-        buf = io.open(fd, mode + 'b', buffering, closefd=False)
+        buf = _io.open(fd, mode + 'b', buffering, closefd=False)
     except OSError as e:
         if e.errno != errno.EBADF:
             raise
@@ -352,7 +351,7 @@
     raw.name = name
     # translate \r\n to \n for sys.stdin on Windows
     newline = None if sys.platform == 'win32' and not writing else '\n'
-    stream = io.TextIOWrapper(buf, encoding, errors, newline=newline,
+    stream = _io.TextIOWrapper(buf, encoding, errors, newline=newline,
                               line_buffering=unbuffered or raw.isatty())
     stream.mode = mode
     return stream
@@ -549,12 +548,6 @@
 
     return options
 
-# this indirection is needed to be able to import this module on python2, else
-# we have a SyntaxError: unqualified exec in a nested function
- at hidden_applevel
-def exec_(src, dic):
-    exec(src, dic)
-
 @hidden_applevel
 def run_command_line(interactive,
                      inspect,
@@ -663,7 +656,7 @@
             else:
                 if not isolated:
                     sys.path.insert(0, '')
-                success = run_toplevel(exec_, bytes, mainmodule.__dict__)
+                success = run_toplevel(exec, bytes, mainmodule.__dict__)
         elif run_module != 0:
             # handle the "-m" command
             # '' on sys.path is required also here
@@ -703,7 +696,7 @@
                                                         python_startup,
                                                         'exec',
                                                         PyCF_ACCEPT_NULL_BYTES)
-                            exec_(co_python_startup, mainmodule.__dict__)
+                            exec(co_python_startup, mainmodule.__dict__)
                         mainmodule.__file__ = python_startup
                         mainmodule.__cached__ = None
                         run_toplevel(run_it)
@@ -721,7 +714,7 @@
                 def run_it():
                     co_stdin = compile(sys.stdin.read(), '<stdin>', 'exec',
                                        PyCF_ACCEPT_NULL_BYTES)
-                    exec_(co_stdin, mainmodule.__dict__)
+                    exec(co_stdin, mainmodule.__dict__)
                 mainmodule.__file__ = '<stdin>'
                 mainmodule.__cached__ = None
                 success = run_toplevel(run_it)
@@ -763,7 +756,7 @@
                         co = marshal.load(f)
                     if type(co) is not type((lambda:0).__code__):
                         raise RuntimeError("Bad code object in .pyc file")
-                    exec_(co, namespace)
+                    exec(co, namespace)
                 args = (execfile, filename, mainmodule.__dict__)
             else:
                 filename = sys.argv[0]
@@ -791,7 +784,7 @@
                             code = f.read()
                         co = compile(code, filename, 'exec',
                                      PyCF_ACCEPT_NULL_BYTES)
-                        exec_(co, namespace)
+                        exec(co, namespace)
                     args = (execfile, filename, mainmodule.__dict__)
             success = run_toplevel(*args)
 
diff --git a/pypy/interpreter/test/test_app_main.py b/pypy/interpreter/test/test_app_main.py
--- a/pypy/interpreter/test/test_app_main.py
+++ b/pypy/interpreter/test/test_app_main.py
@@ -1043,36 +1043,6 @@
         assert data.startswith("15\\u20ac ('strict', 'backslashreplace')")
 
 
-class TestAppMain:
-    def test_print_info(self):
-        from pypy.interpreter import app_main
-        import sys, cStringIO
-        prev_so = sys.stdout
-        prev_ti = getattr(sys, 'pypy_translation_info', 'missing')
-        sys.pypy_translation_info = {
-            'translation.foo': True,
-            'translation.bar': 42,
-            'translation.egg.something': None,
-            'objspace.x': 'hello',
-        }
-        try:
-            sys.stdout = f = cStringIO.StringIO()
-            py.test.raises(SystemExit, app_main.print_info)
-        finally:
-            sys.stdout = prev_so
-            if prev_ti == 'missing':
-                del sys.pypy_translation_info
-            else:
-                sys.pypy_translation_info = prev_ti
-        assert f.getvalue() == ("[objspace]\n"
-                                "    x = 'hello'\n"
-                                "[translation]\n"
-                                "    bar = 42\n"
-                                "    [egg]\n"
-                                "        something = None\n"
-                                "    foo = True\n")
-
-
 @py.test.mark.skipif('config.getoption("runappdirect")')
 class AppTestAppMain:
     def setup_class(self):


More information about the pypy-commit mailing list