Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(93153)

Side by Side Diff: Lib/test/support/script_helper.py

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/support/__init__.py ('k') | Lib/test/test_base64.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Common utility functions used by various script execution tests 1 # Common utility functions used by various script execution tests
2 # e.g. test_cmd_line, test_cmd_line_script and test_runpy 2 # e.g. test_cmd_line, test_cmd_line_script and test_runpy
3 3
4 import collections 4 import collections
5 import importlib 5 import importlib
6 import sys 6 import sys
7 import os 7 import os
8 import os.path 8 import os.path
9 import tempfile 9 import tempfile
10 import subprocess 10 import subprocess
11 import py_compile 11 import py_compile
12 import contextlib 12 import contextlib
13 import shutil 13 import shutil
14 import unittest
14 import zipfile 15 import zipfile
15 16
16 from importlib.util import source_from_cache 17 from importlib.util import source_from_cache
17 from test.support import make_legacy_pyc, strip_python_stderr 18 from test.support import make_legacy_pyc, strip_python_stderr
18 19
19 20
20 # Cached result of the expensive test performed in the function below. 21 # Cached result of the expensive test performed in the function below.
21 __cached_interp_requires_environment = None 22 __cached_interp_requires_environment = None
22 23
23 def interpreter_requires_environment(): 24 def interpreter_requires_environment():
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 try: 86 try:
86 out, err = p.communicate() 87 out, err = p.communicate()
87 finally: 88 finally:
88 subprocess._cleanup() 89 subprocess._cleanup()
89 p.stdout.close() 90 p.stdout.close()
90 p.stderr.close() 91 p.stderr.close()
91 rc = p.returncode 92 rc = p.returncode
92 err = strip_python_stderr(err) 93 err = strip_python_stderr(err)
93 return _PythonRunResult(rc, out, err), cmd_line 94 return _PythonRunResult(rc, out, err), cmd_line
94 95
96 @unittest.skipUnless(hasattr(subprocess, 'Popen'), "test requires subprocess.Pop en()")
95 def _assert_python(expected_success, *args, **env_vars): 97 def _assert_python(expected_success, *args, **env_vars):
96 res, cmd_line = run_python_until_end(*args, **env_vars) 98 res, cmd_line = run_python_until_end(*args, **env_vars)
97 if (res.rc and expected_success) or (not res.rc and not expected_success): 99 if (res.rc and expected_success) or (not res.rc and not expected_success):
98 # Limit to 80 lines to ASCII characters 100 # Limit to 80 lines to ASCII characters
99 maxlen = 80 * 100 101 maxlen = 80 * 100
100 out, err = res.out, res.err 102 out, err = res.out, res.err
101 if len(out) > maxlen: 103 if len(out) > maxlen:
102 out = b'(... truncated stdout ...)' + out[-maxlen:] 104 out = b'(... truncated stdout ...)' + out[-maxlen:]
103 if len(err) > maxlen: 105 if len(err) > maxlen:
104 err = b'(... truncated stderr ...)' + err[-maxlen:] 106 err = b'(... truncated stderr ...)' + err[-maxlen:]
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 def assert_python_failure(*args, **env_vars): 139 def assert_python_failure(*args, **env_vars):
138 """ 140 """
139 Assert that running the interpreter with `args` and optional environment 141 Assert that running the interpreter with `args` and optional environment
140 variables `env_vars` fails (rc != 0) and return a (return code, stdout, 142 variables `env_vars` fails (rc != 0) and return a (return code, stdout,
141 stderr) tuple. 143 stderr) tuple.
142 144
143 See assert_python_ok() for more options. 145 See assert_python_ok() for more options.
144 """ 146 """
145 return _assert_python(False, *args, **env_vars) 147 return _assert_python(False, *args, **env_vars)
146 148
149 @unittest.skipUnless(hasattr(subprocess, 'Popen'), "test requires subprocess.Pop en()")
147 def spawn_python(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw): 150 def spawn_python(*args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, **kw):
148 """Run a Python subprocess with the given arguments. 151 """Run a Python subprocess with the given arguments.
149 152
150 kw is extra keyword args to pass to subprocess.Popen. Returns a Popen 153 kw is extra keyword args to pass to subprocess.Popen. Returns a Popen
151 object. 154 object.
152 """ 155 """
153 cmd_line = [sys.executable, '-E'] 156 cmd_line = [sys.executable, '-E']
154 cmd_line.extend(args) 157 cmd_line.extend(args)
155 # Under Fedora (?), GNU readline can output junk on stderr when initialized, 158 # Under Fedora (?), GNU readline can output junk on stderr when initialized,
156 # depending on the TERM setting. Setting TERM=vt100 is supposed to disable 159 # depending on the TERM setting. Setting TERM=vt100 is supposed to disable
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 zip_file.write(script_name, script_name_in_zip) 238 zip_file.write(script_name, script_name_in_zip)
236 zip_file.close() 239 zip_file.close()
237 for name in unlink: 240 for name in unlink:
238 os.unlink(name) 241 os.unlink(name)
239 #if test.support.verbose: 242 #if test.support.verbose:
240 # zip_file = zipfile.ZipFile(zip_name, 'r') 243 # zip_file = zipfile.ZipFile(zip_name, 'r')
241 # print 'Contents of %r:' % zip_name 244 # print 'Contents of %r:' % zip_name
242 # zip_file.printdir() 245 # zip_file.printdir()
243 # zip_file.close() 246 # zip_file.close()
244 return zip_name, os.path.join(zip_name, script_name_in_zip) 247 return zip_name, os.path.join(zip_name, script_name_in_zip)
OLDNEW
« no previous file with comments | « Lib/test/support/__init__.py ('k') | Lib/test/test_base64.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+