2 # -*- coding: utf-8 -*-
3 """Minimal test script to check for modules needed in python workshop.
5 Execute this code at the command line by typing:
7 python workshop_checklist.py
9 How to get a command line:
11 - On OSX run this with the Terminal application.
13 - On Windows, go to the Start menu, select 'Run' and type 'cmd' (without the
14 quotes) to run the cmd.exe Windows Command Prompt.
16 Run the script and follow the instructions it prints at the end.
19 ##############################################################################
22 # Modules whose imports we're going to validate
28 # 'sympy', 'Cython', 'networkx', 'mayavi.mlab',
32 ##############################################################################
35 # Standard library imports
41 from StringIO import StringIO
45 import nose.tools as nt
47 #-----------------------------------------------------------------------------
48 # Generic utility functions
50 """Summarize some info about the system"""
52 print '=================='
53 print 'System information'
54 print '=================='
55 print 'os.name :',os.name
57 print 'os.uname :',os.uname()
60 print 'platform :',sys.platform
61 print 'platform+ :',platform.platform()
62 print 'prefix :',sys.prefix
63 print 'exec_prefix :',sys.exec_prefix
64 print 'executable :',sys.executable
65 print 'version_info :',sys.version_info
66 print 'version :',sys.version
67 print '=================='
70 #-----------------------------------------------------------------------------
73 def check_import(mname):
74 "Check that the given name imports correctly"
75 exec "import %s as m" % mname
77 if mname == 'matplotlib':
79 m.rcParams['figure.subplot.top']= 0.85
83 except AttributeError:
86 print 'MOD: %s, version: %s' % (mname,vinfo)
89 # Test generators are best written without docstrings, because nose can then
90 # show the parameters being used.
93 yield check_import, mname
96 # Test generator, don't put a docstring in it
99 import numpy.testing as npt
101 # Examples taken from the loadtxt docstring
104 c = StringIO("0 1\n2 3")
106 a2 = np.array([[ 0., 1.],
108 yield npt.assert_array_equal,a1,a2
110 d = StringIO("M 21 72\nF 35 58")
111 a1 = np.loadtxt(d, dtype={'names': ('gender', 'age', 'weight'),
112 'formats': ('S1', 'i4', 'f4')})
114 a2 = np.array([('M', 21, 72.0), ('F', 35, 58.0)],
115 dtype=[('gender', '|S1'), ('age', '<i4'), ('weight', '<f4')])
116 yield npt.assert_array_equal,a1,a2
118 c = StringIO("1,0,2\n3,0,4")
119 x,y = np.loadtxt(c, delimiter=',', usecols=(0,2), unpack=True)
120 yield npt.assert_array_equal,x,np.array([ 1., 3.])
121 yield npt.assert_array_equal,y,np.array([ 2., 4.])
125 "Simple plot generation."
126 from matplotlib import pyplot as plt
129 plt.xlabel('some numbers')
130 plt.savefig('tmp_test_plot.png')
133 def test_plot_math():
135 from matplotlib import pyplot as plt
137 plt.plot([1,2,3],label='data')
138 t=(r'And X is $\sum_{i=0}^\infty \gamma_i + \frac{\alpha^{i^2}}{\gamma}'
139 r'+ \cos(2 \theta^2)$')
143 plt.savefig('tmp_test_plot_math.png')
147 """Remove temporary pngs made by our plotting tests"""
149 for f in glob.glob('tmp_test_plot*.png'):
153 print '*** Error: could not remove file',f
156 #-----------------------------------------------------------------------------
157 # Main routine, executed when this file is run as a script
159 if __name__ == '__main__':
160 print "Running tests:"
161 # This call form is ipython-friendly
162 nose.runmodule(argv=[__file__,'-vvs'],
165 ***************************************************************************
167 ***************************************************************************
169 If the printout above did not finish in 'OK' but instead says 'FAILED', copy
170 and send the *entire* output (all info above and summary below) to the