Revision: 4747
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4747&view=rev
Author: astraw
Date: 2007-12-16 11:28:46 -0800 (Sun, 16 Dec 2007)
Log Message:
-----------
Add test for rec2csv and csv2rec roundtrip not losing precision.
Added Paths:
-----------
trunk/matplotlib/unit/mlab_unit.py
Added: trunk/matplotlib/unit/mlab_unit.py
===================================================================
--- trunk/matplotlib/unit/mlab_unit.py (rev 0)
+++ trunk/matplotlib/unit/mlab_unit.py 2007-12-16 19:28:46 UTC (rev 4747)
@@ -0,0 +1,38 @@
+import unittest
+import matplotlib.mlab as mlab
+import numpy
+import StringIO
+
+class TestMlab(unittest.TestCase):
+ def test_csv2rec_closefile(self):
+ # If passed a file-like object, rec2csv should not close it.
+ ra=numpy.rec.array([(123, 1197346475.0137341), (456, 123.456)],
+ dtype=[('a', '<i8'), ('b', '<f8')])
+ fh = StringIO.StringIO()
+ mlab.rec2csv( ra, fh )
+ self.failIf( fh.closed )
+
+ def test_csv2rec_roundtrip(self):
+ # Make sure double-precision floats pass through.
+
+ # A bug in numpy (fixed in r4602) meant that numpy scalars
+ # lost precision when passing through repr(). csv2rec was
+ # affected by this. This test will only pass on numpy >=
+ # 1.0.5.
+ ra=numpy.rec.array([(123, 1197346475.0137341), (456, 123.456)],
+ dtype=[('a', '<i8'), ('b', '<f8')])
+ rec2csv_closes_files = True
+ if rec2csv_closes_files:
+ fh = 'mlab_unit_tmp.csv'
+ else:
+ fh = StringIO.StringIO()
+ mlab.rec2csv( ra, fh )
+ if not rec2csv_closes_files:
+ fh.seek(0)
+ ra2 = mlab.csv2rec(fh)
+ for name in ra.dtype.names:
+ #print name, repr(ra[name]), repr(ra2[name])
+ self.failUnless( numpy.all(ra[name] == ra2[name]) ) # should not
fail with numpy 1.0.5
+
+if __name__=='__main__':
+ unittest.main()
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins