[pypy-svn] pypy default: Fix one of the failures in test_sys, encode unicode correctly when printing SystemExit(errorcode)

alex_gaynor commits-noreply at bitbucket.org
Sun Mar 6 02:09:32 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r42435:73c2f8332dd9
Date: 2011-03-05 16:40 -0800
http://bitbucket.org/pypy/pypy/changeset/73c2f8332dd9/

Log:	Fix one of the failures in test_sys, encode unicode correctly when
	printing SystemExit(errorcode)

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
@@ -37,7 +37,7 @@
             except AttributeError:
                 pass   # too bad
             else:
-                print >> stderr, exitcode
+                stderr.write(exitcode)
             exitcode = 1
     raise SystemExit(exitcode)
 

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
@@ -534,7 +534,7 @@
 
 class TestNonInteractive:
 
-    def run(self, cmdline, senddata='', expect_prompt=False,
+    def run_with_status_code(self, cmdline, senddata='', expect_prompt=False,
             expect_banner=False, python_flags='', env=None):
         cmdline = '%s %s "%s" %s' % (sys.executable, python_flags,
                                      app_main, cmdline)
@@ -546,11 +546,14 @@
         )
         child_in, child_out_err = process.stdin, process.stdout
         child_in.write(senddata)
-        child_in.close()
         data = child_out_err.read()
-        child_out_err.close()
+        process.communicate()
         assert (banner in data) == expect_banner   # no banner unless expected
         assert ('>>> ' in data) == expect_prompt   # no prompt unless expected
+        return data, process.returncode
+
+    def run(self, *args, **kwargs):
+        data, status = self.run_with_status_code(*args, **kwargs)
         return data
 
     def test_script_on_stdin(self):
@@ -754,6 +757,19 @@
             data = self.run(p, env=env)
             assert data == expected
 
+    def test_sys_exit_pythonioencoding(self):
+        if sys.version_info < (2, 7):
+            skip("test required Python >= 2.7")
+        p = getscript_in_dir("""
+        import sys
+        sys.exit(u'15\u20ac')
+        """)
+        env = os.environ.copy()
+        env["PYTHONIOENCODING"] = "utf-8"
+        data, status = self.run_with_status_code(p, env=env)
+        assert status == 1
+        assert data.startswith("15\xe2\x82\xac")
+
 
 class AppTestAppMain:
 


More information about the Pypy-commit mailing list