~ubuntu-branches/ubuntu/natty/pytables/natty-updates

« back to all changes in this revision

Viewing changes to test/test_earray.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2006-06-28 10:45:03 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20060628104503-cc251q5o5j3e2k10
  * Fixed call to pyversions in debian/rules which failed on recent versions 
    of pyversions
  * Fixed clean rule in debian/rules which left the stamp files behind
  * Acknowledge NMU
  * Added Alexandre Fayolle to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Eh! python!, We are going to include isolatin characters here
2
 
# -*- coding: latin-1 -*-
3
 
 
4
 
import sys
5
 
import unittest
6
 
import os
7
 
import tempfile
8
 
 
9
 
from numarray import *
10
 
from numarray import strings
11
 
from tables import *
12
 
 
13
 
try:
14
 
    import Numeric
15
 
    numeric = 1
16
 
except:
17
 
    numeric = 0
18
 
 
19
 
from test_all import verbose, allequal
20
 
 
21
 
class BasicTestCase(unittest.TestCase):
22
 
    # Default values
23
 
    flavor = "numarray"
24
 
    type = Int32
25
 
    shape = (2,0)
26
 
    start = 0
27
 
    stop = 10
28
 
    step = 1
29
 
    length = 1
30
 
    chunksize = 5
31
 
    nappends = 10
32
 
    compress = 0
33
 
    complib = "zlib"  # Default compression library
34
 
    shuffle = 0
35
 
    fletcher32 = 0
36
 
    reopen = 1  # Tells whether the file has to be reopened on each test or not
37
 
 
38
 
    def setUp(self):
39
 
 
40
 
        # Create an instance of an HDF5 Table
41
 
        self.file = tempfile.mktemp(".h5")
42
 
        self.fileh = openFile(self.file, "w")
43
 
        self.rootgroup = self.fileh.root
44
 
        self.populateFile()
45
 
        if self.reopen:
46
 
            # Close the file
47
 
            self.fileh.close()
48
 
        
49
 
    def populateFile(self):
50
 
        group = self.rootgroup
51
 
        if self.flavor == "numarray":
52
 
            if str(self.type) == "CharType":
53
 
                flavor = "CharArray"
54
 
            else:
55
 
                flavor = "NumArray"
56
 
        else:
57
 
                flavor = "Numeric"
58
 
        if self.type == "CharType":
59
 
            atom = StringAtom(shape=self.shape, length=self.length,
60
 
                              flavor=flavor)
61
 
        else:
62
 
            atom = Atom(dtype=self.type, shape=self.shape, flavor=flavor)
63
 
        title = self.__class__.__name__
64
 
        filters = Filters(complevel = self.compress,
65
 
                          complib = self.complib,
66
 
                          shuffle = self.shuffle,
67
 
                          fletcher32 = self.fletcher32)
68
 
        earray = self.fileh.createEArray(group, 'earray1', atom, title,
69
 
                                         filters = filters,
70
 
                                         expectedrows = 1)
71
 
 
72
 
        # Fill it with rows
73
 
        self.rowshape = list(earray.shape)
74
 
        self.objsize = self.length
75
 
        for i in self.rowshape:
76
 
            if i <> 0:
77
 
                self.objsize *= i
78
 
        self.extdim = earray.extdim
79
 
        self.objsize *= self.chunksize
80
 
        self.rowshape[earray.extdim] = self.chunksize
81
 
        if self.flavor == "numarray":
82
 
            if str(self.type) == "CharType":
83
 
                object = strings.array("a"*self.objsize, shape=self.rowshape,
84
 
                                       itemsize=earray.itemsize)
85
 
            else:
86
 
                object = arange(self.objsize, shape=self.rowshape,
87
 
                                type=earray.type)
88
 
        else:  # Numeric flavor
89
 
            object = Numeric.arange(self.objsize,
90
 
                                    typecode=typecode[earray.type])
91
 
            object = Numeric.reshape(object, self.rowshape)
92
 
        if verbose:
93
 
            if self.flavor == "numarray":
94
 
                print "Object to append -->", object.info()
95
 
            else:
96
 
                print "Object to append -->", repr(object)
97
 
        for i in range(self.nappends):
98
 
            if str(self.type) == "CharType":
99
 
                earray.append(object)
100
 
            elif self.flavor == "numarray":
101
 
                earray.append(object*i)
102
 
            else:
103
 
                object = object * i
104
 
                # For Numeric arrays, we still have to undo the type upgrade
105
 
                earray.append(object.astype(typecode[earray.type]))
106
 
 
107
 
    def tearDown(self):
108
 
        self.fileh.close()
109
 
        os.remove(self.file)
110
 
        
111
 
    #----------------------------------------
112
 
 
113
 
    def test01_iterEArray(self):
114
 
        """Checking enlargeable array iterator"""
115
 
 
116
 
        rootgroup = self.rootgroup
117
 
        if verbose:
118
 
            print '\n', '-=' * 30
119
 
            print "Running %s.test01_iterEArray..." % self.__class__.__name__
120
 
 
121
 
        # Create an instance of an HDF5 Table
122
 
        if self.reopen:
123
 
            self.fileh = openFile(self.file, "r")
124
 
        earray = self.fileh.getNode("/earray1")
125
 
 
126
 
        # Choose a small value for buffer size
127
 
        earray._v_maxTuples = 3
128
 
        if verbose:
129
 
            print "EArray descr:", repr(earray)
130
 
            print "shape of read array ==>", earray.shape
131
 
            print "reopening?:", self.reopen
132
 
            
133
 
        # Build the array to do comparisons
134
 
        if self.flavor == "numarray":
135
 
            if str(self.type) == "CharType":
136
 
                object_ = strings.array("a"*self.objsize, shape=self.rowshape,
137
 
                                        itemsize=earray.itemsize)
138
 
            else:
139
 
                object_ = arange(self.objsize, shape=self.rowshape,
140
 
                                 type=earray.type)
141
 
            object_.swapaxes(earray.extdim, 0)
142
 
        else:
143
 
            object_ = Numeric.arange(self.objsize,
144
 
                                     typecode=typecode[earray.type])
145
 
            object_ = Numeric.reshape(object_, self.rowshape)
146
 
            object_ = Numeric.swapaxes(object_, earray.extdim, 0)
147
 
            
148
 
        # Read all the array
149
 
        for row in earray:
150
 
            chunk = int(earray.nrow % self.chunksize)
151
 
            if chunk == 0:
152
 
                if str(self.type) == "CharType":
153
 
                    object__ = object_
154
 
                else:
155
 
                    object__ = object_ * (earray.nrow / self.chunksize)
156
 
                    if self.flavor == "Numeric":
157
 
                        object__ = object__.astype(typecode[earray.type])
158
 
            object = object__[chunk]
159
 
            # The next adds much more verbosity
160
 
            if verbose and 0:
161
 
                print "number of row ==>", earray.nrow
162
 
                if hasattr(object, "shape"):
163
 
                    print "shape should look as:", object.shape
164
 
                print "row in earray ==>", repr(row)
165
 
                print "Should look like ==>", repr(object)
166
 
 
167
 
            assert self.nappends*self.chunksize == earray.nrows
168
 
            assert allequal(row, object, self.flavor)
169
 
            if hasattr(row, "shape"):
170
 
                assert len(row.shape) == len(self.shape) - 1
171
 
            else:
172
 
                # Scalar case
173
 
                assert len(self.shape) == 1
174
 
 
175
 
            # Check filters:
176
 
            if self.compress <> earray.filters.complevel and verbose:
177
 
                print "Error in compress. Class:", self.__class__.__name__
178
 
                print "self, earray:", self.compress, earray.filters.complevel
179
 
            tinfo = whichLibVersion(self.complib)
180
 
            if tinfo[0] == 0:
181
 
                self.complib = "zlib"
182
 
            assert earray.filters.complib == self.complib
183
 
            assert earray.filters.complevel == self.compress
184
 
            if self.shuffle <> earray.filters.shuffle and verbose:
185
 
                print "Error in shuffle. Class:", self.__class__.__name__
186
 
                print "self, earray:", self.shuffle, earray.filters.shuffle
187
 
            assert self.shuffle == earray.filters.shuffle
188
 
            if self.fletcher32 <> earray.filters.fletcher32 and verbose:
189
 
                print "Error in fletcher32. Class:", self.__class__.__name__
190
 
                print "self, earray:", self.fletcher32, earray.filters.fletcher32
191
 
            assert self.fletcher32 == earray.filters.fletcher32
192
 
 
193
 
    def test02_sssEArray(self):
194
 
        """Checking enlargeable array iterator with (start, stop, step)"""
195
 
 
196
 
        rootgroup = self.rootgroup
197
 
        if verbose:
198
 
            print '\n', '-=' * 30
199
 
            print "Running %s.test02_sssEArray..." % self.__class__.__name__
200
 
 
201
 
        # Create an instance of an HDF5 Table
202
 
        if self.reopen:
203
 
            self.fileh = openFile(self.file, "r")
204
 
        earray = self.fileh.getNode("/earray1")
205
 
 
206
 
        # Choose a small value for buffer size
207
 
        earray._v_maxTuples = 3
208
 
        if verbose:
209
 
            print "EArray descr:", repr(earray)
210
 
            print "shape of read array ==>", earray.shape
211
 
            print "reopening?:", self.reopen
212
 
            
213
 
        # Build the array to do comparisons
214
 
        if self.flavor == "numarray":
215
 
            if str(self.type) == "CharType":
216
 
                object_ = strings.array("a"*self.objsize, shape=self.rowshape,
217
 
                                        itemsize=earray.itemsize)
218
 
            else:
219
 
                object_ = arange(self.objsize, shape=self.rowshape,
220
 
                                 type=earray.type)
221
 
            object_.swapaxes(earray.extdim, 0)
222
 
        else:
223
 
            object_ = Numeric.arange(self.objsize,
224
 
                                     typecode=typecode[earray.type])
225
 
            object_ = Numeric.reshape(object_, self.rowshape)
226
 
            object_ = Numeric.swapaxes(object_, earray.extdim, 0)
227
 
            
228
 
        # Read all the array
229
 
        for row in earray.iterrows(start=self.start, stop=self.stop, step=self.step):
230
 
            if self.chunksize == 1:
231
 
                index = 0
232
 
            else:
233
 
                index = int(earray.nrow % self.chunksize)
234
 
            if str(self.type) == "CharType":
235
 
                object__ = object_
236
 
            else:
237
 
                object__ = object_ * (earray.nrow / self.chunksize)
238
 
                if self.flavor == "Numeric":
239
 
                    object__ = object__.astype(typecode[earray.type])
240
 
            object = object__[index]
241
 
            # The next adds much more verbosity
242
 
            if verbose and 0:
243
 
                print "number of row ==>", earray.nrow
244
 
                if hasattr(object, "shape"):
245
 
                    print "shape should look as:", object.shape
246
 
                print "row in earray ==>", repr(row)
247
 
                print "Should look like ==>", repr(object)
248
 
 
249
 
            assert self.nappends*self.chunksize == earray.nrows
250
 
            assert allequal(row, object, self.flavor)
251
 
            if hasattr(row, "shape"):
252
 
                assert len(row.shape) == len(self.shape) - 1
253
 
            else:
254
 
                # Scalar case
255
 
                assert len(self.shape) == 1
256
 
 
257
 
    def test03_readEArray(self):
258
 
        """Checking read() of enlargeable arrays"""
259
 
 
260
 
        rootgroup = self.rootgroup
261
 
        if verbose:
262
 
            print '\n', '-=' * 30
263
 
            print "Running %s.test03_readEArray..." % self.__class__.__name__
264
 
            
265
 
        # Create an instance of an HDF5 Table
266
 
        if self.reopen:
267
 
            self.fileh = openFile(self.file, "r")
268
 
        earray = self.fileh.getNode("/earray1")
269
 
 
270
 
        # Choose a small value for buffer size
271
 
        earray._v_maxTuples = 3
272
 
        if verbose:
273
 
            print "EArray descr:", repr(earray)
274
 
            print "shape of read array ==>", earray.shape
275
 
            print "reopening?:", self.reopen
276
 
            
277
 
        # Build the array to do comparisons
278
 
        if self.flavor == "numarray":
279
 
            if str(self.type) == "CharType":
280
 
                object_ = strings.array("a"*self.objsize, shape=self.rowshape,
281
 
                                        itemsize=earray.itemsize)
282
 
            else:
283
 
                object_ = arange(self.objsize, shape=self.rowshape,
284
 
                                 type=earray.type)
285
 
            object_.swapaxes(earray.extdim, 0)
286
 
        else:
287
 
            object_ = Numeric.arange(self.objsize,
288
 
                                     typecode=typecode[earray.type])
289
 
            object_ = Numeric.reshape(object_, self.rowshape)
290
 
            object_ = Numeric.swapaxes(object_, earray.extdim, 0)
291
 
            
292
 
        rowshape = self.rowshape
293
 
        rowshape[self.extdim] *= self.nappends
294
 
        if self.flavor == "numarray":
295
 
            if str(self.type) == "CharType":
296
 
                object__ = strings.array(None, shape=rowshape,
297
 
                                         itemsize=earray.itemsize)
298
 
            else:
299
 
                object__ = array(None, shape = rowshape, type=self.type)
300
 
            object__.swapaxes(0, self.extdim)
301
 
        else:
302
 
            object__ = Numeric.zeros(self.rowshape, typecode[earray.type])
303
 
            object__ = Numeric.swapaxes(object__, earray.extdim, 0)
304
 
 
305
 
        for i in range(self.nappends):
306
 
            j = i * self.chunksize
307
 
            if str(self.type) == "CharType":
308
 
                object__[j:j+self.chunksize] = object_
309
 
            else:
310
 
                if self.flavor == "numarray":
311
 
                    object__[j:j+self.chunksize] = object_ * i
312
 
                else:
313
 
                    object__[j:j+self.chunksize] = (object_ * i).astype(typecode[earray.type])
314
 
        stop = self.stop
315
 
        if self.nappends:
316
 
            # stop == None means read only the element designed by start
317
 
            # (in read() contexts)
318
 
            if self.stop == None:
319
 
                if self.start == -1:  # corner case
320
 
                    stop = earray.nrows
321
 
                else:
322
 
                    stop = self.start + 1
323
 
            # Protection against number of elements less than existing
324
 
            #if rowshape[self.extdim] < self.stop or self.stop == 0:
325
 
            if rowshape[self.extdim] < stop:
326
 
                # self.stop == 0 means last row only in read()
327
 
                # and not in [::] slicing notation
328
 
                stop = rowshape[self.extdim]
329
 
            # do a copy() in order to ensure that len(object._data)
330
 
            # actually do a measure of its length
331
 
            object = object__[self.start:stop:self.step].copy()
332
 
            # Swap the axes again to have normal ordering
333
 
            if self.flavor == "numarray":
334
 
                object.swapaxes(0, self.extdim)
335
 
            else:
336
 
                object = Numeric.swapaxes(object, 0, self.extdim)
337
 
        else:
338
 
            if self.flavor == "numarray":
339
 
                object = array(None, shape = self.shape, type=self.type)
340
 
            else:
341
 
                object = Numeric.zeros(self.shape, typecode[self.type])
342
 
 
343
 
        # Read all the array
344
 
        try:
345
 
            row = earray.read(self.start,self.stop,self.step)
346
 
        except IndexError:
347
 
            if self.flavor == "numarray":
348
 
                row = array(None, shape = self.shape, type=self.type)
349
 
            else:
350
 
                row = Numeric.zeros(self.shape, typecode[self.type])
351
 
 
352
 
        if verbose:
353
 
            if hasattr(object, "shape"):
354
 
                print "shape should look as:", object.shape
355
 
            print "Object read ==>", repr(row)
356
 
            print "Should look like ==>", repr(object)
357
 
            
358
 
        assert self.nappends*self.chunksize == earray.nrows
359
 
        assert allequal(row, object, self.flavor)
360
 
        if hasattr(row, "shape"):
361
 
            assert len(row.shape) == len(self.shape)
362
 
        else:
363
 
            # Scalar case
364
 
            assert len(self.shape) == 1
365
 
 
366
 
    def test04_getitemEArray(self):
367
 
        """Checking enlargeable array __getitem__ special method"""
368
 
 
369
 
        rootgroup = self.rootgroup
370
 
        if verbose:
371
 
            print '\n', '-=' * 30
372
 
            print "Running %s.test04_getitemEArray..." % self.__class__.__name__
373
 
 
374
 
        if not hasattr(self, "slices"):
375
 
            # If there is not a slices attribute, create it
376
 
            self.slices = (slice(self.start, self.stop, self.step),)
377
 
            
378
 
        # Create an instance of an HDF5 Table
379
 
        if self.reopen:
380
 
            self.fileh = openFile(self.file, "r")
381
 
        earray = self.fileh.getNode("/earray1")
382
 
 
383
 
        # Choose a small value for buffer size
384
 
        #earray._v_maxTuples = 3   # this does not really changes the chunksize
385
 
        if verbose:
386
 
            print "EArray descr:", repr(earray)
387
 
            print "shape of read array ==>", earray.shape
388
 
            print "reopening?:", self.reopen
389
 
 
390
 
        # Build the array to do comparisons
391
 
        if str(self.type) == "CharType":
392
 
            object_ = strings.array("a"*self.objsize, shape=self.rowshape,
393
 
                                    itemsize=earray.itemsize)
394
 
        else:
395
 
            object_ = arange(self.objsize, shape=self.rowshape,
396
 
                             type=earray.type)
397
 
        object_.swapaxes(earray.extdim, 0)
398
 
            
399
 
        rowshape = self.rowshape
400
 
        rowshape[self.extdim] *= self.nappends
401
 
        if str(self.type) == "CharType":
402
 
            object__ = strings.array(None, shape=rowshape,
403
 
                                     itemsize=earray.itemsize)
404
 
        else:
405
 
            object__ = array(None, shape = rowshape, type=self.type)
406
 
        object__.swapaxes(0, self.extdim)
407
 
 
408
 
        for i in range(self.nappends):
409
 
            j = i * self.chunksize
410
 
            if str(self.type) == "CharType":
411
 
                object__[j:j+self.chunksize] = object_
412
 
            else:
413
 
                object__[j:j+self.chunksize] = object_ * i
414
 
 
415
 
        stop = self.stop
416
 
        if self.nappends:
417
 
            # Swap the axes again to have normal ordering
418
 
            object__.swapaxes(0, self.extdim)
419
 
            # do a copy() in order to ensure that len(object._data)
420
 
            # actually do a measure of its length
421
 
            object = object__.__getitem__(self.slices).copy()
422
 
        else:
423
 
            object = array(None, shape = self.shape, type=self.type)
424
 
 
425
 
        if self.flavor == "Numeric":
426
 
            # Convert the object to Numeric
427
 
            object = Numeric.array(object, typecode=typecode[self.type])
428
 
 
429
 
        # Read all the array
430
 
        row = earray.__getitem__(self.slices)
431
 
        try:
432
 
            row = earray.__getitem__(self.slices)
433
 
        except IndexError:
434
 
            print "IndexError!"
435
 
            if self.flavor == "numarray":
436
 
                row = array(None, shape = self.shape, type=self.type)
437
 
            else:
438
 
                row = Numeric.zeros(self.shape, typecode[self.type])
439
 
 
440
 
        if verbose:
441
 
            print "Object read:\n", repr(row) #, row.info()
442
 
            print "Should look like:\n", repr(object) #, row.info()
443
 
            if hasattr(object, "shape"):
444
 
                print "Original object shape:", self.shape
445
 
                print "Shape read:", row.shape
446
 
                print "shape should look as:", object.shape
447
 
 
448
 
        assert self.nappends*self.chunksize == earray.nrows
449
 
        assert allequal(row, object, self.flavor)
450
 
        if not hasattr(row, "shape"):
451
 
            # Scalar case
452
 
            assert len(self.shape) == 1
453
 
 
454
 
 
455
 
    def test05_setitemEArray(self):
456
 
        """Checking enlargeable array __setitem__ special method"""
457
 
 
458
 
        rootgroup = self.rootgroup
459
 
        if self.__class__.__name__ == "Ellipsis6EArrayTestCase":
460
 
            # We have a problem with test design here, but I think
461
 
            # it is not worth the effort to solve it
462
 
            # F.Alted 2004-10-27
463
 
            return
464
 
        if verbose:
465
 
            print '\n', '-=' * 30
466
 
            print "Running %s.test05_setitemEArray..." % self.__class__.__name__
467
 
 
468
 
        if not hasattr(self, "slices"):
469
 
            # If there is not a slices attribute, create it
470
 
            self.slices = (slice(self.start, self.stop, self.step),)
471
 
            
472
 
        # Create an instance of an HDF5 Table
473
 
        if self.reopen:
474
 
            self.fileh = openFile(self.file, "a")
475
 
        earray = self.fileh.getNode("/earray1")
476
 
 
477
 
        # Choose a small value for buffer size
478
 
        #earray._v_maxTuples = 3   # this does not really changes the chunksize
479
 
        if verbose:
480
 
            print "EArray descr:", repr(earray)
481
 
            print "shape of read array ==>", earray.shape
482
 
            print "reopening?:", self.reopen
483
 
 
484
 
        # Build the array to do comparisons
485
 
        if str(self.type) == "CharType":
486
 
            object_ = strings.array("a"*self.objsize, shape=self.rowshape,
487
 
                                    itemsize=earray.itemsize)
488
 
        else:
489
 
            object_ = arange(self.objsize, shape=self.rowshape,
490
 
                             type=earray.type)
491
 
        object_.swapaxes(earray.extdim, 0)
492
 
            
493
 
        rowshape = self.rowshape
494
 
        rowshape[self.extdim] *= self.nappends
495
 
        if str(self.type) == "CharType":
496
 
            object__ = strings.array(None, shape=rowshape,
497
 
                                     itemsize=earray.itemsize)
498
 
        else:
499
 
            object__ = array(None, shape = rowshape, type=self.type)
500
 
        object__.swapaxes(0, self.extdim)
501
 
 
502
 
        for i in range(self.nappends):
503
 
            j = i * self.chunksize
504
 
            if str(self.type) == "CharType":
505
 
                object__[j:j+self.chunksize] = object_
506
 
            else:
507
 
                object__[j:j+self.chunksize] = object_ * i
508
 
                # Modify the earray
509
 
                #earray[j:j+self.chunksize] = object_ * i
510
 
                #earray[self.slices] = 1
511
 
 
512
 
        stop = self.stop
513
 
        if self.nappends:
514
 
            # Swap the axes again to have normal ordering
515
 
            object__.swapaxes(0, self.extdim)
516
 
            # do a copy() in order to ensure that len(object._data)
517
 
            # actually do a measure of its length
518
 
            object = object__.__getitem__(self.slices).copy()
519
 
        else:
520
 
            object = array(None, shape = self.shape, type=self.type)
521
 
 
522
 
        if self.flavor == "Numeric":
523
 
            # Convert the object to Numeric
524
 
            object = Numeric.array(object, typecode=typecode[self.type])
525
 
 
526
 
        if str(self.type) == "CharType":
527
 
            if hasattr(self, "wslice"):
528
 
                object[self.wslize] = object[self.wslice].pad("xXx")
529
 
                earray[self.wslice] = earray[self.wslice].pad("xXx")
530
 
            elif sum(object[self.slices].shape) <> 0 :
531
 
                object[:] = object.pad("xXx")
532
 
                if object.size() > 0:
533
 
                    earray[self.slices] = object
534
 
        else:
535
 
            if hasattr(self, "wslice"):
536
 
                object[self.wslice] = object[self.wslice] * 2 + 3
537
 
                earray[self.wslice] = earray[self.wslice] * 2 + 3
538
 
            elif sum(object[self.slices].shape) <> 0:
539
 
                object = object * 2 + 3
540
 
                if reduce(lambda x,y:x*y, object.shape) > 0:
541
 
                    earray[self.slices] = earray[self.slices] * 2 + 3
542
 
        # Read all the array
543
 
        row = earray.__getitem__(self.slices)
544
 
        try:
545
 
            row = earray.__getitem__(self.slices)
546
 
        except IndexError:
547
 
            print "IndexError!"
548
 
            if self.flavor == "numarray":
549
 
                row = array(None, shape = self.shape, type=self.type)
550
 
            else:
551
 
                row = Numeric.zeros(self.shape, typecode[self.type])
552
 
 
553
 
        if verbose:
554
 
            print "Object read:\n", repr(row) #, row.info()
555
 
            print "Should look like:\n", repr(object) #, row.info()
556
 
            if hasattr(object, "shape"):
557
 
                print "Original object shape:", self.shape
558
 
                print "Shape read:", row.shape
559
 
                print "shape should look as:", object.shape
560
 
 
561
 
        assert self.nappends*self.chunksize == earray.nrows
562
 
        assert allequal(row, object, self.flavor)
563
 
        if not hasattr(row, "shape"):
564
 
            # Scalar case
565
 
            assert len(self.shape) == 1
566
 
 
567
 
 
568
 
class BasicWriteTestCase(BasicTestCase):
569
 
    type = Int32
570
 
    shape = (0,)
571
 
    chunksize = 5
572
 
    nappends = 10
573
 
    step = 1
574
 
    #wslice = slice(1,nappends,2)
575
 
    wslice = 1  # single element case
576
 
 
577
 
class BasicWrite2TestCase(BasicTestCase):
578
 
    type = Int32
579
 
    shape = (0,)
580
 
    chunksize = 5
581
 
    nappends = 10
582
 
    step = 1
583
 
    wslice = slice(chunksize-2,nappends,2)  # range of elements
584
 
    reopen = 0  # This case does not reopen files
585
 
    
586
 
class EmptyEArrayTestCase(BasicTestCase):
587
 
    type = Int32
588
 
    shape = (2, 0)
589
 
    chunksize = 5
590
 
    nappends = 0
591
 
    start = 0
592
 
    stop = 10
593
 
    step = 1
594
 
 
595
 
class EmptyEArray2TestCase(BasicTestCase):
596
 
    type = Int32
597
 
    shape = (2, 0)
598
 
    chunksize = 5
599
 
    nappends = 0
600
 
    start = 0
601
 
    stop = 10
602
 
    step = 1
603
 
    reopen = 0  # This case does not reopen files
604
 
 
605
 
class SlicesEArrayTestCase(BasicTestCase):
606
 
    compress = 1
607
 
    complib = "lzo"
608
 
    type = Int32
609
 
    shape = (2, 0)
610
 
    chunksize = 5
611
 
    nappends = 2
612
 
    slices = (slice(1,2,1), slice(1,3,1))
613
 
 
614
 
class EllipsisEArrayTestCase(BasicTestCase):
615
 
    type = Int32
616
 
    shape = (2, 0)
617
 
    chunksize = 5
618
 
    nappends = 2
619
 
    #slices = (slice(1,2,1), Ellipsis)
620
 
    slices = (Ellipsis, slice(1,2,1))
621
 
 
622
 
class Slices2EArrayTestCase(BasicTestCase):
623
 
    compress = 1
624
 
    complib = "lzo"
625
 
    type = Int32
626
 
    shape = (2, 0, 4)
627
 
    chunksize = 5
628
 
    nappends = 20
629
 
    slices = (slice(1,2,1), slice(None, None, None), slice(1,4,2))
630
 
 
631
 
class Ellipsis2EArrayTestCase(BasicTestCase):
632
 
    type = Int32
633
 
    shape = (2, 0, 4)
634
 
    chunksize = 5
635
 
    nappends = 20
636
 
    slices = (slice(1,2,1), Ellipsis, slice(1,4,2))
637
 
 
638
 
class Slices3EArrayTestCase(BasicTestCase):
639
 
    compress = 1      # To show the chunks id DEBUG is on
640
 
    complib = "lzo"
641
 
    type = Int32
642
 
    shape = (2, 3, 4, 0)
643
 
    chunksize = 5
644
 
    nappends = 20
645
 
    slices = (slice(1, 2, 1), slice(0, None, None), slice(1,4,2))  # Don't work
646
 
    #slices = (slice(None, None, None), slice(0, None, None), slice(1,4,1)) # W
647
 
    #slices = (slice(None, None, None), slice(None, None, None), slice(1,4,2)) # N
648
 
    #slices = (slice(1,2,1), slice(None, None, None), slice(1,4,2)) # N
649
 
    # Disable the failing test temporarily with a working test case
650
 
    slices = (slice(1,2,1), slice(1, 4, None), slice(1,4,2)) # Y
651
 
    #slices = (slice(1,2,1), slice(0, 4, None), slice(1,4,1)) # Y
652
 
    slices = (slice(1,2,1), slice(0, 4, None), slice(1,4,2)) # N
653
 
    #slices = (slice(1,2,1), slice(0, 4, None), slice(1,4,2), slice(0,100,1)) # N
654
 
 
655
 
class Slices4EArrayTestCase(BasicTestCase):
656
 
    type = Int32
657
 
    shape = (2, 3, 4, 0, 5, 6)
658
 
    chunksize = 5
659
 
    nappends = 20
660
 
    slices = (slice(1, 2, 1), slice(0, None, None), slice(1,4,2),
661
 
              slice(0,4,2), slice(3,5,2), slice(2,7,1))
662
 
 
663
 
class Ellipsis3EArrayTestCase(BasicTestCase):
664
 
    type = Int32
665
 
    shape = (2, 3, 4, 0)
666
 
    chunksize = 5
667
 
    nappends = 20
668
 
    slices = (Ellipsis, slice(0, 4, None), slice(1,4,2))
669
 
    slices = (slice(1,2,1), slice(0, 4, None), slice(1,4,2), Ellipsis) 
670
 
 
671
 
class Ellipsis4EArrayTestCase(BasicTestCase):
672
 
    type = Int32
673
 
    shape = (2, 3, 4, 0)
674
 
    chunksize = 5
675
 
    nappends = 20
676
 
    slices = (Ellipsis, slice(0, 4, None), slice(1,4,2))
677
 
    slices = (slice(1,2,1), Ellipsis, slice(1,4,2))
678
 
 
679
 
class Ellipsis5EArrayTestCase(BasicTestCase):
680
 
    type = Int32
681
 
    shape = (2, 3, 4, 0)
682
 
    chunksize = 5
683
 
    nappends = 20
684
 
    slices = (slice(1,2,1), slice(0, 4, None), Ellipsis)
685
 
 
686
 
class Ellipsis6EArrayTestCase(BasicTestCase):
687
 
    type = Int32
688
 
    shape = (2, 3, 4, 0)
689
 
    chunksize = 5
690
 
    nappends = 2
691
 
    # The next slices gives problems with setting values (test05)
692
 
    # This is a problem on the test design, not the Array.__setitem__ 
693
 
    # code, though.
694
 
    slices = (slice(1,2,1), slice(0, 4, None), 2, Ellipsis)
695
 
 
696
 
class Ellipsis7EArrayTestCase(BasicTestCase):
697
 
    type = Int32
698
 
    shape = (2, 3, 4, 0)
699
 
    chunksize = 5
700
 
    nappends = 2
701
 
    slices = (slice(1,2,1), slice(0, 4, None), slice(2,3), Ellipsis)
702
 
 
703
 
class MD3WriteTestCase(BasicTestCase):
704
 
    type = Int32
705
 
    shape = (2, 0, 3)
706
 
    chunksize = 4
707
 
    step = 2
708
 
 
709
 
class MD5WriteTestCase(BasicTestCase):
710
 
    type = Int32
711
 
    shape = (2, 0, 3, 4, 5)  # ok
712
 
    #shape = (1, 1, 0, 1)  # Minimum shape that shows problems with HDF5 1.6.1
713
 
    #shape = (2, 3, 0, 4, 5)  # Floating point exception (HDF5 1.6.1)
714
 
    #shape = (2, 3, 3, 0, 5, 6) # Segmentation fault (HDF5 1.6.1)
715
 
    chunksize = 1
716
 
    nappends = 1
717
 
    start = 1
718
 
    stop = 10
719
 
    step = 10
720
 
 
721
 
class MD6WriteTestCase(BasicTestCase):
722
 
    type = Int32
723
 
    shape = (2, 3, 3, 0, 5, 6)
724
 
    chunksize = 1
725
 
    nappends = 10
726
 
    start = 1
727
 
    stop = 10
728
 
    step = 3
729
 
 
730
 
class MD6WriteTestCase__(BasicTestCase):
731
 
    type = Int32
732
 
    shape = (2, 0)
733
 
    chunksize = 1
734
 
    nappends = 3
735
 
    start = 1
736
 
    stop = 3
737
 
    step = 1
738
 
 
739
 
class MD7WriteTestCase(BasicTestCase):
740
 
    type = Int32
741
 
    shape = (2, 3, 3, 4, 5, 0, 3)
742
 
    chunksize = 10
743
 
    nappends = 1
744
 
    start = 1
745
 
    stop = 10
746
 
    step = 2
747
 
 
748
 
class MD10WriteTestCase(BasicTestCase):
749
 
    type = Int32
750
 
    shape = (1, 2, 3, 4, 5, 5, 4, 3, 2, 0)
751
 
    chunksize = 5
752
 
    nappends = 10
753
 
    start = -1
754
 
    stop = -1
755
 
    step = 10
756
 
 
757
 
class ZlibComprTestCase(BasicTestCase):
758
 
    compress = 1
759
 
    complib = "zlib"
760
 
    start = 3
761
 
    #stop = 0   # means last row
762
 
    stop = None   # means last row from 0.8 on
763
 
    step = 10
764
 
 
765
 
class ZlibShuffleTestCase(BasicTestCase):
766
 
    shuffle = 1
767
 
    compress = 1
768
 
    complib = "zlib"
769
 
    # case start < stop , i.e. no rows read
770
 
    start = 3
771
 
    stop = 1
772
 
    step = 10
773
 
 
774
 
class LZOComprTestCase(BasicTestCase):
775
 
    compress = 1  # sss
776
 
    complib = "lzo"
777
 
    chunksize = 10
778
 
    nappends = 100
779
 
    start = 3
780
 
    stop = 10
781
 
    step = 3
782
 
 
783
 
class LZOShuffleTestCase(BasicTestCase):
784
 
    compress = 1
785
 
    shuffle = 1
786
 
    complib = "lzo"
787
 
    chunksize = 100
788
 
    nappends = 10
789
 
    start = 3
790
 
    stop = 10
791
 
    step = 7
792
 
 
793
 
class UCLComprTestCase(BasicTestCase):
794
 
    compress = 1
795
 
    complib = "ucl"
796
 
    chunksize = 100
797
 
    nappends = 10
798
 
    start = 3
799
 
    stop = 10
800
 
    step = 8
801
 
 
802
 
class UCLShuffleTestCase(BasicTestCase):
803
 
    compress = 1
804
 
    shuffle = 1
805
 
    complib = "ucl"
806
 
    chunksize = 100
807
 
    nappends = 10
808
 
    start = 3
809
 
    stop = 10
810
 
    step = 6
811
 
 
812
 
class Fletcher32TestCase(BasicTestCase):
813
 
    compress = 0
814
 
    fletcher32 = 1
815
 
    chunksize = 50
816
 
    nappends = 20
817
 
    start = 4
818
 
    stop = 20
819
 
    step = 7
820
 
 
821
 
class AllFiltersTestCase(BasicTestCase):
822
 
    compress = 1
823
 
    shuffle = 1
824
 
    fletcher32 = 1
825
 
    complib = "ucl"
826
 
    chunksize = 20  # sss
827
 
    nappends = 50
828
 
    start = 2
829
 
    stop = 99 
830
 
    step = 6
831
 
#     chunksize = 3
832
 
#     nappends = 2
833
 
#     start = 1
834
 
#     stop = 10
835
 
#     step = 2
836
 
 
837
 
class FloatTypeTestCase(BasicTestCase):
838
 
    type = Float64
839
 
    shape = (2,0)
840
 
    chunksize = 5
841
 
    nappends = 10
842
 
    start = 3
843
 
    stop = 10
844
 
    step = 20
845
 
 
846
 
class ComplexTypeTestCase(BasicTestCase):
847
 
    type = Complex64
848
 
    shape = (2,0)
849
 
    chunksize = 5
850
 
    nappends = 10
851
 
    start = 3
852
 
    stop = 10
853
 
    step = 20
854
 
 
855
 
class CharTypeTestCase(BasicTestCase):
856
 
    type = "CharType"
857
 
    length = 20
858
 
    shape = (2, 0)
859
 
    #shape = (2,0,20)
860
 
    chunksize = 5
861
 
    nappends = 10
862
 
    start = 3
863
 
    stop = 10
864
 
    step = 20
865
 
    slices = (slice(0,1),slice(1,2))
866
 
 
867
 
class CharType2TestCase(BasicTestCase):
868
 
    type = "CharType"
869
 
    length = 20
870
 
    shape = (0,)
871
 
    #shape = (0, 20)
872
 
    chunksize = 5
873
 
    nappends = 10
874
 
    start = 1
875
 
    stop = 10
876
 
    step = 2
877
 
 
878
 
class CharTypeComprTestCase(BasicTestCase):
879
 
    type = "CharType"
880
 
    length = 20
881
 
    shape = (20,0,10)
882
 
    #shape = (20,0,10,20)
883
 
    compr = 1
884
 
    #shuffle = 1  # this shouldn't do nothing on chars
885
 
    chunksize = 50
886
 
    nappends = 10
887
 
    start = -1
888
 
    stop = 100
889
 
    step = 20
890
 
 
891
 
class Numeric1TestCase(BasicTestCase):
892
 
    # Setting flavor to Numeric here gives some problems due,
893
 
    # most probably to test implementation, not library code
894
 
    #flavor = "Numeric"
895
 
    type = "Int32"
896
 
    shape = (2,0)
897
 
    compress = 1
898
 
    shuffle = 1
899
 
    chunksize = 50
900
 
    nappends = 20
901
 
    start = -1
902
 
    stop = 100
903
 
    step = 20
904
 
 
905
 
class Numeric2TestCase(BasicTestCase):
906
 
    flavor = "Numeric"
907
 
    # type = Float32 gives some problems on tests. It is *not* a
908
 
    # problem with Array.__setitem__(), just with test design
909
 
    #type = "Float32"
910
 
    type = "Float64"
911
 
    shape = (0,)
912
 
    compress = 1
913
 
    shuffle = 1
914
 
    chunksize = 2
915
 
    nappends = 1
916
 
    start = -1
917
 
    stop = 100
918
 
    step = 20
919
 
 
920
 
class NumericComprTestCase(BasicTestCase):
921
 
    flavor = "Numeric"
922
 
    type = "Float64"
923
 
    compress = 1
924
 
    shuffle = 1
925
 
    shape = (0,)
926
 
    compr = 1
927
 
    chunksize = 2
928
 
    nappends = 1
929
 
    start = 51
930
 
    stop = 100
931
 
    step = 7
932
 
 
933
 
# It remains a test of Numeric char types, but the code is getting too messy
934
 
 
935
 
class OffsetStrideTestCase(unittest.TestCase):
936
 
    mode  = "w" 
937
 
    compress = 0
938
 
    complib = "zlib"  # Default compression library
939
 
 
940
 
    def setUp(self):
941
 
 
942
 
        # Create an instance of an HDF5 Table
943
 
        self.file = tempfile.mktemp(".h5")
944
 
        self.fileh = openFile(self.file, self.mode)
945
 
        self.rootgroup = self.fileh.root
946
 
 
947
 
    def tearDown(self):
948
 
        self.fileh.close()
949
 
        os.remove(self.file)
950
 
        
951
 
    #----------------------------------------
952
 
 
953
 
    def test01a_String(self):
954
 
        """Checking earray with offseted numarray strings appends"""
955
 
 
956
 
        root = self.rootgroup
957
 
        if verbose:
958
 
            print '\n', '-=' * 30
959
 
            print "Running %s.test01a_StringAtom..." % self.__class__.__name__
960
 
 
961
 
        # Create an string atom
962
 
        earray = self.fileh.createEArray(root, 'strings',
963
 
                                         StringAtom(length=3,
964
 
                                                    shape=(0,2,2)),
965
 
                                         "Array of strings")
966
 
        a=strings.array([[["a","b"],["123", "45"],["45", "123"]]], itemsize=3)
967
 
        earray.append(a[:,1:])
968
 
        a=strings.array([[["s", "a"],["ab", "f"],["s", "abc"],["abc", "f"]]])
969
 
        earray.append(a[:,2:])
970
 
 
971
 
        # Read all the rows:
972
 
        row = earray.read()
973
 
        if verbose:
974
 
            print "Object read:", row
975
 
            print "Nrows in", earray._v_pathname, ":", earray.nrows
976
 
            print "Second row in earray ==>", row[1].tolist()
977
 
            
978
 
        assert earray.nrows == 2
979
 
        assert row[0].tolist() == [["123", "45"],["45", "123"]]
980
 
        assert row[1].tolist() == [["s", "abc"],["abc", "f"]]
981
 
        assert len(row[0]) == 2
982
 
        assert len(row[1]) == 2
983
 
 
984
 
    def test01b_String(self):
985
 
        """Checking earray with strided numarray strings appends"""
986
 
 
987
 
        root = self.rootgroup
988
 
        if verbose:
989
 
            print '\n', '-=' * 30
990
 
            print "Running %s.test01b_StringAtom..." % self.__class__.__name__
991
 
 
992
 
        # Create an string atom
993
 
        earray = self.fileh.createEArray(root, 'strings',
994
 
                                         StringAtom(length=3,
995
 
                                                    shape=(0,2,2)),
996
 
                                         "Array of strings")
997
 
        a=strings.array([[["a","b"],["123", "45"],["45", "123"]]], itemsize=3)
998
 
        earray.append(a[:,::2])
999
 
        a=strings.array([[["s", "a"],["ab", "f"],["s", "abc"],["abc", "f"]]])
1000
 
        earray.append(a[:,::2])
1001
 
 
1002
 
        # Read all the rows:
1003
 
        row = earray.read()
1004
 
        if verbose:
1005
 
            print "Object read:", row
1006
 
            print "Nrows in", earray._v_pathname, ":", earray.nrows
1007
 
            print "Second row in earray ==>", row[1].tolist()
1008
 
            
1009
 
        assert earray.nrows == 2
1010
 
        assert row[0].tolist() == [["a","b"],["45", "123"]]
1011
 
        assert row[1].tolist() == [["s", "a"],["s", "abc"]]
1012
 
        assert len(row[0]) == 2
1013
 
        assert len(row[1]) == 2
1014
 
 
1015
 
    def test02a_int(self):
1016
 
        """Checking earray with offseted numarray ints appends"""
1017
 
 
1018
 
        root = self.rootgroup
1019
 
        if verbose:
1020
 
            print '\n', '-=' * 30
1021
 
            print "Running %s.test02a_int..." % self.__class__.__name__
1022
 
 
1023
 
        # Create an string atom
1024
 
        earray = self.fileh.createEArray(root, 'EAtom',
1025
 
                                         Int32Atom(shape=(0,3)),
1026
 
                                         "array of ints")
1027
 
        a=array([(0,0,0), (1,0,3), (1,1,1), (0,0,0)], type=Int32)
1028
 
        earray.append(a[2:])  # Create an offset
1029
 
        a=array([(1,1,1), (-1,0,0)], type=Int32)
1030
 
        earray.append(a[1:])  # Create an offset
1031
 
 
1032
 
        # Read all the rows:
1033
 
        row = earray.read()
1034
 
        if verbose:
1035
 
            print "Object read:", row
1036
 
            print "Nrows in", earray._v_pathname, ":", earray.nrows
1037
 
            print "Third row in vlarray ==>", row[2]
1038
 
            
1039
 
        assert earray.nrows == 3
1040
 
        assert allequal(row[0], array([1,1,1], type=Int32))
1041
 
        assert allequal(row[1], array([0,0,0], type=Int32))
1042
 
        assert allequal(row[2], array([-1,0,0], type=Int32))
1043
 
 
1044
 
    def test02b_int(self):
1045
 
        """Checking earray with strided numarray ints appends"""
1046
 
 
1047
 
        root = self.rootgroup
1048
 
        if verbose:
1049
 
            print '\n', '-=' * 30
1050
 
            print "Running %s.test02b_int..." % self.__class__.__name__
1051
 
 
1052
 
        # Create an string atom
1053
 
        earray = self.fileh.createEArray(root, 'EAtom',
1054
 
                                         Int32Atom(shape=(0,3)),
1055
 
                                         "array of ints")
1056
 
        a=array([(0,0,0), (1,0,3), (1,1,1), (3,3,3)], type=Int32)
1057
 
        earray.append(a[::3])  # Create an offset
1058
 
        a=array([(1,1,1), (-1,0,0)], type=Int32)
1059
 
        earray.append(a[::2])  # Create an offset
1060
 
 
1061
 
        # Read all the rows:
1062
 
        row = earray.read()
1063
 
        if verbose:
1064
 
            print "Object read:", row
1065
 
            print "Nrows in", earray._v_pathname, ":", earray.nrows
1066
 
            print "Third row in vlarray ==>", row[2]
1067
 
            
1068
 
        assert earray.nrows == 3
1069
 
        assert allequal(row[0], array([0,0,0], type=Int32))
1070
 
        assert allequal(row[1], array([3,3,3], type=Int32))
1071
 
        assert allequal(row[2], array([1,1,1], type=Int32))
1072
 
 
1073
 
class CopyTestCase(unittest.TestCase):
1074
 
 
1075
 
    def test01_copy(self):
1076
 
        """Checking EArray.copy() method """
1077
 
 
1078
 
        if verbose:
1079
 
            print '\n', '-=' * 30
1080
 
            print "Running %s.test01_copy..." % self.__class__.__name__
1081
 
 
1082
 
        # Create an instance of an HDF5 Table
1083
 
        file = tempfile.mktemp(".h5")
1084
 
        fileh = openFile(file, "w")
1085
 
 
1086
 
        # Create an EArray
1087
 
        arr = Atom(shape=(0, 2), dtype=Int16)
1088
 
        array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1089
 
        array1.append(array([[456, 2],[3, 457]], type=Int16))
1090
 
 
1091
 
        if self.close:
1092
 
            if verbose:
1093
 
                print "(closing file version)"
1094
 
            fileh.close()
1095
 
            fileh = openFile(file, mode = "a")
1096
 
            array1 = fileh.root.array1
1097
 
            
1098
 
        # Copy it to another location
1099
 
        array2, size = array1.copy('/', 'array2')
1100
 
 
1101
 
        if self.close:
1102
 
            if verbose:
1103
 
                print "(closing file version)"
1104
 
            fileh.close()
1105
 
            fileh = openFile(file, mode = "r")
1106
 
            array1 = fileh.root.array1
1107
 
            array2 = fileh.root.array2
1108
 
 
1109
 
        if verbose:
1110
 
            print "array1-->", array1.read()
1111
 
            print "array2-->", array2.read()
1112
 
            #print "dirs-->", dir(array1), dir(array2)
1113
 
            print "attrs array1-->", repr(array1.attrs)
1114
 
            print "attrs array2-->", repr(array2.attrs)
1115
 
            
1116
 
        # Check that all the elements are equal
1117
 
        assert allequal(array1.read(), array2.read())
1118
 
 
1119
 
        # Assert other properties in array
1120
 
        assert array1.nrows == array2.nrows
1121
 
        assert array1.shape == array2.shape
1122
 
        assert array1.extdim == array2.extdim
1123
 
        assert array1.flavor == array2.flavor
1124
 
        assert array1.type == array2.type
1125
 
        assert array1.itemsize == array2.itemsize
1126
 
        assert array1.title == array2.title
1127
 
        assert str(array1.atom) == str(array2.atom)
1128
 
 
1129
 
        # Close the file
1130
 
        fileh.close()
1131
 
        os.remove(file)
1132
 
 
1133
 
    def test02_copy(self):
1134
 
        """Checking EArray.copy() method (where specified)"""
1135
 
 
1136
 
        if verbose:
1137
 
            print '\n', '-=' * 30
1138
 
            print "Running %s.test02_copy..." % self.__class__.__name__
1139
 
 
1140
 
        # Create an instance of an HDF5 Table
1141
 
        file = tempfile.mktemp(".h5")
1142
 
        fileh = openFile(file, "w")
1143
 
 
1144
 
        # Create an EArray
1145
 
        arr = Atom(shape=(0, 2), dtype=Int16)
1146
 
        array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1147
 
        array1.append(array([[456, 2],[3, 457]], type=Int16))
1148
 
 
1149
 
        if self.close:
1150
 
            if verbose:
1151
 
                print "(closing file version)"
1152
 
            fileh.close()
1153
 
            fileh = openFile(file, mode = "a")
1154
 
            array1 = fileh.root.array1
1155
 
            
1156
 
        # Copy to another location
1157
 
        group1 = fileh.createGroup("/", "group1")
1158
 
        array2, size = array1.copy(group1, 'array2')
1159
 
 
1160
 
        if self.close:
1161
 
            if verbose:
1162
 
                print "(closing file version)"
1163
 
            fileh.close()
1164
 
            fileh = openFile(file, mode = "r")
1165
 
            array1 = fileh.root.array1
1166
 
            array2 = fileh.root.group1.array2
1167
 
 
1168
 
        if verbose:
1169
 
            print "array1-->", array1.read()
1170
 
            print "array2-->", array2.read()
1171
 
            #print "dirs-->", dir(array1), dir(array2)
1172
 
            print "attrs array1-->", repr(array1.attrs)
1173
 
            print "attrs array2-->", repr(array2.attrs)
1174
 
            
1175
 
        # Check that all the elements are equal
1176
 
        assert allequal(array1.read(), array2.read())
1177
 
 
1178
 
        # Assert other properties in array
1179
 
        assert array1.nrows == array2.nrows
1180
 
        assert array1.shape == array2.shape
1181
 
        assert array1.extdim == array2.extdim
1182
 
        assert array1.flavor == array2.flavor
1183
 
        assert array1.type == array2.type
1184
 
        assert array1.itemsize == array2.itemsize
1185
 
        assert array1.title == array2.title
1186
 
        assert str(array1.atom) == str(array2.atom)
1187
 
 
1188
 
        # Close the file
1189
 
        fileh.close()
1190
 
        os.remove(file)
1191
 
 
1192
 
    def test03_copy(self):
1193
 
        """Checking EArray.copy() method (Numeric flavor)"""
1194
 
 
1195
 
        if verbose:
1196
 
            print '\n', '-=' * 30
1197
 
            print "Running %s.test03_copy..." % self.__class__.__name__
1198
 
 
1199
 
        # Create an instance of an HDF5 Table
1200
 
        file = tempfile.mktemp(".h5")
1201
 
        fileh = openFile(file, "w")
1202
 
 
1203
 
        if numeric:
1204
 
            arr = Atom(shape=(0, 2), dtype=Int16, flavor="Numeric")
1205
 
        else:
1206
 
            arr = Atom(shape=(0, 2), dtype=Int16)
1207
 
 
1208
 
        array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1209
 
        array1.append(array([[456, 2],[3, 457]], type=Int16))
1210
 
 
1211
 
        if self.close:
1212
 
            if verbose:
1213
 
                print "(closing file version)"
1214
 
            fileh.close()
1215
 
            fileh = openFile(file, mode = "a")
1216
 
            array1 = fileh.root.array1
1217
 
            
1218
 
        # Copy to another location
1219
 
        array2, size = array1.copy('/', 'array2')
1220
 
 
1221
 
        if self.close:
1222
 
            if verbose:
1223
 
                print "(closing file version)"
1224
 
            fileh.close()
1225
 
            fileh = openFile(file, mode = "r")
1226
 
            array1 = fileh.root.array1
1227
 
            array2 = fileh.root.array2
1228
 
 
1229
 
        if verbose:
1230
 
            print "attrs array1-->", repr(array1.attrs)
1231
 
            print "attrs array2-->", repr(array2.attrs)
1232
 
            
1233
 
        # Assert other properties in array
1234
 
        assert array1.nrows == array2.nrows
1235
 
        assert array1.shape == array2.shape
1236
 
        assert array1.extdim == array2.extdim
1237
 
        assert array1.flavor == array2.flavor   # Very important here!
1238
 
        assert array1.type == array2.type
1239
 
        assert array1.itemsize == array2.itemsize
1240
 
        assert array1.title == array2.title
1241
 
        assert str(array1.atom) == str(array2.atom)
1242
 
 
1243
 
        # Close the file
1244
 
        fileh.close()
1245
 
        os.remove(file)
1246
 
 
1247
 
    def test03b_copy(self):
1248
 
        """Checking EArray.copy() method (Tuple flavor)"""
1249
 
 
1250
 
        if verbose:
1251
 
            print '\n', '-=' * 30
1252
 
            print "Running %s.test03b_copy..." % self.__class__.__name__
1253
 
 
1254
 
        # Create an instance of an HDF5 Table
1255
 
        file = tempfile.mktemp(".h5")
1256
 
        fileh = openFile(file, "w")
1257
 
 
1258
 
        arr = Atom(shape=(0, 2), dtype=Int16, flavor="Tuple")
1259
 
        array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1260
 
        array1.append(((456, 2),(3, 457)))
1261
 
 
1262
 
        if self.close:
1263
 
            if verbose:
1264
 
                print "(closing file version)"
1265
 
            fileh.close()
1266
 
            fileh = openFile(file, mode = "a")
1267
 
            array1 = fileh.root.array1
1268
 
            
1269
 
        # Copy to another location
1270
 
        array2, size = array1.copy('/', 'array2')
1271
 
 
1272
 
        if self.close:
1273
 
            if verbose:
1274
 
                print "(closing file version)"
1275
 
            fileh.close()
1276
 
            fileh = openFile(file, mode = "r")
1277
 
            array1 = fileh.root.array1
1278
 
            array2 = fileh.root.array2
1279
 
 
1280
 
        if verbose:
1281
 
            print "attrs array1-->", repr(array1.attrs)
1282
 
            print "attrs array2-->", repr(array2.attrs)
1283
 
 
1284
 
        # Check that all elements are equal
1285
 
        assert array1.read() == array2.read()
1286
 
        # Assert other properties in array
1287
 
        assert array1.nrows == array2.nrows
1288
 
        assert array1.shape == array2.shape
1289
 
        assert array1.extdim == array2.extdim
1290
 
        assert array1.flavor == array2.flavor   # Very important here!
1291
 
        assert array1.type == array2.type
1292
 
        assert array1.itemsize == array2.itemsize
1293
 
        assert array1.title == array2.title
1294
 
        assert str(array1.atom) == str(array2.atom)
1295
 
 
1296
 
        # Close the file
1297
 
        fileh.close()
1298
 
        os.remove(file)
1299
 
 
1300
 
    def test03c_copy(self):
1301
 
        """Checking EArray.copy() method (List flavor)"""
1302
 
 
1303
 
        if verbose:
1304
 
            print '\n', '-=' * 30
1305
 
            print "Running %s.test03c_copy..." % self.__class__.__name__
1306
 
 
1307
 
        # Create an instance of an HDF5 Table
1308
 
        file = tempfile.mktemp(".h5")
1309
 
        fileh = openFile(file, "w")
1310
 
 
1311
 
        arr = Atom(shape=(0, 2), dtype=Int16, flavor="List")
1312
 
        array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1313
 
        array1.append([[456, 2],[3, 457]])
1314
 
 
1315
 
        if self.close:
1316
 
            if verbose:
1317
 
                print "(closing file version)"
1318
 
            fileh.close()
1319
 
            fileh = openFile(file, mode = "a")
1320
 
            array1 = fileh.root.array1
1321
 
            
1322
 
        # Copy to another location
1323
 
        array2, size = array1.copy('/', 'array2')
1324
 
 
1325
 
        if self.close:
1326
 
            if verbose:
1327
 
                print "(closing file version)"
1328
 
            fileh.close()
1329
 
            fileh = openFile(file, mode = "r")
1330
 
            array1 = fileh.root.array1
1331
 
            array2 = fileh.root.array2
1332
 
 
1333
 
        if verbose:
1334
 
            print "attrs array1-->", repr(array1.attrs)
1335
 
            print "attrs array2-->", repr(array2.attrs)
1336
 
 
1337
 
        # Check that all elements are equal
1338
 
        assert array1.read() == array2.read()
1339
 
        # Assert other properties in array
1340
 
        assert array1.nrows == array2.nrows
1341
 
        assert array1.shape == array2.shape
1342
 
        assert array1.extdim == array2.extdim
1343
 
        assert array1.flavor == array2.flavor   # Very important here!
1344
 
        assert array1.type == array2.type
1345
 
        assert array1.itemsize == array2.itemsize
1346
 
        assert array1.title == array2.title
1347
 
        assert str(array1.atom) == str(array2.atom)
1348
 
 
1349
 
        # Close the file
1350
 
        fileh.close()
1351
 
        os.remove(file)
1352
 
 
1353
 
    def test03d_copy(self):
1354
 
        """Checking EArray.copy() method (String flavor)"""
1355
 
 
1356
 
        if verbose:
1357
 
            print '\n', '-=' * 30
1358
 
            print "Running %s.test03d_copy..." % self.__class__.__name__
1359
 
 
1360
 
        # Create an instance of an HDF5 Table
1361
 
        file = tempfile.mktemp(".h5")
1362
 
        fileh = openFile(file, "w")
1363
 
 
1364
 
        arr = StringAtom(shape=(0, 2), length=4, flavor="String")
1365
 
        array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1366
 
        array1.append([["456", "2"],["3", "457"]])
1367
 
 
1368
 
        if self.close:
1369
 
            if verbose:
1370
 
                print "(closing file version)"
1371
 
            fileh.close()
1372
 
            fileh = openFile(file, mode = "a")
1373
 
            array1 = fileh.root.array1
1374
 
            
1375
 
        # Copy to another location
1376
 
        array2, size = array1.copy('/', 'array2')
1377
 
 
1378
 
        if self.close:
1379
 
            if verbose:
1380
 
                print "(closing file version)"
1381
 
            fileh.close()
1382
 
            fileh = openFile(file, mode = "r")
1383
 
            array1 = fileh.root.array1
1384
 
            array2 = fileh.root.array2
1385
 
 
1386
 
        if verbose:
1387
 
            print "attrs array1-->", repr(array1.attrs)
1388
 
            print "attrs array2-->", repr(array2.attrs)
1389
 
 
1390
 
        # Check that all elements are equal
1391
 
        assert array1.read() == array2.read()
1392
 
        
1393
 
        # Assert other properties in array
1394
 
        assert array1.nrows == array2.nrows
1395
 
        assert array1.shape == array2.shape
1396
 
        assert array1.extdim == array2.extdim
1397
 
        assert array1.flavor == array2.flavor   # Very important here!
1398
 
        assert array1.type == array2.type
1399
 
        assert array1.itemsize == array2.itemsize
1400
 
        assert array1.title == array2.title
1401
 
        assert str(array1.atom) == str(array2.atom)
1402
 
 
1403
 
        # Close the file
1404
 
        fileh.close()
1405
 
        os.remove(file)
1406
 
 
1407
 
    def test03e_copy(self):
1408
 
        """Checking EArray.copy() method (CharArray flavor)"""
1409
 
 
1410
 
        if verbose:
1411
 
            print '\n', '-=' * 30
1412
 
            print "Running %s.test03e_copy..." % self.__class__.__name__
1413
 
 
1414
 
        # Create an instance of an HDF5 Table
1415
 
        file = tempfile.mktemp(".h5")
1416
 
        fileh = openFile(file, "w")
1417
 
 
1418
 
        arr = StringAtom(shape=(0, 2), length=4, flavor="CharArray")
1419
 
        array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1420
 
        array1.append(strings.array([["456", "2"],["3", "457"]], itemsize=4))
1421
 
 
1422
 
        if self.close:
1423
 
            if verbose:
1424
 
                print "(closing file version)"
1425
 
            fileh.close()
1426
 
            fileh = openFile(file, mode = "a")
1427
 
            array1 = fileh.root.array1
1428
 
            
1429
 
        # Copy to another location
1430
 
        array2, size = array1.copy('/', 'array2')
1431
 
 
1432
 
        if self.close:
1433
 
            if verbose:
1434
 
                print "(closing file version)"
1435
 
            fileh.close()
1436
 
            fileh = openFile(file, mode = "r")
1437
 
            array1 = fileh.root.array1
1438
 
            array2 = fileh.root.array2
1439
 
 
1440
 
        if verbose:
1441
 
            print "attrs array1-->", repr(array1.attrs)
1442
 
            print "attrs array2-->", repr(array2.attrs)
1443
 
 
1444
 
        # Check that all elements are equal
1445
 
        assert allequal(array1.read(), array2.read())
1446
 
        # Assert other properties in array
1447
 
        assert array1.nrows == array2.nrows
1448
 
        assert array1.shape == array2.shape
1449
 
        assert array1.extdim == array2.extdim
1450
 
        assert array1.flavor == array2.flavor   # Very important here!
1451
 
        assert array1.type == array2.type
1452
 
        assert array1.itemsize == array2.itemsize
1453
 
        assert array1.title == array2.title
1454
 
        assert str(array1.atom) == str(array2.atom)
1455
 
 
1456
 
        # Close the file
1457
 
        fileh.close()
1458
 
        os.remove(file)
1459
 
 
1460
 
    def test04_copy(self):
1461
 
        """Checking EArray.copy() method (checking title copying)"""
1462
 
 
1463
 
        if verbose:
1464
 
            print '\n', '-=' * 30
1465
 
            print "Running %s.test04_copy..." % self.__class__.__name__
1466
 
 
1467
 
        # Create an instance of an HDF5 Table
1468
 
        file = tempfile.mktemp(".h5")
1469
 
        fileh = openFile(file, "w")
1470
 
 
1471
 
        # Create an EArray
1472
 
        atom=Int16Atom(shape=(0,2))
1473
 
        array1 = fileh.createEArray(fileh.root, 'array1', atom, "title array1")
1474
 
        array1.append(array([[456, 2],[3, 457]], type=Int16))
1475
 
        # Append some user attrs
1476
 
        array1.attrs.attr1 = "attr1"
1477
 
        array1.attrs.attr2 = 2
1478
 
 
1479
 
        if self.close:
1480
 
            if verbose:
1481
 
                print "(closing file version)"
1482
 
            fileh.close()
1483
 
            fileh = openFile(file, mode = "a")
1484
 
            array1 = fileh.root.array1
1485
 
            
1486
 
        # Copy it to another Array
1487
 
        array2, size = array1.copy('/', 'array2', title="title array2")
1488
 
 
1489
 
        if self.close:
1490
 
            if verbose:
1491
 
                print "(closing file version)"
1492
 
            fileh.close()
1493
 
            fileh = openFile(file, mode = "r")
1494
 
            array1 = fileh.root.array1
1495
 
            array2 = fileh.root.array2
1496
 
            
1497
 
        # Assert user attributes
1498
 
        if verbose:
1499
 
            print "title of destination array-->", array2.title
1500
 
        array2.title == "title array2"
1501
 
 
1502
 
        # Close the file
1503
 
        fileh.close()
1504
 
        os.remove(file)
1505
 
 
1506
 
    def test05_copy(self):
1507
 
        """Checking EArray.copy() method (user attributes copied)"""
1508
 
 
1509
 
        if verbose:
1510
 
            print '\n', '-=' * 30
1511
 
            print "Running %s.test05_copy..." % self.__class__.__name__
1512
 
 
1513
 
        # Create an instance of an HDF5 Table
1514
 
        file = tempfile.mktemp(".h5")
1515
 
        fileh = openFile(file, "w")
1516
 
 
1517
 
        # Create an EArray
1518
 
        atom=Int16Atom(shape=(0,2))
1519
 
        array1 = fileh.createEArray(fileh.root, 'array1', atom, "title array1")
1520
 
        array1.append(array([[456, 2],[3, 457]], type=Int16))
1521
 
        # Append some user attrs
1522
 
        array1.attrs.attr1 = "attr1"
1523
 
        array1.attrs.attr2 = 2
1524
 
 
1525
 
        if self.close:
1526
 
            if verbose:
1527
 
                print "(closing file version)"
1528
 
            fileh.close()
1529
 
            fileh = openFile(file, mode = "a")
1530
 
            array1 = fileh.root.array1
1531
 
            
1532
 
        # Copy it to another Array
1533
 
        array2, size = array1.copy('/', 'array2', copyuserattrs=1)
1534
 
 
1535
 
        if self.close:
1536
 
            if verbose:
1537
 
                print "(closing file version)"
1538
 
            fileh.close()
1539
 
            fileh = openFile(file, mode = "r")
1540
 
            array1 = fileh.root.array1
1541
 
            array2 = fileh.root.array2
1542
 
 
1543
 
        if verbose:
1544
 
            print "attrs array1-->", repr(array1.attrs)
1545
 
            print "attrs array2-->", repr(array2.attrs)
1546
 
            
1547
 
        # Assert user attributes
1548
 
        array2.attrs.attr1 == "attr1"
1549
 
        array2.attrs.attr2 == 2
1550
 
 
1551
 
        # Close the file
1552
 
        fileh.close()
1553
 
        os.remove(file)
1554
 
 
1555
 
    def test05b_copy(self):
1556
 
        """Checking EArray.copy() method (user attributes not copied)"""
1557
 
 
1558
 
        if verbose:
1559
 
            print '\n', '-=' * 30
1560
 
            print "Running %s.test05b_copy..." % self.__class__.__name__
1561
 
 
1562
 
        # Create an instance of an HDF5 Table
1563
 
        file = tempfile.mktemp(".h5")
1564
 
        fileh = openFile(file, "w")
1565
 
 
1566
 
        # Create an Array
1567
 
        atom=Int16Atom(shape=(0,2))
1568
 
        array1 = fileh.createEArray(fileh.root, 'array1', atom, "title array1")
1569
 
        array1.append(array([[456, 2],[3, 457]], type=Int16))
1570
 
        # Append some user attrs
1571
 
        array1.attrs.attr1 = "attr1"
1572
 
        array1.attrs.attr2 = 2
1573
 
 
1574
 
        if self.close:
1575
 
            if verbose:
1576
 
                print "(closing file version)"
1577
 
            fileh.close()
1578
 
            fileh = openFile(file, mode = "a")
1579
 
            array1 = fileh.root.array1
1580
 
            
1581
 
        # Copy it to another Array
1582
 
        array2, size = array1.copy('/', 'array2', copyuserattrs=0)
1583
 
 
1584
 
        if self.close:
1585
 
            if verbose:
1586
 
                print "(closing file version)"
1587
 
            fileh.close()
1588
 
            fileh = openFile(file, mode = "r")
1589
 
            array1 = fileh.root.array1
1590
 
            array2 = fileh.root.array2
1591
 
 
1592
 
        if verbose:
1593
 
            print "attrs array1-->", repr(array1.attrs)
1594
 
            print "attrs array2-->", repr(array2.attrs)
1595
 
            
1596
 
        # Assert user attributes
1597
 
        hasattr(array2.attrs, "attr1") == 0
1598
 
        hasattr(array2.attrs, "attr2") == 0
1599
 
 
1600
 
        # Close the file
1601
 
        fileh.close()
1602
 
        os.remove(file)
1603
 
 
1604
 
 
1605
 
class CloseCopyTestCase(CopyTestCase):
1606
 
    close = 1
1607
 
 
1608
 
class OpenCopyTestCase(CopyTestCase):
1609
 
    close = 0
1610
 
 
1611
 
class CopyIndexTestCase(unittest.TestCase):
1612
 
    maxTuples = 2
1613
 
 
1614
 
    def test01_index(self):
1615
 
        """Checking EArray.copy() method with indexes"""
1616
 
 
1617
 
        if verbose:
1618
 
            print '\n', '-=' * 30
1619
 
            print "Running %s.test01_index..." % self.__class__.__name__
1620
 
 
1621
 
        # Create an instance of an HDF5 Array
1622
 
        file = tempfile.mktemp(".h5")
1623
 
        fileh = openFile(file, "w")
1624
 
 
1625
 
        # Create an EArray
1626
 
        atom = Int32Atom(shape=(0,2))
1627
 
        array1 = fileh.createEArray(fileh.root, 'array1', atom, "title array1")
1628
 
        r = arange(200, type=Int32, shape=(100,2))
1629
 
        array1.append(r)
1630
 
        
1631
 
        # Select a different buffer size:
1632
 
        array1._v_maxTuples = self.maxTuples
1633
 
        
1634
 
        # Copy to another array
1635
 
        array2, size = array1.copy("/", 'array2',
1636
 
                             start=self.start,
1637
 
                             stop=self.stop,
1638
 
                             step=self.step)
1639
 
        if verbose:
1640
 
            print "array1-->", array1.read()
1641
 
            print "array2-->", array2.read()
1642
 
            print "attrs array1-->", repr(array1.attrs)
1643
 
            print "attrs array2-->", repr(array2.attrs)
1644
 
            
1645
 
        # Check that all the elements are equal
1646
 
        r2 = r[self.start:self.stop:self.step]
1647
 
        assert allequal(r2, array2.read())
1648
 
 
1649
 
        # Assert the number of rows in array
1650
 
        if verbose:
1651
 
            print "nrows in array2-->", array2.nrows
1652
 
            print "and it should be-->", r2.shape[0]
1653
 
        assert r2.shape[0] == array2.nrows
1654
 
 
1655
 
        # Close the file
1656
 
        fileh.close()
1657
 
        os.remove(file)
1658
 
 
1659
 
    def test02_indexclosef(self):
1660
 
        """Checking EArray.copy() method with indexes (close file version)"""
1661
 
 
1662
 
        if verbose:
1663
 
            print '\n', '-=' * 30
1664
 
            print "Running %s.test02_indexclosef..." % self.__class__.__name__
1665
 
 
1666
 
        # Create an instance of an HDF5 Array
1667
 
        file = tempfile.mktemp(".h5")
1668
 
        fileh = openFile(file, "w")
1669
 
 
1670
 
        # Create an EArray
1671
 
        atom = Int32Atom(shape=(0,2))
1672
 
        array1 = fileh.createEArray(fileh.root, 'array1', atom, "title array1")
1673
 
        r = arange(200, type=Int32, shape=(100,2))
1674
 
        array1.append(r)
1675
 
 
1676
 
        # Select a different buffer size:
1677
 
        array1._v_maxTuples = self.maxTuples
1678
 
 
1679
 
        # Copy to another array
1680
 
        array2, size = array1.copy("/", 'array2',
1681
 
                             start=self.start,
1682
 
                             stop=self.stop,
1683
 
                             step=self.step)
1684
 
        # Close and reopen the file
1685
 
        fileh.close()
1686
 
        fileh = openFile(file, mode = "r")
1687
 
        array1 = fileh.root.array1
1688
 
        array2 = fileh.root.array2
1689
 
 
1690
 
        if verbose:
1691
 
            print "array1-->", array1.read()
1692
 
            print "array2-->", array2.read()
1693
 
            print "attrs array1-->", repr(array1.attrs)
1694
 
            print "attrs array2-->", repr(array2.attrs)
1695
 
            
1696
 
        # Check that all the elements are equal
1697
 
        r2 = r[self.start:self.stop:self.step]
1698
 
        assert allequal(r2, array2.read())
1699
 
 
1700
 
        # Assert the number of rows in array
1701
 
        if verbose:
1702
 
            print "nrows in array2-->", array2.nrows
1703
 
            print "and it should be-->", r2.shape[0]
1704
 
        assert r2.shape[0] == array2.nrows
1705
 
 
1706
 
        # Close the file
1707
 
        fileh.close()
1708
 
        os.remove(file)
1709
 
 
1710
 
class CopyIndex1TestCase(CopyIndexTestCase):
1711
 
    maxTuples = 1
1712
 
    start = 0
1713
 
    stop = 7
1714
 
    step = 1
1715
 
 
1716
 
class CopyIndex2TestCase(CopyIndexTestCase): 
1717
 
    maxTuples = 2
1718
 
    start = 0
1719
 
    stop = -1
1720
 
    step = 1
1721
 
        
1722
 
class CopyIndex3TestCase(CopyIndexTestCase):
1723
 
    maxTuples = 3
1724
 
    start = 1
1725
 
    stop = 7
1726
 
    step = 1
1727
 
 
1728
 
class CopyIndex4TestCase(CopyIndexTestCase):
1729
 
    maxTuples = 4        
1730
 
    start = 0
1731
 
    stop = 6
1732
 
    step = 1
1733
 
 
1734
 
class CopyIndex5TestCase(CopyIndexTestCase):
1735
 
    maxTuples = 2
1736
 
    start = 3
1737
 
    stop = 7
1738
 
    step = 1
1739
 
 
1740
 
class CopyIndex6TestCase(CopyIndexTestCase):
1741
 
    maxTuples = 2
1742
 
    start = 3
1743
 
    stop = 6
1744
 
    step = 2
1745
 
 
1746
 
class CopyIndex7TestCase(CopyIndexTestCase):
1747
 
    start = 0
1748
 
    stop = 7
1749
 
    step = 10
1750
 
 
1751
 
class CopyIndex8TestCase(CopyIndexTestCase):
1752
 
    start = 6
1753
 
    stop = -1  # Negative values means starting from the end
1754
 
    step = 1
1755
 
 
1756
 
class CopyIndex9TestCase(CopyIndexTestCase):
1757
 
    start = 3
1758
 
    stop = 4
1759
 
    step = 1
1760
 
 
1761
 
class CopyIndex10TestCase(CopyIndexTestCase):
1762
 
    maxTuples = 1
1763
 
    start = 3
1764
 
    stop = 4
1765
 
    step = 2
1766
 
 
1767
 
class CopyIndex11TestCase(CopyIndexTestCase):
1768
 
    start = -3
1769
 
    stop = -1
1770
 
    step = 2
1771
 
 
1772
 
class CopyIndex12TestCase(CopyIndexTestCase):
1773
 
    start = -1   # Should point to the last element
1774
 
    stop = None  # None should mean the last element (including it)
1775
 
    step = 1
1776
 
 
1777
 
class TruncateTestCase(unittest.TestCase):
1778
 
 
1779
 
    def _test00_truncate(self):
1780
 
        """Checking EArray.truncate() method (truncating to 0 rows)"""
1781
 
 
1782
 
        if verbose:
1783
 
            print '\n', '-=' * 30
1784
 
            print "Running %s.test00_truncate..." % self.__class__.__name__
1785
 
 
1786
 
        # Create an instance of an HDF5 Table
1787
 
        file = tempfile.mktemp(".h5")
1788
 
        fileh = openFile(file, "w")
1789
 
 
1790
 
        # Create an EArray
1791
 
        arr = Atom(shape=(0, 2), dtype=Int16)
1792
 
        array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1793
 
        # Append two rows
1794
 
        array1.append(array([[456, 2],[3, 457]], type=Int16))
1795
 
 
1796
 
        if self.close:
1797
 
            fileh.close()
1798
 
            fileh = openFile(file, mode = "a")
1799
 
            array1 = fileh.root.array1
1800
 
            
1801
 
        # Truncate to 0 elements
1802
 
        size = array1.truncate(0)
1803
 
 
1804
 
        if self.close:
1805
 
            if verbose:
1806
 
                print "(closing file version)"
1807
 
            fileh.close()
1808
 
            fileh = openFile(file, mode = "r")
1809
 
            array1 = fileh.root.array1
1810
 
 
1811
 
        if verbose:
1812
 
            print "array1-->", array1.read()
1813
 
            print "size-->", size
1814
 
 
1815
 
        assert size == 0
1816
 
        assert allequal(array1[:], array([], type=Int16, shape=(0,2)))
1817
 
 
1818
 
    def test01_truncate(self):
1819
 
        """Checking EArray.truncate() method (truncating to 1 rows)"""
1820
 
 
1821
 
        if verbose:
1822
 
            print '\n', '-=' * 30
1823
 
            print "Running %s.test01_truncate..." % self.__class__.__name__
1824
 
 
1825
 
        # Create an instance of an HDF5 Table
1826
 
        file = tempfile.mktemp(".h5")
1827
 
        fileh = openFile(file, "w")
1828
 
 
1829
 
        # Create an EArray
1830
 
        arr = Atom(shape=(0, 2), dtype=Int16)
1831
 
        array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1832
 
        # Append two rows
1833
 
        array1.append(array([[456, 2],[3, 457]], type=Int16))
1834
 
 
1835
 
        if self.close:
1836
 
            fileh.close()
1837
 
            fileh = openFile(file, mode = "a")
1838
 
            array1 = fileh.root.array1
1839
 
            
1840
 
        # Truncate to 1 element
1841
 
        size = array1.truncate(1)
1842
 
 
1843
 
        if self.close:
1844
 
            if verbose:
1845
 
                print "(closing file version)"
1846
 
            fileh.close()
1847
 
            fileh = openFile(file, mode = "r")
1848
 
            array1 = fileh.root.array1
1849
 
 
1850
 
        if verbose:
1851
 
            print "array1-->", array1.read()
1852
 
            print "size-->", size
1853
 
 
1854
 
        assert size == 1
1855
 
        assert allequal(array1.read(), array([[456, 2]], type=Int16))
1856
 
 
1857
 
    def test02_truncate(self):
1858
 
        """Checking EArray.truncate() method (truncating to >= earray.nrows)"""
1859
 
 
1860
 
        if verbose:
1861
 
            print '\n', '-=' * 30
1862
 
            print "Running %s.test02_truncate..." % self.__class__.__name__
1863
 
 
1864
 
        # Create an instance of an HDF5 Table
1865
 
        file = tempfile.mktemp(".h5")
1866
 
        fileh = openFile(file, "w")
1867
 
 
1868
 
        # Create an EArray
1869
 
        arr = Atom(shape=(0, 2), dtype=Int16)
1870
 
        array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1871
 
        # Append two rows
1872
 
        array1.append(array([[456, 2],[3, 457]], type=Int16))
1873
 
 
1874
 
        if self.close:
1875
 
            fileh.close()
1876
 
            fileh = openFile(file, mode = "a")
1877
 
            array1 = fileh.root.array1
1878
 
            
1879
 
        # Truncate to 2 elements
1880
 
        size = array1.truncate(2)
1881
 
 
1882
 
        if self.close:
1883
 
            if verbose:
1884
 
                print "(closing file version)"
1885
 
            fileh.close()
1886
 
            fileh = openFile(file, mode = "r")
1887
 
            array1 = fileh.root.array1
1888
 
 
1889
 
        if verbose:
1890
 
            print "array1-->", array1.read()
1891
 
            print "size-->", size
1892
 
 
1893
 
        assert size == 2
1894
 
        assert allequal(array1.read(), array([[456, 2],[3, 457]], type=Int16))
1895
 
 
1896
 
    def test03_truncate(self):
1897
 
        """Checking EArray.truncate() method (truncating to > earray.nrows)"""
1898
 
 
1899
 
        if verbose:
1900
 
            print '\n', '-=' * 30
1901
 
            print "Running %s.test03_truncate..." % self.__class__.__name__
1902
 
 
1903
 
        # Create an instance of an HDF5 Table
1904
 
        file = tempfile.mktemp(".h5")
1905
 
        fileh = openFile(file, "w")
1906
 
 
1907
 
        # Create an EArray
1908
 
        arr = Atom(shape=(0, 2), dtype=Int16)
1909
 
        array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1910
 
        # Append two rows
1911
 
        array1.append(array([[456, 2],[3, 457]], type=Int16))
1912
 
 
1913
 
        if self.close:
1914
 
            fileh.close()
1915
 
            fileh = openFile(file, mode = "a")
1916
 
            array1 = fileh.root.array1
1917
 
            
1918
 
        # Truncate to 3 element
1919
 
        size = array1.truncate(3)
1920
 
 
1921
 
        if self.close:
1922
 
            if verbose:
1923
 
                print "(closing file version)"
1924
 
            fileh.close()
1925
 
            fileh = openFile(file, mode = "r")
1926
 
            array1 = fileh.root.array1
1927
 
 
1928
 
        if verbose:
1929
 
            print "array1-->", array1.read()
1930
 
            print "size-->", size
1931
 
 
1932
 
        assert size == 2
1933
 
        assert allequal(array1.read(), array([[456, 2],[3, 457]], type=Int16))
1934
 
 
1935
 
 
1936
 
class TruncateOpenTestCase(TruncateTestCase):
1937
 
    close = 0
1938
 
 
1939
 
class TruncateCloseTestCase(TruncateTestCase):
1940
 
    close = 1
1941
 
 
1942
 
 
1943
 
#----------------------------------------------------------------------
1944
 
 
1945
 
def suite():
1946
 
    theSuite = unittest.TestSuite()
1947
 
    global numeric
1948
 
    niter = 1
1949
 
 
1950
 
    #theSuite.addTest(unittest.makeSuite(BasicWriteTestCase))
1951
 
#     theSuite.addTest(unittest.makeSuite(TruncateOpenTestCase))
1952
 
#     theSuite.addTest(unittest.makeSuite(TruncateCloseTestCase))
1953
 
    for n in range(niter):
1954
 
        theSuite.addTest(unittest.makeSuite(BasicWriteTestCase))
1955
 
        theSuite.addTest(unittest.makeSuite(BasicWrite2TestCase))
1956
 
        theSuite.addTest(unittest.makeSuite(EmptyEArrayTestCase))
1957
 
        theSuite.addTest(unittest.makeSuite(EmptyEArray2TestCase))
1958
 
        theSuite.addTest(unittest.makeSuite(SlicesEArrayTestCase))
1959
 
        theSuite.addTest(unittest.makeSuite(Slices2EArrayTestCase))
1960
 
        theSuite.addTest(unittest.makeSuite(Slices3EArrayTestCase))
1961
 
        theSuite.addTest(unittest.makeSuite(Slices4EArrayTestCase))
1962
 
        theSuite.addTest(unittest.makeSuite(EllipsisEArrayTestCase))
1963
 
        theSuite.addTest(unittest.makeSuite(Ellipsis2EArrayTestCase))
1964
 
        theSuite.addTest(unittest.makeSuite(Ellipsis3EArrayTestCase))
1965
 
        theSuite.addTest(unittest.makeSuite(Ellipsis4EArrayTestCase))
1966
 
        theSuite.addTest(unittest.makeSuite(Ellipsis5EArrayTestCase))
1967
 
        theSuite.addTest(unittest.makeSuite(Ellipsis6EArrayTestCase))
1968
 
        theSuite.addTest(unittest.makeSuite(Ellipsis7EArrayTestCase))
1969
 
        theSuite.addTest(unittest.makeSuite(MD3WriteTestCase))
1970
 
        theSuite.addTest(unittest.makeSuite(MD5WriteTestCase))
1971
 
        theSuite.addTest(unittest.makeSuite(MD6WriteTestCase))
1972
 
        theSuite.addTest(unittest.makeSuite(MD7WriteTestCase))
1973
 
        theSuite.addTest(unittest.makeSuite(MD10WriteTestCase))
1974
 
        theSuite.addTest(unittest.makeSuite(ZlibComprTestCase))
1975
 
        theSuite.addTest(unittest.makeSuite(ZlibShuffleTestCase))
1976
 
        theSuite.addTest(unittest.makeSuite(LZOComprTestCase))
1977
 
        theSuite.addTest(unittest.makeSuite(LZOShuffleTestCase))
1978
 
        theSuite.addTest(unittest.makeSuite(UCLComprTestCase))
1979
 
        theSuite.addTest(unittest.makeSuite(UCLShuffleTestCase))
1980
 
        theSuite.addTest(unittest.makeSuite(FloatTypeTestCase))
1981
 
        theSuite.addTest(unittest.makeSuite(ComplexTypeTestCase))
1982
 
        theSuite.addTest(unittest.makeSuite(CharTypeTestCase))    
1983
 
        theSuite.addTest(unittest.makeSuite(CharType2TestCase))    
1984
 
        theSuite.addTest(unittest.makeSuite(CharTypeComprTestCase))
1985
 
        if numeric:
1986
 
            theSuite.addTest(unittest.makeSuite(Numeric1TestCase))
1987
 
            theSuite.addTest(unittest.makeSuite(Numeric2TestCase))
1988
 
            theSuite.addTest(unittest.makeSuite(NumericComprTestCase))
1989
 
        theSuite.addTest(unittest.makeSuite(OffsetStrideTestCase))
1990
 
        theSuite.addTest(unittest.makeSuite(Fletcher32TestCase))
1991
 
        theSuite.addTest(unittest.makeSuite(AllFiltersTestCase))
1992
 
        theSuite.addTest(unittest.makeSuite(CloseCopyTestCase))
1993
 
        theSuite.addTest(unittest.makeSuite(OpenCopyTestCase))
1994
 
        theSuite.addTest(unittest.makeSuite(CopyIndex1TestCase))
1995
 
        theSuite.addTest(unittest.makeSuite(CopyIndex2TestCase))
1996
 
        theSuite.addTest(unittest.makeSuite(CopyIndex3TestCase))
1997
 
        theSuite.addTest(unittest.makeSuite(CopyIndex4TestCase))
1998
 
        theSuite.addTest(unittest.makeSuite(CopyIndex5TestCase))
1999
 
        theSuite.addTest(unittest.makeSuite(CopyIndex6TestCase))
2000
 
        theSuite.addTest(unittest.makeSuite(CopyIndex7TestCase))
2001
 
        theSuite.addTest(unittest.makeSuite(CopyIndex8TestCase))
2002
 
        theSuite.addTest(unittest.makeSuite(CopyIndex9TestCase))
2003
 
        theSuite.addTest(unittest.makeSuite(CopyIndex10TestCase))
2004
 
        theSuite.addTest(unittest.makeSuite(CopyIndex11TestCase))
2005
 
        theSuite.addTest(unittest.makeSuite(CopyIndex12TestCase))
2006
 
        theSuite.addTest(unittest.makeSuite(TruncateOpenTestCase))
2007
 
        theSuite.addTest(unittest.makeSuite(TruncateCloseTestCase))
2008
 
 
2009
 
    return theSuite
2010
 
 
2011
 
 
2012
 
if __name__ == '__main__':
2013
 
    unittest.main( defaultTest='suite' )
2014
 
 
2015
 
## Local Variables:
2016
 
## mode: python
2017
 
## py-indent-offset: 4
2018
 
## tab-width: 4
2019
 
## End:
2020