1
## Automatically adapted for scipy Oct 19, 2005 by convertcode.py
5
# This python script tests the numpyio module.
6
# also check out numpyio.fread.__doc__ and other method docstrings.
9
from numpy.testing import *
12
from io import numpyio
16
import numpy.oldnumeric as N
19
class test_numpyio(ScipyTestCase):
20
def check_basic(self):
24
fname = tempfile.mktemp('.dat')
25
fid = open(fname,"wb")
26
# Write the data as shorts
27
numpyio.fwrite(fid,20,a,N.Int16)
29
# Reopen the file and read in data
30
fid = open(fname,"rb")
31
print "\nDon't worry about a warning regarding the number of bytes read."
32
b = numpyio.fread(fid,1000000,N.Int16,N.Int)
34
assert(N.product(a.astype(N.Int16) == b,axis=0))
37
class test_read_array(ScipyTestCase):
38
def check_complex(self):
39
a = rand(13,4) + 1j*rand(13,4)
40
fname = tempfile.mktemp('.dat')
41
io.write_array(fname,a)
42
b = io.read_array(fname,atype=N.Complex)
43
assert_array_almost_equal(a,b,decimal=4)
46
def check_float(self):
48
fname = tempfile.mktemp('.dat')
49
io.write_array(fname,a)
50
b = io.read_array(fname)
51
assert_array_almost_equal(a,b,decimal=4)
54
def check_integer(self):
55
from scipy import stats
56
a = stats.randint.rvs(1,20,size=(3,4))
57
fname = tempfile.mktemp('.dat')
58
io.write_array(fname,a)
59
b = io.read_array(fname,atype=a.dtype.char)
60
assert_array_equal(a,b)
63
if __name__ == "__main__":