annotate Lib/test/script_helper.py @ 79691:05c8928362ee

Merge __next__ method link fixes with 3.3.
author Ezio Melotti <ezio.melotti@gmail.com>
date Fri, 12 Oct 2012 13:46:37 +0300
parents 4182c0e6a389
children 4f0034477ba9 bc18b5d4920e
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
76577
4182c0e6a389 Invalidate finder caches after creating a new script.
Brett Cannon <brett@python.org>
parents: 75097
diff changeset
4 import importlib
66138
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
5 import sys
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
6 import os
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
7 import os.path
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
8 import tempfile
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
9 import subprocess
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
10 import py_compile
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
11 import contextlib
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
12 import shutil
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
13 import zipfile
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
14
60648
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
15 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
16 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
17
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
18 # 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
19 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
20 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
21 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
22 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
23 # 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
24 # shared library builds.
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
25 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
26 # 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
27 # 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
28 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
29 env = {}
66138
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
30 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
31 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
32 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
33 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
34 env=env)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
35 try:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
36 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
37 finally:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
38 subprocess._cleanup()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
39 p.stdout.close()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
40 p.stderr.close()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
41 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
42 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
43 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
44 raise AssertionError(
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
45 "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
46 "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
47 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
48
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
49 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
50 """
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
51 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
52 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
53 """
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
54 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
55
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
56 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
57 """
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
58 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
59 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
60 """
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
61 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
62
69070
b0680b5a5215 Issue #11393: Add the new faulthandler module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
63 def spawn_python(*args, **kw):
66138
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
64 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
65 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
66 return subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
69070
b0680b5a5215 Issue #11393: Add the new faulthandler module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
67 stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
b0680b5a5215 Issue #11393: Add the new faulthandler module
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68257
diff changeset
68 **kw)
66138
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
69
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
70 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
71 p.stdin.close()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
72 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
73 p.stdout.close()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
74 # 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
75 # with regrtest -R.
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
76 p.wait()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
77 subprocess._cleanup()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
78 return data
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
79
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
80 # Script creation utilities
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
81 @contextlib.contextmanager
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
82 def temp_dir():
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
83 dirname = tempfile.mkdtemp()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
84 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
85 try:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
86 yield dirname
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
87 finally:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
88 shutil.rmtree(dirname)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
89
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
90 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
91 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
92 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
93 # 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
94 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
95 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
96 script_file.close()
76577
4182c0e6a389 Invalidate finder caches after creating a new script.
Brett Cannon <brett@python.org>
parents: 75097
diff changeset
97 importlib.invalidate_caches()
66138
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
98 return script_name
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
99
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
100 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
101 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
102 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
103 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
104 if name_in_zip is None:
60648
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
105 parts = script_name.split(os.sep)
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
106 if len(parts) >= 2 and parts[-2] == '__pycache__':
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
107 legacy_pyc = make_legacy_pyc(source_from_cache(script_name))
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
108 name_in_zip = os.path.basename(legacy_pyc)
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
109 script_name = legacy_pyc
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
110 else:
7b69e630d237 PEP 3147
Barry Warsaw <barry@python.org>
parents: 59186
diff changeset
111 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
112 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
113 zip_file.close()
63273
aa19a7cc1bf3 Syntax cleanup.
Florent Xicluna <florent.xicluna@gmail.com>
parents: 60648
diff changeset
114 #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
115 # 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
116 # 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
117 # 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
118 # 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
119 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
120
66138
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
121 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
122 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
123 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
124
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
125 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
126 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
127 unlink = []
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
128 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
129 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
130 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
131 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
132 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
133 if compiled:
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 zip_file.close()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
147 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
148 os.unlink(name)
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
149 #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
150 # 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
151 # 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
152 # zip_file.printdir()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
153 # zip_file.close()
dea4f7641940 I'm only backporting the tests (which run fine), as well as
Antoine Pitrou <solipsis@pitrou.net>
parents:
diff changeset
154 return zip_name, os.path.join(zip_name, script_name_in_zip)