Skip to content

Commit ddcfc7c

Browse files
committed
MRG - updated from nisext upstream; adding zip tests
1 parent 174a6ea commit ddcfc7c

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

nisext/testers.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import os
1515
from os.path import join as pjoin
16+
from glob import glob
1617
import shutil
1718
import tempfile
1819
import zipfile
@@ -188,25 +189,58 @@ def info_from_here(mod_name):
188189
shutil.rmtree(install_path)
189190

190191

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
193194
194195
Parameters
195196
----------
196197
mod_name : str
197198
name of module - e.g. 'nibabel'
198-
repo_path : None or str
199+
source_path : None or str
199200
Path from which to install. If None, defaults to working directory
200201
"""
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())
203204
install_path = tempfile.mkdtemp()
204205
try:
205-
site_pkgs_path = install_from_to(repo_path,
206+
site_pkgs_path = install_from_to(source_path,
206207
install_path,
207208
PY_LIB_SDIR)
208209
run_mod_cmd(mod_name, site_pkgs_path, mod_name + '.test()')
209210
finally:
210211
shutil.rmtree(install_path)
211212

212213

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

Comments
 (0)