Back to index

python3.2  3.2.2
Functions
test.script_helper Namespace Reference

Functions

def _assert_python
def assert_python_ok
def assert_python_failure
def spawn_python
def kill_python
def temp_dir
def make_script
def make_zip_script
def make_pkg
def make_zip_pkg

Function Documentation

def test.script_helper._assert_python (   expected_success,
  args,
  env_vars 
) [private]

Definition at line 19 of file script_helper.py.

00019 
00020 def _assert_python(expected_success, *args, **env_vars):
00021     cmd_line = [sys.executable]
00022     if not env_vars:
00023         cmd_line.append('-E')
00024     cmd_line.extend(args)
00025     # Need to preserve the original environment, for in-place testing of
00026     # shared library builds.
00027     env = os.environ.copy()
00028     env.update(env_vars)
00029     p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
00030                          stdout=subprocess.PIPE, stderr=subprocess.PIPE,
00031                          env=env)
00032     try:
00033         out, err = p.communicate()
00034     finally:
00035         subprocess._cleanup()
00036         p.stdout.close()
00037         p.stderr.close()
00038     rc = p.returncode
00039     err =  strip_python_stderr(err)
00040     if (rc and expected_success) or (not rc and not expected_success):
00041         raise AssertionError(
00042             "Process return code is %d, "
00043             "stderr follows:\n%s" % (rc, err.decode('ascii', 'ignore')))
00044     return rc, out, err

Here is the call graph for this function:

Here is the caller graph for this function:

def test.script_helper.assert_python_failure (   args,
  env_vars 
)
Assert that running the interpreter with `args` and optional environment
variables `env_vars` fails and return a (return code, stdout, stderr) tuple.

Definition at line 52 of file script_helper.py.

00052 
00053 def assert_python_failure(*args, **env_vars):
00054     """
00055     Assert that running the interpreter with `args` and optional environment
00056     variables `env_vars` fails and return a (return code, stdout, stderr) tuple.
00057     """
00058     return _assert_python(False, *args, **env_vars)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.script_helper.assert_python_ok (   args,
  env_vars 
)
Assert that running the interpreter with `args` and optional environment
variables `env_vars` is ok and return a (return code, stdout, stderr) tuple.

Definition at line 45 of file script_helper.py.

00045 
00046 def assert_python_ok(*args, **env_vars):
00047     """
00048     Assert that running the interpreter with `args` and optional environment
00049     variables `env_vars` is ok and return a (return code, stdout, stderr) tuple.
00050     """
00051     return _assert_python(True, *args, **env_vars)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 65 of file script_helper.py.

00065 
00066 def kill_python(p):
00067     p.stdin.close()
00068     data = p.stdout.read()
00069     p.stdout.close()
00070     # try to cleanup the child so we don't appear to leak when running
00071     # with regrtest -R.
00072     p.wait()
00073     subprocess._cleanup()
00074     return data
00075 
00076 # Script creation utilities
@contextlib.contextmanager

Here is the call graph for this function:

Here is the caller graph for this function:

def test.script_helper.make_pkg (   pkg_dir,
  init_source = '' 
)

Definition at line 115 of file script_helper.py.

00115 
00116 def make_pkg(pkg_dir, init_source=''):
00117     os.mkdir(pkg_dir)
00118     make_script(pkg_dir, '__init__', init_source)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.script_helper.make_script (   script_dir,
  script_basename,
  source 
)

Definition at line 85 of file script_helper.py.

00085 
00086 def make_script(script_dir, script_basename, source):
00087     script_filename = script_basename+os.extsep+'py'
00088     script_name = os.path.join(script_dir, script_filename)
00089     # The script should be encoded to UTF-8, the default string encoding
00090     script_file = open(script_name, 'w', encoding='utf-8')
00091     script_file.write(source)
00092     script_file.close()
00093     return script_name

Here is the caller graph for this function:

def test.script_helper.make_zip_pkg (   zip_dir,
  zip_basename,
  pkg_name,
  script_basename,
  source,
  depth = 1,
  compiled = False 
)

Definition at line 120 of file script_helper.py.

00120 
00121                  source, depth=1, compiled=False):
00122     unlink = []
00123     init_name = make_script(zip_dir, '__init__', '')
00124     unlink.append(init_name)
00125     init_basename = os.path.basename(init_name)
00126     script_name = make_script(zip_dir, script_basename, source)
00127     unlink.append(script_name)
00128     if compiled:
00129         init_name = py_compile(init_name, doraise=True)
00130         script_name = py_compile(script_name, doraise=True)
00131         unlink.extend((init_name, script_name))
00132     pkg_names = [os.sep.join([pkg_name]*i) for i in range(1, depth+1)]
00133     script_name_in_zip = os.path.join(pkg_names[-1], os.path.basename(script_name))
00134     zip_filename = zip_basename+os.extsep+'zip'
00135     zip_name = os.path.join(zip_dir, zip_filename)
00136     zip_file = zipfile.ZipFile(zip_name, 'w')
00137     for name in pkg_names:
00138         init_name_in_zip = os.path.join(name, init_basename)
00139         zip_file.write(init_name, init_name_in_zip)
00140     zip_file.write(script_name, script_name_in_zip)
00141     zip_file.close()
00142     for name in unlink:
00143         os.unlink(name)
00144     #if test.support.verbose:
00145     #    zip_file = zipfile.ZipFile(zip_name, 'r')
00146     #    print 'Contents of %r:' % zip_name
00147     #    zip_file.printdir()
00148     #    zip_file.close()
00149     return zip_name, os.path.join(zip_name, script_name_in_zip)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.script_helper.make_zip_script (   zip_dir,
  zip_basename,
  script_name,
  name_in_zip = None 
)

Definition at line 94 of file script_helper.py.

00094 
00095 def make_zip_script(zip_dir, zip_basename, script_name, name_in_zip=None):
00096     zip_filename = zip_basename+os.extsep+'zip'
00097     zip_name = os.path.join(zip_dir, zip_filename)
00098     zip_file = zipfile.ZipFile(zip_name, 'w')
00099     if name_in_zip is None:
00100         parts = script_name.split(os.sep)
00101         if len(parts) >= 2 and parts[-2] == '__pycache__':
00102             legacy_pyc = make_legacy_pyc(source_from_cache(script_name))
00103             name_in_zip = os.path.basename(legacy_pyc)
00104             script_name = legacy_pyc
00105         else:
00106             name_in_zip = os.path.basename(script_name)
00107     zip_file.write(script_name, name_in_zip)
00108     zip_file.close()
00109     #if test.support.verbose:
00110     #    zip_file = zipfile.ZipFile(zip_name, 'r')
00111     #    print 'Contents of %r:' % zip_name
00112     #    zip_file.printdir()
00113     #    zip_file.close()
00114     return zip_name, os.path.join(zip_name, name_in_zip)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 59 of file script_helper.py.

00059 
00060 def spawn_python(*args):
00061     cmd_line = [sys.executable, '-E']
00062     cmd_line.extend(args)
00063     return subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
00064                             stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

Here is the caller graph for this function:

Definition at line 77 of file script_helper.py.

00077 
00078 def temp_dir():
00079     dirname = tempfile.mkdtemp()
00080     dirname = os.path.realpath(dirname)
00081     try:
00082         yield dirname
00083     finally:
00084         shutil.rmtree(dirname)

Here is the call graph for this function:

Here is the caller graph for this function: