~ubuntu-branches/ubuntu/saucy/python-scipy/saucy

« back to all changes in this revision

Viewing changes to Lib/io/tests/test_array_import.py

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
## Automatically adapted for scipy Oct 19, 2005 by convertcode.py
2
 
 
3
 
#!/usr/bin/env python
4
 
 
5
 
# This python script tests the numpyio module.
6
 
# also check out numpyio.fread.__doc__ and other method docstrings.
7
 
 
8
 
import os
9
 
from numpy.testing import *
10
 
set_package_path()
11
 
import io
12
 
from io import numpyio
13
 
restore_path()
14
 
 
15
 
 
16
 
import numpy.oldnumeric as N
17
 
import tempfile
18
 
 
19
 
class test_numpyio(ScipyTestCase):
20
 
    def check_basic(self):
21
 
        # Generate some data
22
 
        a = 255*rand(20)
23
 
        # Open a file
24
 
        fname = tempfile.mktemp('.dat')
25
 
        fid = open(fname,"wb")
26
 
        # Write the data as shorts
27
 
        numpyio.fwrite(fid,20,a,N.Int16)
28
 
        fid.close()
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)
33
 
        fid.close()
34
 
        assert(N.product(a.astype(N.Int16) == b,axis=0))
35
 
        os.remove(fname)
36
 
 
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)
44
 
        os.remove(fname)
45
 
 
46
 
    def check_float(self):
47
 
        a = rand(3,4)*30
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)
52
 
        os.remove(fname)
53
 
 
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)
61
 
        os.remove(fname)
62
 
 
63
 
if __name__ == "__main__":
64
 
    ScipyTest().run()