1- import unittest
1+ import datetime , StringIO , unittest
22import matplotlib .mlab as mlab
33import numpy
4- import StringIO
54
65class TestMlab (unittest .TestCase ):
76 def test_csv2rec_closefile (self ):
@@ -21,11 +20,22 @@ def test_csv2rec_roundtrip(self):
2120 # lost precision when passing through repr(). csv2rec was
2221 # affected by this. This test will only pass on numpy >=
2322 # 1.0.5.
24- ra = numpy .rec .array ([(123 , 1197346475.0137341 , 'a,bc' ),
25- (456 , 123.456 , 'd\' ef' ),
26- (789 , 0.000000001 , 'ghi' ),
23+ delta = datetime .timedelta (days = 1 )
24+ date0 = datetime .date (2007 ,12 ,16 )
25+ date1 = date0 + delta
26+ date2 = date1 + delta
27+
28+ delta = datetime .timedelta (days = 1 )
29+ datetime0 = datetime .datetime (2007 ,12 ,16 ,22 ,29 ,34 ,924122 )
30+ datetime1 = datetime0 + delta
31+ datetime2 = datetime1 + delta
32+ ra = numpy .rec .fromrecords ([
33+ (123 , date0 , datetime0 , 1197346475.0137341 , 'a,bc' ),
34+ (456 , date1 , datetime1 , 123.456 , 'd\' ef' ),
35+ (789 , date2 , datetime2 , 0.000000001 , 'ghi' ),
2736 ],
28- dtype = [('a' , '<i8' ), ('b' , '<f8' ), ('c' , '|S3' )])
37+ names = 'intdata,datedata,datetimedata,floatdata,stringdata' )
38+
2939 fh = StringIO .StringIO ()
3040 mlab .rec2csv ( ra , fh )
3141 fh .seek (0 )
@@ -36,6 +46,8 @@ def test_csv2rec_roundtrip(self):
3646 fh .seek (0 )
3747 ra2 = mlab .csv2rec (fh )
3848 fh .close ()
49+ #print 'ra', ra
50+ #print 'ra2', ra2
3951 for name in ra .dtype .names :
4052 if 0 :
4153 print name , repr (ra [name ]), repr (ra2 [name ])
0 commit comments