3
# This python script tests the numpyio module.
4
# also check out numpyio.fread.__doc__ and other method docstrings.
8
from unittest import TestCase
9
from scipy_test.testing import *
12
from io import numpyio
20
class test_numpyio(TestCase):
21
def check_basic(self):
25
fname = tempfile.mktemp('.dat')
26
fid = open(fname,"wb")
27
# Write the data as shorts
28
numpyio.fwrite(fid,20,a,Numeric.Int16)
30
# Reopen the file and read in data
31
fid = open(fname,"rb")
32
print "\nDon't worry about a warning regarding the number of bytes read."
33
b = numpyio.fread(fid,1000000,Numeric.Int16,Numeric.Int)
35
assert(N.product(a.astype(N.Int16) == b))
38
class test_read_array(TestCase):
39
def check_complex(self):
40
a = rand(13,4) + 1j*rand(13,4)
41
fname = tempfile.mktemp('.dat')
42
io.write_array(fname,a)
43
b = io.read_array(fname,atype=N.Complex)
44
assert_array_almost_equal(a,b,decimal=4)
47
def check_float(self):
49
fname = tempfile.mktemp('.dat')
50
io.write_array(fname,a)
51
b = io.read_array(fname)
52
assert_array_almost_equal(a,b,decimal=4)
55
def check_integer(self):
56
from scipy import stats
57
a = stats.randint.rvs(1,20,size=(3,4))
58
fname = tempfile.mktemp('.dat')
59
io.write_array(fname,a)
60
b = io.read_array(fname,atype=N.Int)
61
assert_array_equal(a,b)
64
if __name__ == "__main__":
65
ScipyTest('io.array_import').run()