Skip to content

Commit d1cc3b0

Browse files
committed
tests: add tests for rec2csv and csv2rec
svn path=/trunk/matplotlib/; revision=8020
1 parent 787755e commit d1cc3b0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/matplotlib/tests/test_mlab.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import numpy as np
22
import matplotlib.mlab as mlab
3+
import tempfile
4+
from nose.tools import raises
35

46
def test_colinear_pca():
57
a = mlab.PCA._get_colinear()
@@ -8,3 +10,25 @@ def test_colinear_pca():
810
assert(np.allclose(pca.fracs[2:], 0.))
911
assert(np.allclose(pca.Y[:,2:], 0.))
1012

13+
def test_recarray_csv_roundtrip():
14+
expected = np.recarray((99,),
15+
[('x',np.float),('y',np.float),('t',np.float)])
16+
expected['x'][0] = 1
17+
expected['y'][1] = 2
18+
expected['t'][2] = 3
19+
fd = tempfile.TemporaryFile(suffix='csv')
20+
mlab.rec2csv(expected,fd)
21+
fd.seek(0)
22+
actual = mlab.csv2rec(fd)
23+
fd.close()
24+
assert np.allclose( expected['x'], actual['x'] )
25+
assert np.allclose( expected['y'], actual['y'] )
26+
assert np.allclose( expected['t'], actual['t'] )
27+
28+
@raises(ValueError)
29+
def test_rec2csv_bad_shape():
30+
bad = np.recarray((99,4),[('x',np.float),('y',np.float)])
31+
fd = tempfile.TemporaryFile(suffix='csv')
32+
33+
# the bad recarray should trigger a ValueError for having ndim > 1.
34+
mlab.rec2csv(bad,fd)

0 commit comments

Comments
 (0)