|
13 | 13 |
|
14 | 14 | import os
|
15 | 15 | from os.path import join as pjoin
|
| 16 | +from glob import glob |
16 | 17 | import shutil
|
17 | 18 | import tempfile
|
18 | 19 | import zipfile
|
@@ -188,25 +189,58 @@ def info_from_here(mod_name):
|
188 | 189 | shutil.rmtree(install_path)
|
189 | 190 |
|
190 | 191 |
|
191 |
| -def tests_installed(mod_name, repo_path=None): |
192 |
| - """ Install from `repo_path` into temporary directory; run tests |
| 192 | +def tests_installed(mod_name, source_path=None): |
| 193 | + """ Install from `source_path` into temporary directory; run tests |
193 | 194 |
|
194 | 195 | Parameters
|
195 | 196 | ----------
|
196 | 197 | mod_name : str
|
197 | 198 | name of module - e.g. 'nibabel'
|
198 |
| - repo_path : None or str |
| 199 | + source_path : None or str |
199 | 200 | Path from which to install. If None, defaults to working directory
|
200 | 201 | """
|
201 |
| - if repo_path is None: |
202 |
| - repo_path = os.path.abspath(os.getcwd()) |
| 202 | + if source_path is None: |
| 203 | + source_path = os.path.abspath(os.getcwd()) |
203 | 204 | install_path = tempfile.mkdtemp()
|
204 | 205 | try:
|
205 |
| - site_pkgs_path = install_from_to(repo_path, |
| 206 | + site_pkgs_path = install_from_to(source_path, |
206 | 207 | install_path,
|
207 | 208 | PY_LIB_SDIR)
|
208 | 209 | run_mod_cmd(mod_name, site_pkgs_path, mod_name + '.test()')
|
209 | 210 | finally:
|
210 | 211 | shutil.rmtree(install_path)
|
211 | 212 |
|
212 | 213 |
|
| 214 | +def tests_from_zip(mod_name, zip_fname): |
| 215 | + """ Runs test from sdist zip source archive """ |
| 216 | + install_path = tempfile.mkdtemp() |
| 217 | + try: |
| 218 | + zip_extract_all(zip_fname, install_path) |
| 219 | + pkg_dirs = glob(pjoin(install_path, mod_name + "*")) |
| 220 | + if len(pkg_dirs) != 1: |
| 221 | + raise OSError('There must be one and only one package dir') |
| 222 | + pkg_contents = pjoin(install_path, pkg_dirs[0]) |
| 223 | + tests_installed(mod_name, pkg_contents) |
| 224 | + finally: |
| 225 | + shutil.rmtree(install_path) |
| 226 | + |
| 227 | + |
| 228 | +def sdist_tests(mod_name, repo_path=None): |
| 229 | + """ Make sdist zip, install from it, and run tests """ |
| 230 | + pwd = os.path.abspath(os.getcwd()) |
| 231 | + if repo_path is None: |
| 232 | + repo_path = pwd |
| 233 | + install_path = tempfile.mkdtemp() |
| 234 | + try: |
| 235 | + os.chdir(repo_path) |
| 236 | + my_call('python setup.py sdist --formats=zip --dist-dir=' |
| 237 | + + install_path) |
| 238 | + zip_fnames = glob(pjoin(install_path, mod_name + "*.zip")) |
| 239 | + if len(zip_fnames) != 1: |
| 240 | + raise OSError('There must be one and only one zip file, ' |
| 241 | + 'but I found "%s"' % ': '.join(zip_fnames)) |
| 242 | + tests_from_zip(mod_name, zip_fnames[0]) |
| 243 | + finally: |
| 244 | + os.chdir(pwd) |
| 245 | + shutil.rmtree(install_path) |
| 246 | + |
0 commit comments