File: test_shape.py

package info (click to toggle)
netcdf4-python 1.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,604 kB
  • sloc: python: 6,057; ansic: 854; makefile: 15; sh: 2
file content (38 lines) | stat: -rw-r--r-- 1,126 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from netCDF4 import Dataset
import tempfile, unittest, os
import numpy as np

file_name = tempfile.NamedTemporaryFile(suffix='.nc', delete=False).name
xdim=None; ydim=121; zdim=169
datashape = (ydim,zdim)
data = np.ones(datashape,dtype=np.float64)

class ShapeTestCase(unittest.TestCase):

    def setUp(self):
        self.file = file_name
        f = Dataset(file_name,'w')
        f.createDimension('x',xdim)
        f.createDimension('y',ydim)
        f.createDimension('z',zdim)
        v = f.createVariable('data',np.float64,('x','y','z'))
        f.close()

    def tearDown(self):
        # Remove the temporary files
        os.remove(self.file)

    def runTest(self):
        """test for issue 90 (array shape should not be modified by
        assignment to netCDF variable)"""
        f  = Dataset(self.file, 'a')
        v = f.variables['data']
        v[0] = data
        # make sure shape of data array
        # is not changed by assigning it
        # to a netcdf var with one more dimension (issue 90)
        assert data.shape == datashape 
        f.close()

if __name__ == '__main__':
    unittest.main()