annotate Lib/test/script_helper.py @ 78069:a8aa77458e12 3.2

Add c_size_t and c_ssize_t to the ctypes summary table.
author Antoine Pitrou <solipsis@pitrou.net>
date Thu, 12 Jul 2012 20:31:50 +0200
parents 4a31f6b11e7a
children ed76dc34b39d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66138
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
1 # Common utility functions used by various script execution tests
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
2 # e.g. test_cmd_line, test_cmd_line_script and test_runpy
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
3
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
4 import sys
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
5 import os
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
6 import os.path
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
7 import tempfile
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
8 import subprocess
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
9 import py_compile
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
10 import contextlib
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
11 import shutil
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
12 import zipfile
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
13
60648
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
14 from imp import source_from_cache
66798
d57591bdf61e Have script_helper._assert_python strip refcount strings from stderr.
R. David Murray <rdmurray@bitdance.com>
parents: 66123
diff changeset
15 from test.support import make_legacy_pyc, strip_python_stderr
66138
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
16
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
17 # Executing the interpreter in a subprocess
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
18 def _assert_python(expected_success, *args, **env_vars):
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
19 cmd_line = [sys.executable]
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
20 if not env_vars:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
21 cmd_line.append('-E')
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
22 # Need to preserve the original environment, for in-place testing of
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
23 # shared library builds.
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
24 env = os.environ.copy()
75066
f4b7ecf8a5f8 Issue #13703: add a way to randomize the hash values of basic types (str, bytes, datetime)
Georg Brandl <georg@python.org>
parents: 67917
diff changeset
25 # But a special flag that can be set to override -- in this case, the
f4b7ecf8a5f8 Issue #13703: add a way to randomize the hash values of basic types (str, bytes, datetime)
Georg Brandl <georg@python.org>
parents: 67917
diff changeset
26 # caller is responsible to pass the full environment.
f4b7ecf8a5f8 Issue #13703: add a way to randomize the hash values of basic types (str, bytes, datetime)
Georg Brandl <georg@python.org>
parents: 67917
diff changeset
27 if env_vars.pop('__cleanenv', None):
f4b7ecf8a5f8 Issue #13703: add a way to randomize the hash values of basic types (str, bytes, datetime)
Georg Brandl <georg@python.org>
parents: 67917
diff changeset
28 env = {}
66138
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
29 env.update(env_vars)
75066
f4b7ecf8a5f8 Issue #13703: add a way to randomize the hash values of basic types (str, bytes, datetime)
Georg Brandl <georg@python.org>
parents: 67917
diff changeset
30 cmd_line.extend(args)
66138
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
31 p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
32 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
33 env=env)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
34 try:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
35 out, err = p.communicate()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
36 finally:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
37 subprocess._cleanup()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
38 p.stdout.close()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
39 p.stderr.close()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
40 rc = p.returncode
67917
8084c668b637 Merged revisions 87136,87221,87256,87337-87338,87571,87839,88164 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents: 66138
diff changeset
41 err = strip_python_stderr(err)
66138
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
42 if (rc and expected_success) or (not rc and not expected_success):
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
43 raise AssertionError(
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
44 "Process return code is %d, "
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
45 "stderr follows:\n%s" % (rc, err.decode('ascii', 'ignore')))
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
46 return rc, out, err
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
47
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
48 def assert_python_ok(*args, **env_vars):
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
49 """
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
50 Assert that running the interpreter with `args` and optional environment
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
51 variables `env_vars` is ok and return a (return code, stdout, stderr) tuple.
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
52 """
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
53 return _assert_python(True, *args, **env_vars)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
54
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
55 def assert_python_failure(*args, **env_vars):
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
56 """
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
57 Assert that running the interpreter with `args` and optional environment
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
58 variables `env_vars` fails and return a (return code, stdout, stderr) tuple.
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
59 """
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
60 return _assert_python(False, *args, **env_vars)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
61
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
62 def spawn_python(*args):
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
63 cmd_line = [sys.executable, '-E']
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
64 cmd_line.extend(args)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
65 return subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
66 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
67
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
68 def kill_python(p):
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
69 p.stdin.close()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
70 data = p.stdout.read()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
71 p.stdout.close()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
72 # try to cleanup the child so we don't appear to leak when running
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
73 # with regrtest -R.
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
74 p.wait()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
75 subprocess._cleanup()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
76 return data
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
77
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
78 # Script creation utilities
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
79 @contextlib.contextmanager
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
80 def temp_dir():
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
81 dirname = tempfile.mkdtemp()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
82 dirname = os.path.realpath(dirname)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
83 try:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
84 yield dirname
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
85 finally:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
86 shutil.rmtree(dirname)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
87
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
88 def make_script(script_dir, script_basename, source):
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
89 script_filename = script_basename+os.extsep+'py'
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
90 script_name = os.path.join(script_dir, script_filename)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
91 # The script should be encoded to UTF-8, the default string encoding
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
92 script_file = open(script_name, 'w', encoding='utf-8')
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
93 script_file.write(source)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
94 script_file.close()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
95 return script_name
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
96
57291
fd417cd64341 Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
97 def make_zip_script(zip_dir, zip_basename, script_name, name_in_zip=None):
fd417cd64341 Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
98 zip_filename = zip_basename+os.extsep+'zip'
fd417cd64341 Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
99 zip_name = os.path.join(zip_dir, zip_filename)
fd417cd64341 Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
100 zip_file = zipfile.ZipFile(zip_name, 'w')
fd417cd64341 Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
101 if name_in_zip is None:
60648
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
102 parts = script_name.split(os.sep)
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
103 if len(parts) >= 2 and parts[-2] == '__pycache__':
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
104 legacy_pyc = make_legacy_pyc(source_from_cache(script_name))
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
105 name_in_zip = os.path.basename(legacy_pyc)
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
106 script_name = legacy_pyc
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
107 else:
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
108 name_in_zip = os.path.basename(script_name)
57291
fd417cd64341 Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
109 zip_file.write(script_name, name_in_zip)
fd417cd64341 Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
110 zip_file.close()
63273
aa19a7cc1bf3 Syntax cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 60648
diff changeset
111 #if test.support.verbose:
57291
fd417cd64341 Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
112 # zip_file = zipfile.ZipFile(zip_name, 'r')
fd417cd64341 Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
113 # print 'Contents of %r:' % zip_name
fd417cd64341 Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
114 # zip_file.printdir()
fd417cd64341 Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
115 # zip_file.close()
fd417cd64341 Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
116 return zip_name, os.path.join(zip_name, name_in_zip)
fd417cd64341 Merged revisions 76286-76287,76289-76294,76296-76299,76301-76305,76307,76310-76311,76313-76322 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff changeset
117
66138
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
118 def make_pkg(pkg_dir, init_source=''):
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
119 os.mkdir(pkg_dir)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
120 make_script(pkg_dir, '__init__', init_source)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
121
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
122 def make_zip_pkg(zip_dir, zip_basename, pkg_name, script_basename,
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
123 source, depth=1, compiled=False):
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
124 unlink = []
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
125 init_name = make_script(zip_dir, '__init__', '')
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
126 unlink.append(init_name)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
127 init_basename = os.path.basename(init_name)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
128 script_name = make_script(zip_dir, script_basename, source)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
129 unlink.append(script_name)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
130 if compiled:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
131 init_name = py_compile(init_name, doraise=True)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
132 script_name = py_compile(script_name, doraise=True)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
133 unlink.extend((init_name, script_name))
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
134 pkg_names = [os.sep.join([pkg_name]*i) for i in range(1, depth+1)]
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
135 script_name_in_zip = os.path.join(pkg_names[-1], os.path.basename(script_name))
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
136 zip_filename = zip_basename+os.extsep+'zip'
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
137 zip_name = os.path.join(zip_dir, zip_filename)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
138 zip_file = zipfile.ZipFile(zip_name, 'w')
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
139 for name in pkg_names:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
140 init_name_in_zip = os.path.join(name, init_basename)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
141 zip_file.write(init_name, init_name_in_zip)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
142 zip_file.write(script_name, script_name_in_zip)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
143 zip_file.close()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
144 for name in unlink:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
145 os.unlink(name)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
146 #if test.support.verbose:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
147 # zip_file = zipfile.ZipFile(zip_name, 'r')
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
148 # print 'Contents of %r:' % zip_name
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
149 # zip_file.printdir()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
150 # zip_file.close()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
151 return zip_name, os.path.join(zip_name, script_name_in_zip)