Skip to content

Commit 64f3eaf

Browse files
committed
MRG - updated from upstream nisext, adding install / test routine
1 parent 1278bf6 commit 64f3eaf

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

nisext/testers.py

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,16 @@
2323

2424
PY_LIB_SDIR = 'pylib'
2525

26-
def sys_print_info(mod_name, pkg_path):
27-
''' Run info print in own process in anonymous path
26+
def run_mod_cmd(mod_name, pkg_path, cmd):
27+
''' Run command in own process in anonymous path
28+
29+
Parameters
30+
----------
31+
mod_name : str
32+
Name of module to import - e.g. 'nibabel'
33+
pkg_path : str
34+
directory containing `mod_name` package. Typically that will be the
35+
directory containing the e.g. 'nibabel' directory.
2836
'''
2937
cwd = os.getcwd()
3038
tmpdir = tempfile.mkdtemp()
@@ -33,10 +41,10 @@ def sys_print_info(mod_name, pkg_path):
3341
my_call('python -c "import sys; sys.path.insert(1,\'%s\'); '
3442
'import %s;'
3543
'print %s.__file__;'
36-
'print %s.get_info()"' % (pkg_path,
37-
mod_name,
38-
mod_name,
39-
mod_name))
44+
'%s"' % (pkg_path,
45+
mod_name,
46+
mod_name,
47+
cmd))
4048
finally:
4149
os.chdir(cwd)
4250
shutil.rmtree(tmpdir)
@@ -131,8 +139,6 @@ def contexts_print_info(mod_name, repo_path, install_path):
131139
path into which to install temporary installations
132140
'''
133141
site_pkgs_path = os.path.join(install_path, PY_LIB_SDIR)
134-
py_lib_locs = ' --install-purelib=%s --install-platlib=%s' % (
135-
site_pkgs_path, site_pkgs_path)
136142
# first test archive
137143
pwd = os.path.abspath(os.getcwd())
138144
out_fname = pjoin(install_path, 'test.zip')
@@ -146,19 +152,20 @@ def contexts_print_info(mod_name, repo_path, install_path):
146152
site_pkgs_path = install_from_to(install_from,
147153
install_path,
148154
PY_LIB_SDIR)
149-
sys_print_info(mod_name, site_pkgs_path)
155+
cmd_str = 'print %s.get_info()' % mod_name
156+
run_mod_cmd(mod_name, site_pkgs_path, cmd_str)
150157
# now test install into a directory from the repository
151158
site_pkgs_path = install_from_to(repo_path,
152159
install_path,
153160
PY_LIB_SDIR)
154-
sys_print_info(mod_name, site_pkgs_path)
161+
run_mod_cmd(mod_name, site_pkgs_path, cmd_str)
155162
# Take the opportunity to audit the py files
156163
repo_mod_path = os.path.join(repo_path, mod_name)
157164
install_mod_path = os.path.join(site_pkgs_path, mod_name)
158165
print 'Files not taken across by the installation:'
159166
print check_installed_files(repo_mod_path, install_mod_path)
160167
# test from development tree
161-
sys_print_info(mod_name, repo_path)
168+
run_mod_cmd(mod_name, repo_path, cmd_str)
162169
return
163170

164171

@@ -181,3 +188,25 @@ def info_from_here(mod_name):
181188
shutil.rmtree(install_path)
182189

183190

191+
def tests_installed(mod_name, repo_path=None):
192+
""" Install from `repo_path` into temporary directory; run tests
193+
194+
Parameters
195+
----------
196+
mod_name : str
197+
name of module - e.g. 'nibabel'
198+
repo_path : None or str
199+
Path from which to install. If None, defaults to working directory
200+
"""
201+
if repo_path is None:
202+
repo_path = os.path.abspath(os.getcwd())
203+
install_path = tempfile.mkdtemp()
204+
try:
205+
site_pkgs_path = install_from_to(repo_path,
206+
install_path,
207+
PY_LIB_SDIR)
208+
run_mod_cmd(mod_name, site_pkgs_path, mod_name + '.test()')
209+
finally:
210+
shutil.rmtree(install_path)
211+
212+

0 commit comments

Comments
 (0)