import unittest, os, tempfile
import numpy as np
from numpy.random.mtrand import uniform 
from numpy.testing import assert_array_equal, assert_array_almost_equal
import netCDF4

# rudimentary test of diskless file capability.

# create an n1dim by n2dim by n3dim random array
n1dim = 10
n2dim = 73 
n3dim = 144
ranarr = 100.*uniform(size=(n1dim,n2dim,n3dim))
FILE_NAME = tempfile.mktemp(".nc")

class DisklessTestCase(unittest.TestCase):

    def setUp(self):
        self.file = FILE_NAME
        f = netCDF4.Dataset(self.file,'w',diskless=True)
        self.f = f
        # foo has a single unlimited dimension
        f.createDimension('n1', n1dim)
        f.createDimension('n2', n2dim)
        f.createDimension('n3', n3dim)
        foo = f.createVariable('data1', ranarr.dtype.str[1:], ('n1','n2','n3'))
        # write some data to it.
        foo[0:n1dim-1] = ranarr[:-1,:,:]
        foo[n1dim-1] = ranarr[-1,:,:]

    def tearDown(self):
        self.f.close()

    def runTest(self):
        """testing diskless file capability"""
        foo = self.f.variables['data1']
        # check shape.
        self.assert_(foo.shape == (n1dim,n2dim,n3dim))
        # check data.
        assert_array_almost_equal(foo[:], ranarr)
        # file does not actually exist on disk
        assert(os.path.isfile(self.file)==False)

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

@@ -914,16 +914,323 @@
 %5B-1,:,:%5D
+%0A        # bar has 2 unlimited dimensions%0A        f.createDimension('n4', None)%0A        f.createDimension('n5', n2dim)%0A        f.createDimension('n6', None)%0A        # write some data to it.%0A        bar = f.createVariable('data2', ranarr.dtype.str%5B1:%5D, ('n4','n5','n6'))%0A        bar%5B0:n1dim,:, 0:n3dim%5D = 2.0
 %0A%0A    de
@@ -1381,16 +1381,56 @@
 data1'%5D%0A
+        bar = self.f.variables%5B'data2'%5D%0A
         
@@ -1499,16 +1499,71 @@
 n3dim))%0A
+        self.assert_(bar.shape == (n1dim,n2dim,n3dim))%0A
         
@@ -1626,16 +1626,108 @@
 ranarr)%0A
+        assert_array_almost_equal(bar%5B:,:,:%5D, 2.*np.ones((n1dim,n2dim,n3dim),ranarr.dtype))%0A
         

test 2 unlim dims in a diskless file.