From: Fernando Perez Date: Sat, 29 Dec 2012 19:43:59 +0000 (-0500) Subject: workshop_checklist.py: Add installation-testing script X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=868a36fb03276b3924697c9b35cf606a5b41368a;p=swc-workshop.git workshop_checklist.py: Add installation-testing script This script was linked to by Eric Bray [1] and hosted on Fernando Perez's website [2]. [1]: https://github.com/swcarpentry/website/issues/38#issuecomment-11386945 [2]: http://fperez.org/py4science/workshop_checklist.py --- 868a36fb03276b3924697c9b35cf606a5b41368a diff --git a/workshop_checklist.py b/workshop_checklist.py new file mode 100644 index 0000000..8792498 --- /dev/null +++ b/workshop_checklist.py @@ -0,0 +1,173 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +"""Minimal test script to check for modules needed in python workshop. + +Execute this code at the command line by typing: + +python workshop_checklist.py + +How to get a command line: + +- On OSX run this with the Terminal application. + +- On Windows, go to the Start menu, select 'Run' and type 'cmd' (without the +quotes) to run the cmd.exe Windows Command Prompt. + +Run the script and follow the instructions it prints at the end. +""" + +############################################################################## +# Config here + +# Modules whose imports we're going to validate +MODULES = ['IPython', + 'numpy', + 'scipy', + 'scipy.io', + 'matplotlib','pylab', + # 'sympy', 'Cython', 'networkx', 'mayavi.mlab', + # 'setuptools', + ] + +############################################################################## +# Code begins + +# Standard library imports +import glob +import os +import platform +import sys + +from StringIO import StringIO + +# Third-party imports +import nose +import nose.tools as nt + +#----------------------------------------------------------------------------- +# Generic utility functions +def sys_info(): + """Summarize some info about the system""" + + print '==================' + print 'System information' + print '==================' + print 'os.name :',os.name + try: + print 'os.uname :',os.uname() + except: + pass + print 'platform :',sys.platform + print 'platform+ :',platform.platform() + print 'prefix :',sys.prefix + print 'exec_prefix :',sys.exec_prefix + print 'executable :',sys.executable + print 'version_info :',sys.version_info + print 'version :',sys.version + print '==================' + + +#----------------------------------------------------------------------------- +# Tests + +def check_import(mname): + "Check that the given name imports correctly" + exec "import %s as m" % mname + + if mname == 'matplotlib': + m.use('Agg') + m.rcParams['figure.subplot.top']= 0.85 + + try: + vinfo = m.__version__ + except AttributeError: + vinfo = '*no info*' + + print 'MOD: %s, version: %s' % (mname,vinfo) + + +# Test generators are best written without docstrings, because nose can then +# show the parameters being used. +def test_imports(): + for mname in MODULES: + yield check_import, mname + + +# Test generator, don't put a docstring in it +def test_loadtxt(): + import numpy as np + import numpy.testing as npt + + # Examples taken from the loadtxt docstring + array = np.array + + c = StringIO("0 1\n2 3") + a1 = np.loadtxt(c) + a2 = np.array([[ 0., 1.], + [ 2., 3.]]) + yield npt.assert_array_equal,a1,a2 + + d = StringIO("M 21 72\nF 35 58") + a1 = np.loadtxt(d, dtype={'names': ('gender', 'age', 'weight'), + 'formats': ('S1', 'i4', 'f4')}) + + a2 = np.array([('M', 21, 72.0), ('F', 35, 58.0)], + dtype=[('gender', '|S1'), ('age', '