1
# Eh! python!, We are going to include isolatin characters here
2
# -*- coding: latin-1 -*-
10
from numarray import strings
25
from common import verbose, allequal, cleanup, heavy
26
# To delete the internal attributes automagically
27
unittest.TestCase.tearDown = cleanup
29
class BasicTestCase(unittest.TestCase):
41
complib = "zlib" # Default compression library
44
reopen = 1 # Tells whether the file has to be reopened on each test or not
48
# Create an instance of an HDF5 Table
49
self.file = tempfile.mktemp(".h5")
50
self.fileh = openFile(self.file, "w")
51
self.rootgroup = self.fileh.root
57
def populateFile(self):
58
group = self.rootgroup
59
if self.flavor == "numarray":
61
elif self.flavor == "numeric":
63
elif self.flavor == "numpy":
65
if self.type == "CharType":
66
atom = StringAtom(shape=self.shape, length=self.length,
69
atom = Atom(dtype=self.type, shape=self.shape, flavor=flavor)
70
title = self.__class__.__name__
71
filters = Filters(complevel = self.compress,
72
complib = self.complib,
73
shuffle = self.shuffle,
74
fletcher32 = self.fletcher32)
75
earray = self.fileh.createEArray(group, 'earray1', atom, title,
80
self.rowshape = list(earray.shape)
81
self.objsize = self.length
82
for i in self.rowshape:
85
self.extdim = earray.extdim
86
self.objsize *= self.chunksize
87
self.rowshape[earray.extdim] = self.chunksize
88
if str(self.type) == "CharType":
89
object = strings.array("a"*self.objsize, shape=self.rowshape,
90
itemsize=earray.itemsize)
92
object = arange(self.objsize, shape=self.rowshape,
94
if self.flavor == "numpy":
95
object = numpy.asarray(object)
96
elif self.flavor == "numeric":
97
object = Numeric.asarray(object)
99
if self.flavor == "numarray":
100
print "Object to append -->", object.info()
102
print "Object to append -->", repr(object)
103
for i in range(self.nappends):
104
if str(self.type) == "CharType":
105
earray.append(object)
106
elif self.flavor in ["numarray","numpy"]:
107
earray.append(object*i)
110
# For Numeric arrays, we still have to undo the type upgrade
111
earray.append(object.astype(typecode[earray.type]))
118
#----------------------------------------
120
def test01_iterEArray(self):
121
"""Checking enlargeable array iterator"""
123
rootgroup = self.rootgroup
125
print '\n', '-=' * 30
126
print "Running %s.test01_iterEArray..." % self.__class__.__name__
128
# Create an instance of an HDF5 Table
130
self.fileh = openFile(self.file, "r")
131
earray = self.fileh.getNode("/earray1")
133
# Choose a small value for buffer size
134
earray._v_maxTuples = 3
136
print "EArray descr:", repr(earray)
137
print "shape of read array ==>", earray.shape
138
print "reopening?:", self.reopen
140
# Build the array to do comparisons
141
if str(self.type) == "CharType":
142
object_ = strings.array("a"*self.objsize, shape=self.rowshape,
143
itemsize=earray.itemsize)
145
object_ = arange(self.objsize, shape=self.rowshape,
147
object_.swapaxes(earray.extdim, 0)
148
if self.flavor == "numpy":
149
object_ = numpy.asarray(object_)
150
elif self.flavor == "numeric":
151
object_ = Numeric.asarray(object_)
155
chunk = int(earray.nrow % self.chunksize)
157
if str(self.type) == "CharType":
160
object__ = object_ * (earray.nrow / self.chunksize)
161
if self.flavor == "numeric":
162
object__ = object__.astype(typecode[earray.type])
163
object = object__[chunk]
164
# The next adds much more verbosity
166
print "number of row ==>", earray.nrow
167
if hasattr(object, "shape"):
168
print "shape should look as:", object.shape
169
print "row in earray ==>", repr(row)
170
print "Should look like ==>", repr(object)
172
assert self.nappends*self.chunksize == earray.nrows
173
assert allequal(row, object, self.flavor)
174
if hasattr(row, "shape"):
175
assert len(row.shape) == len(self.shape) - 1
178
assert len(self.shape) == 1
181
if self.compress <> earray.filters.complevel and verbose:
182
print "Error in compress. Class:", self.__class__.__name__
183
print "self, earray:", self.compress, earray.filters.complevel
184
tinfo = whichLibVersion(self.complib)
186
self.complib = "zlib"
187
assert earray.filters.complib == self.complib
188
assert earray.filters.complevel == self.compress
189
if self.shuffle <> earray.filters.shuffle and verbose:
190
print "Error in shuffle. Class:", self.__class__.__name__
191
print "self, earray:", self.shuffle, earray.filters.shuffle
192
assert self.shuffle == earray.filters.shuffle
193
if self.fletcher32 <> earray.filters.fletcher32 and verbose:
194
print "Error in fletcher32. Class:", self.__class__.__name__
195
print "self, earray:", self.fletcher32, earray.filters.fletcher32
196
assert self.fletcher32 == earray.filters.fletcher32
198
def test02_sssEArray(self):
199
"""Checking enlargeable array iterator with (start, stop, step)"""
201
rootgroup = self.rootgroup
203
print '\n', '-=' * 30
204
print "Running %s.test02_sssEArray..." % self.__class__.__name__
206
# Create an instance of an HDF5 Table
208
self.fileh = openFile(self.file, "r")
209
earray = self.fileh.getNode("/earray1")
211
# Choose a small value for buffer size
212
earray._v_maxTuples = 3
214
print "EArray descr:", repr(earray)
215
print "shape of read array ==>", earray.shape
216
print "reopening?:", self.reopen
218
# Build the array to do comparisons
219
if str(self.type) == "CharType":
220
object_ = strings.array("a"*self.objsize, shape=self.rowshape,
221
itemsize=earray.itemsize)
223
object_ = arange(self.objsize, shape=self.rowshape,
225
object_.swapaxes(earray.extdim, 0)
226
if self.flavor == "numpy":
227
object_ = numpy.asarray(object_)
228
elif self.flavor == "numeric":
229
object_ = Numeric.asarray(object_)
232
for row in earray.iterrows(start=self.start, stop=self.stop, step=self.step):
233
if self.chunksize == 1:
236
index = int(earray.nrow % self.chunksize)
237
if str(self.type) == "CharType":
240
object__ = object_ * (earray.nrow / self.chunksize)
241
if self.flavor == "numeric":
242
object__ = object__.astype(typecode[earray.type])
243
object = object__[index]
244
# The next adds much more verbosity
246
print "number of row ==>", earray.nrow
247
if hasattr(object, "shape"):
248
print "shape should look as:", object.shape
249
print "row in earray ==>", repr(row)
250
print "Should look like ==>", repr(object)
252
assert self.nappends*self.chunksize == earray.nrows
253
assert allequal(row, object, self.flavor)
254
if hasattr(row, "shape"):
255
assert len(row.shape) == len(self.shape) - 1
258
assert len(self.shape) == 1
260
def test03_readEArray(self):
261
"""Checking read() of enlargeable arrays"""
263
rootgroup = self.rootgroup
265
print '\n', '-=' * 30
266
print "Running %s.test03_readEArray..." % self.__class__.__name__
268
# This conversion made just in case indices are numpy scalars
269
if self.start is not None: self.start = long(self.start)
270
if self.stop is not None: self.stop = long(self.stop)
271
if self.step is not None: self.step = long(self.step)
273
# Create an instance of an HDF5 Table
275
self.fileh = openFile(self.file, "r")
276
earray = self.fileh.getNode("/earray1")
278
# Choose a small value for buffer size
279
earray._v_maxTuples = 3
281
print "EArray descr:", repr(earray)
282
print "shape of read array ==>", earray.shape
283
print "reopening?:", self.reopen
285
# Build the array to do comparisons
286
if str(self.type) == "CharType":
287
object_ = strings.array("a"*self.objsize, shape=self.rowshape,
288
itemsize=earray.itemsize)
290
object_ = arange(self.objsize, shape=self.rowshape,
292
object_.swapaxes(earray.extdim, 0)
293
if self.flavor == "numpy":
294
object_ = numpy.asarray(object_)
295
elif self.flavor == "numeric":
296
object_ = Numeric.asarray(object_)
298
rowshape = self.rowshape
299
rowshape[self.extdim] *= self.nappends
300
if str(self.type) == "CharType":
301
object__ = strings.array(None, shape=rowshape,
302
itemsize=earray.itemsize)
304
object__ = array(None, shape = rowshape, type=self.type)
305
object__.swapaxes(0, self.extdim)
306
if self.flavor == "numpy":
307
object__ = numpy.asarray(object__)
308
elif self.flavor == "numeric":
309
object__ = Numeric.asarray(object__)
311
for i in range(self.nappends):
312
j = i * self.chunksize
313
if str(self.type) == "CharType":
314
object__[j:j+self.chunksize] = object_
316
if self.flavor in ["numarray", "numpy"]:
317
object__[j:j+self.chunksize] = object_ * i
319
object__[j:j+self.chunksize] = (object_ * i).astype(typecode[earray.type])
323
# stop == None means read only the element designed by start
324
# (in read() contexts)
325
if self.stop == None:
326
if self.start == -1: # corner case
329
stop = self.start + 1
330
# Protection against number of elements less than existing
331
#if rowshape[self.extdim] < self.stop or self.stop == 0:
332
if rowshape[self.extdim] < stop:
333
# self.stop == 0 means last row only in read()
334
# and not in [::] slicing notation
335
stop = rowshape[self.extdim]
336
# do a copy() in order to ensure that len(object._data)
337
# actually do a measure of its length
338
object = object__[self.start:stop:self.step].copy()
339
# Swap the axes again to have normal ordering
340
if self.flavor == "numarray":
341
object.swapaxes(0, self.extdim)
342
elif self.flavor == "numpy":
343
object = object.swapaxes(0, self.extdim)
344
elif self.flavor == "numeric":
345
object = Numeric.swapaxes(object, 0, self.extdim)
347
object = array(None, shape = self.shape, type=self.type)
348
if self.flavor == "numpy":
349
object = numpy.asarray(object)
350
elif self.flavor == "numeric":
351
object = Numeric.asarray(object)
355
row = earray.read(self.start,self.stop,self.step)
357
row = array(None, shape = self.shape, type=self.type)
358
if self.flavor == "numpy":
359
row = numpy.asarray(row)
360
elif self.flavor == "numeric":
361
row = Numeric.asarray(row)
364
if hasattr(object, "shape"):
365
print "shape should look as:", object.shape
366
print "Object read ==>", repr(row)
367
print "Should look like ==>", repr(object)
369
assert self.nappends*self.chunksize == earray.nrows
370
assert allequal(row, object, self.flavor)
371
if hasattr(row, "shape"):
372
assert len(row.shape) == len(self.shape)
375
assert len(self.shape) == 1
377
def test04_getitemEArray(self):
378
"""Checking enlargeable array __getitem__ special method"""
380
rootgroup = self.rootgroup
382
print '\n', '-=' * 30
383
print "Running %s.test04_getitemEArray..." % self.__class__.__name__
385
if not hasattr(self, "slices"):
386
# If there is not a slices attribute, create it
387
# This conversion made just in case indices are numpy scalars
388
if self.start is not None: self.start = long(self.start)
389
if self.stop is not None: self.stop = long(self.stop)
390
if self.step is not None: self.step = long(self.step)
391
self.slices = (slice(self.start, self.stop, self.step),)
393
# Create an instance of an HDF5 Table
395
self.fileh = openFile(self.file, "r")
396
earray = self.fileh.getNode("/earray1")
398
# Choose a small value for buffer size
399
#earray._v_maxTuples = 3 # this does not really changes the chunksize
401
print "EArray descr:", repr(earray)
402
print "shape of read array ==>", earray.shape
403
print "reopening?:", self.reopen
405
# Build the array to do comparisons
406
if str(self.type) == "CharType":
407
object_ = strings.array("a"*self.objsize, shape=self.rowshape,
408
itemsize=earray.itemsize)
409
# Additional conversion for the numpy case
410
if self.flavor == "numpy":
411
object_ = numpy.asarray(object_)
413
object_ = arange(self.objsize, shape=self.rowshape,
415
object_.swapaxes(earray.extdim, 0)
417
rowshape = self.rowshape
418
rowshape[self.extdim] *= self.nappends
419
if str(self.type) == "CharType":
420
object__ = strings.array(None, shape=rowshape,
421
itemsize=earray.itemsize)
422
# Additional conversion for the numpy case
423
if self.flavor == "numpy":
424
object__ = numpy.asarray(object__)
426
object__ = array(None, shape = rowshape, type=self.type)
427
object__.swapaxes(0, self.extdim)
429
for i in range(self.nappends):
430
j = i * self.chunksize
431
if str(self.type) == "CharType":
432
object__[j:j+self.chunksize] = object_
434
object__[j:j+self.chunksize] = object_ * i
438
# Swap the axes again to have normal ordering
439
object__.swapaxes(0, self.extdim)
440
# do a copy() in order to ensure that len(object._data)
441
# actually do a measure of its length
442
object = object__.__getitem__(self.slices).copy()
444
object = array(None, shape = self.shape, type=self.type)
446
if self.flavor == "numpy":
447
# Convert the object to NumPy
448
object = numpy.asarray(object)
449
elif self.flavor == "numeric":
450
# Convert the object to Numeric
451
object = Numeric.asarray(object)
454
row = earray.__getitem__(self.slices)
456
row = earray.__getitem__(self.slices)
459
row = array(None, shape = self.shape, type=self.type)
460
if self.flavor == "numpy":
461
row = numpy.asarray(row)
462
elif self.flavor == "numeric":
463
row = Numeric.asarray(row)
466
print "Object read:\n", repr(row) #, row.info()
467
print "Should look like:\n", repr(object) #, row.info()
468
if hasattr(object, "shape"):
469
print "Original object shape:", self.shape
470
print "Shape read:", row.shape
471
print "shape should look as:", object.shape
473
assert self.nappends*self.chunksize == earray.nrows
474
assert allequal(row, object, self.flavor)
475
if not hasattr(row, "shape"):
477
assert len(self.shape) == 1
480
def test05_setitemEArray(self):
481
"""Checking enlargeable array __setitem__ special method"""
483
rootgroup = self.rootgroup
484
if self.__class__.__name__ == "Ellipsis6EArrayTestCase":
485
# We have a problem with test design here, but I think
486
# it is not worth the effort to solve it
490
print '\n', '-=' * 30
491
print "Running %s.test05_setitemEArray..." % self.__class__.__name__
493
if not hasattr(self, "slices"):
494
# If there is not a slices attribute, create it
495
# This conversion made just in case indices are numpy scalars
496
if self.start is not None: self.start = long(self.start)
497
if self.stop is not None: self.stop = long(self.stop)
498
if self.step is not None: self.step = long(self.step)
499
self.slices = (slice(self.start, self.stop, self.step),)
501
# Create an instance of an HDF5 Table
503
self.fileh = openFile(self.file, "a")
504
earray = self.fileh.getNode("/earray1")
506
# Choose a small value for buffer size
507
#earray._v_maxTuples = 3 # this does not really changes the chunksize
509
print "EArray descr:", repr(earray)
510
print "shape of read array ==>", earray.shape
511
print "reopening?:", self.reopen
513
# Build the array to do comparisons
514
if str(self.type) == "CharType":
515
object_ = strings.array("a"*self.objsize, shape=self.rowshape,
516
itemsize=earray.itemsize)
517
# Additional conversion for the numpy case
518
if self.flavor == "numpy":
519
object_ = numpy.asarray(object_)
521
object_ = arange(self.objsize, shape=self.rowshape,
523
object_.swapaxes(earray.extdim, 0)
526
rowshape = self.rowshape
527
rowshape[self.extdim] *= self.nappends
528
if str(self.type) == "CharType":
529
object__ = strings.array(None, shape=rowshape,
530
itemsize=earray.itemsize)
531
# Additional conversion for the numpy case
532
if self.flavor == "numpy":
533
object__ = numpy.asarray(object__)
535
object__ = array(None, shape = rowshape, type=self.type)
536
object__.swapaxes(0, self.extdim)
538
for i in range(self.nappends):
539
j = i * self.chunksize
540
if str(self.type) == "CharType":
541
object__[j:j+self.chunksize] = object_
543
object__[j:j+self.chunksize] = object_ * i
545
#earray[j:j+self.chunksize] = object_ * i
546
#earray[self.slices] = 1
550
# Swap the axes again to have normal ordering
551
object__.swapaxes(0, self.extdim)
552
# do a copy() in order to ensure that len(object._data)
553
# actually do a measure of its length
554
object = object__.__getitem__(self.slices).copy()
556
object = array(None, shape = self.shape, type=self.type)
558
if self.flavor == "numpy":
559
object = numpy.asarray(object)
560
elif self.flavor == "numeric":
561
object = Numeric.asarray(object)
563
if str(self.type) == "CharType":
564
if hasattr(self, "wslice"):
565
# These sentences should be equivalent
566
#object[self.wslize] = object[self.wslice].pad("xXx")
567
#earray[self.wslice] = earray[self.wslice].pad("xXx")
568
object[self.wslize] = "xXx"
569
earray[self.wslice] = "xXx"
570
elif sum(object[self.slices].shape) <> 0 :
571
#object[:] = object.pad("xXx")
573
if self.flavor == "numpy":
575
earray[self.slices] = object
577
if object.size() > 0:
578
earray[self.slices] = object
580
if hasattr(self, "wslice"):
581
object[self.wslice] = object[self.wslice] * 2 + 3
582
earray[self.wslice] = earray[self.wslice] * 2 + 3
583
elif sum(object[self.slices].shape) <> 0:
584
object = object * 2 + 3
585
if reduce(lambda x,y:x*y, object.shape) > 0:
586
earray[self.slices] = earray[self.slices] * 2 + 3
588
row = earray.__getitem__(self.slices)
590
row = earray.__getitem__(self.slices)
593
row = array(None, shape = self.shape, type=self.type)
594
if self.flavor == "numpy":
595
row = numpy.asarray(row)
596
elif self.flavor == "numeric":
597
row = Numeric.asarray(self.shape)
600
print "Object read:\n", repr(row) #, row.info()
601
print "Should look like:\n", repr(object) #, row.info()
602
if hasattr(object, "shape"):
603
print "Original object shape:", self.shape
604
print "Shape read:", row.shape
605
print "shape should look as:", object.shape
607
assert self.nappends*self.chunksize == earray.nrows
608
assert allequal(row, object, self.flavor)
609
if not hasattr(row, "shape"):
611
assert len(self.shape) == 1
614
class BasicWriteTestCase(BasicTestCase):
620
#wslice = slice(1,nappends,2)
621
wslice = 1 # single element case
623
class BasicWrite2TestCase(BasicTestCase):
629
wslice = slice(chunksize-2,nappends,2) # range of elements
630
reopen = 0 # This case does not reopen files
632
class EmptyEArrayTestCase(BasicTestCase):
641
class NP_EmptyEArrayTestCase(BasicTestCase):
647
start = numpy.uint8(0)
648
stop = numpy.uint32(10)
649
step = numpy.int64(1)
651
class EmptyEArray2TestCase(BasicTestCase):
659
reopen = 0 # This case does not reopen files
661
class SlicesEArrayTestCase(BasicTestCase):
668
slices = (slice(1,2,1), slice(1,3,1))
670
class Slices2EArrayTestCase(BasicTestCase):
677
slices = (slice(1,2,1), slice(None, None, None), slice(1,4,2))
679
class EllipsisEArrayTestCase(BasicTestCase):
684
#slices = (slice(1,2,1), Ellipsis)
685
slices = (Ellipsis, slice(1,2,1))
687
class Ellipsis2EArrayTestCase(BasicTestCase):
692
slices = (slice(1,2,1), Ellipsis, slice(1,4,2))
694
class Slices3EArrayTestCase(BasicTestCase):
695
compress = 1 # To show the chunks id DEBUG is on
701
slices = (slice(1, 2, 1), slice(0, None, None), slice(1,4,2)) # Don't work
702
#slices = (slice(None, None, None), slice(0, None, None), slice(1,4,1)) # W
703
#slices = (slice(None, None, None), slice(None, None, None), slice(1,4,2)) # N
704
#slices = (slice(1,2,1), slice(None, None, None), slice(1,4,2)) # N
705
# Disable the failing test temporarily with a working test case
706
slices = (slice(1,2,1), slice(1, 4, None), slice(1,4,2)) # Y
707
#slices = (slice(1,2,1), slice(0, 4, None), slice(1,4,1)) # Y
708
slices = (slice(1,2,1), slice(0, 4, None), slice(1,4,2)) # N
709
#slices = (slice(1,2,1), slice(0, 4, None), slice(1,4,2), slice(0,100,1)) # N
711
class Slices4EArrayTestCase(BasicTestCase):
713
shape = (2, 3, 4, 0, 5, 6)
716
slices = (slice(1, 2, 1), slice(0, None, None), slice(1,4,2),
717
slice(0,4,2), slice(3,5,2), slice(2,7,1))
719
class Ellipsis3EArrayTestCase(BasicTestCase):
724
slices = (Ellipsis, slice(0, 4, None), slice(1,4,2))
725
slices = (slice(1,2,1), slice(0, 4, None), slice(1,4,2), Ellipsis)
727
class Ellipsis4EArrayTestCase(BasicTestCase):
732
slices = (Ellipsis, slice(0, 4, None), slice(1,4,2))
733
slices = (slice(1,2,1), Ellipsis, slice(1,4,2))
735
class Ellipsis5EArrayTestCase(BasicTestCase):
740
slices = (slice(1,2,1), slice(0, 4, None), Ellipsis)
742
class Ellipsis6EArrayTestCase(BasicTestCase):
747
# The next slices gives problems with setting values (test05)
748
# This is a problem on the test design, not the Array.__setitem__
750
slices = (slice(1,2,1), slice(0, 4, None), 2, Ellipsis)
752
class Ellipsis7EArrayTestCase(BasicTestCase):
757
slices = (slice(1,2,1), slice(0, 4, None), slice(2,3), Ellipsis)
759
class MD3WriteTestCase(BasicTestCase):
765
class MD5WriteTestCase(BasicTestCase):
767
shape = (2, 0, 3, 4, 5) # ok
768
#shape = (1, 1, 0, 1) # Minimum shape that shows problems with HDF5 1.6.1
769
#shape = (2, 3, 0, 4, 5) # Floating point exception (HDF5 1.6.1)
770
#shape = (2, 3, 3, 0, 5, 6) # Segmentation fault (HDF5 1.6.1)
777
class MD6WriteTestCase(BasicTestCase):
779
shape = (2, 3, 3, 0, 5, 6)
786
class NP_MD6WriteTestCase(BasicTestCase):
787
"Testing NumPy scalars as indexes"
789
shape = (2, 3, 3, 0, 5, 6)
793
start = numpy.int8(1)
794
stop = numpy.int16(10)
795
step = numpy.int32(3)
797
class MD6WriteTestCase__(BasicTestCase):
806
class MD7WriteTestCase(BasicTestCase):
808
shape = (2, 3, 3, 4, 5, 0, 3)
815
class MD10WriteTestCase(BasicTestCase):
817
shape = (1, 2, 3, 4, 5, 5, 4, 3, 2, 0)
824
class NP_MD10WriteTestCase(BasicTestCase):
826
shape = (1, 2, 3, 4, 5, 5, 4, 3, 2, 0)
830
start = numpy.int8(-1)
831
stop = numpy.int64(-1)
832
step = numpy.uint8(10)
834
class ZlibComprTestCase(BasicTestCase):
838
#stop = 0 # means last row
839
stop = None # means last row from 0.8 on
842
class ZlibShuffleTestCase(BasicTestCase):
846
# case start < stop , i.e. no rows read
851
class LZOComprTestCase(BasicTestCase):
860
class LZOShuffleTestCase(BasicTestCase):
870
class BZIP2ComprTestCase(BasicTestCase):
879
class BZIP2ShuffleTestCase(BasicTestCase):
889
class Fletcher32TestCase(BasicTestCase):
898
class AllFiltersTestCase(BasicTestCase):
914
class FloatTypeTestCase(BasicTestCase):
923
class ComplexTypeTestCase(BasicTestCase):
932
class CharTypeTestCase(BasicTestCase):
942
slices = (slice(0,1),slice(1,2))
944
class CharType2TestCase(BasicTestCase):
955
class CharTypeComprTestCase(BasicTestCase):
959
#shape = (20,0,10,20)
961
#shuffle = 1 # this shouldn't do nothing on chars
968
class _Numpy1TestCase(BasicTestCase):
969
# Setting flavor to Numeric here gives some problems due,
970
# most probably to test implementation, not library code
982
class Numpy2TestCase(BasicTestCase):
984
# type = Float32 gives some problems on tests. It is *not* a
985
# problem with Array.__setitem__(), just with test design
997
class NumpyComprTestCase(BasicTestCase):
1010
class CharTypeNumpyTestCase(BasicTestCase):
1021
slices = (slice(0,1),slice(1,2))
1023
class CharType2NumpyTestCase(BasicTestCase):
1035
class CharTypeComprNumpyTestCase(BasicTestCase):
1040
#shape = (20,0,10,20)
1042
#shuffle = 1 # this shouldn't do nothing on chars
1049
class Numeric1TestCase(BasicTestCase):
1050
# Setting flavor to Numeric here gives some problems due,
1051
# most probably, to test implementation, not library code
1063
class Numeric2TestCase(BasicTestCase):
1065
# type = Float32 gives some problems on tests. It is *not* a
1066
# problem with Array.__setitem__(), just with test design
1078
class NumericComprTestCase(BasicTestCase):
1091
# It remains a test of Numeric char types, but the code is getting too messy
1093
class OffsetStrideTestCase(unittest.TestCase):
1096
complib = "zlib" # Default compression library
1100
# Create an instance of an HDF5 Table
1101
self.file = tempfile.mktemp(".h5")
1102
self.fileh = openFile(self.file, self.mode)
1103
self.rootgroup = self.fileh.root
1107
os.remove(self.file)
1110
#----------------------------------------
1112
def test01a_String(self):
1113
"""Checking earray with offseted numarray strings appends"""
1115
root = self.rootgroup
1117
print '\n', '-=' * 30
1118
print "Running %s.test01a_StringAtom..." % self.__class__.__name__
1120
# Create an string atom
1121
earray = self.fileh.createEArray(root, 'strings',
1122
StringAtom(length=3,
1125
a=strings.array([[["a","b"],["123", "45"],["45", "123"]]], itemsize=3)
1126
earray.append(a[:,1:])
1127
a=strings.array([[["s", "a"],["ab", "f"],["s", "abc"],["abc", "f"]]])
1128
earray.append(a[:,2:])
1130
# Read all the rows:
1133
print "Object read:", row
1134
print "Nrows in", earray._v_pathname, ":", earray.nrows
1135
print "Second row in earray ==>", row[1].tolist()
1137
assert earray.nrows == 2
1138
assert row[0].tolist() == [["123", "45"],["45", "123"]]
1139
assert row[1].tolist() == [["s", "abc"],["abc", "f"]]
1140
assert len(row[0]) == 2
1141
assert len(row[1]) == 2
1143
def test01b_String(self):
1144
"""Checking earray with strided numarray strings appends"""
1146
root = self.rootgroup
1148
print '\n', '-=' * 30
1149
print "Running %s.test01b_StringAtom..." % self.__class__.__name__
1151
# Create an string atom
1152
earray = self.fileh.createEArray(root, 'strings',
1153
StringAtom(length=3,
1156
a=strings.array([[["a","b"],["123", "45"],["45", "123"]]], itemsize=3)
1157
earray.append(a[:,::2])
1158
a=strings.array([[["s", "a"],["ab", "f"],["s", "abc"],["abc", "f"]]])
1159
earray.append(a[:,::2])
1161
# Read all the rows:
1164
print "Object read:", row
1165
print "Nrows in", earray._v_pathname, ":", earray.nrows
1166
print "Second row in earray ==>", row[1].tolist()
1168
assert earray.nrows == 2
1169
assert row[0].tolist() == [["a","b"],["45", "123"]]
1170
assert row[1].tolist() == [["s", "a"],["s", "abc"]]
1171
assert len(row[0]) == 2
1172
assert len(row[1]) == 2
1174
def test02a_int(self):
1175
"""Checking earray with offseted numarray ints appends"""
1177
root = self.rootgroup
1179
print '\n', '-=' * 30
1180
print "Running %s.test02a_int..." % self.__class__.__name__
1182
# Create an string atom
1183
earray = self.fileh.createEArray(root, 'EAtom',
1184
Int32Atom(shape=(0,3)),
1186
a=array([(0,0,0), (1,0,3), (1,1,1), (0,0,0)], type=Int32)
1187
earray.append(a[2:]) # Create an offset
1188
a=array([(1,1,1), (-1,0,0)], type=Int32)
1189
earray.append(a[1:]) # Create an offset
1191
# Read all the rows:
1194
print "Object read:", row
1195
print "Nrows in", earray._v_pathname, ":", earray.nrows
1196
print "Third row in vlarray ==>", row[2]
1198
assert earray.nrows == 3
1199
assert allequal(row[0], array([1,1,1], type=Int32))
1200
assert allequal(row[1], array([0,0,0], type=Int32))
1201
assert allequal(row[2], array([-1,0,0], type=Int32))
1203
def test02b_int(self):
1204
"""Checking earray with strided numarray ints appends"""
1206
root = self.rootgroup
1208
print '\n', '-=' * 30
1209
print "Running %s.test02b_int..." % self.__class__.__name__
1211
# Create an string atom
1212
earray = self.fileh.createEArray(root, 'EAtom',
1213
Int32Atom(shape=(0,3)),
1215
a=array([(0,0,0), (1,0,3), (1,1,1), (3,3,3)], type=Int32)
1216
earray.append(a[::3]) # Create an offset
1217
a=array([(1,1,1), (-1,0,0)], type=Int32)
1218
earray.append(a[::2]) # Create an offset
1220
# Read all the rows:
1223
print "Object read:", row
1224
print "Nrows in", earray._v_pathname, ":", earray.nrows
1225
print "Third row in vlarray ==>", row[2]
1227
assert earray.nrows == 3
1228
assert allequal(row[0], array([0,0,0], type=Int32))
1229
assert allequal(row[1], array([3,3,3], type=Int32))
1230
assert allequal(row[2], array([1,1,1], type=Int32))
1232
class CopyTestCase(unittest.TestCase):
1234
def test01_copy(self):
1235
"""Checking EArray.copy() method """
1238
print '\n', '-=' * 30
1239
print "Running %s.test01_copy..." % self.__class__.__name__
1241
# Create an instance of an HDF5 Table
1242
file = tempfile.mktemp(".h5")
1243
fileh = openFile(file, "w")
1246
arr = Atom(shape=(0, 2), dtype=Int16)
1247
array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1248
array1.append(array([[456, 2],[3, 457]], type=Int16))
1252
print "(closing file version)"
1254
fileh = openFile(file, mode = "a")
1255
array1 = fileh.root.array1
1257
# Copy it to another location
1258
array2 = array1.copy('/', 'array2')
1262
print "(closing file version)"
1264
fileh = openFile(file, mode = "r")
1265
array1 = fileh.root.array1
1266
array2 = fileh.root.array2
1269
print "array1-->", array1.read()
1270
print "array2-->", array2.read()
1271
#print "dirs-->", dir(array1), dir(array2)
1272
print "attrs array1-->", repr(array1.attrs)
1273
print "attrs array2-->", repr(array2.attrs)
1275
# Check that all the elements are equal
1276
assert allequal(array1.read(), array2.read())
1278
# Assert other properties in array
1279
assert array1.nrows == array2.nrows
1280
assert array1.shape == array2.shape
1281
assert array1.extdim == array2.extdim
1282
assert array1.flavor == array2.flavor
1283
assert array1.type == array2.type
1284
assert array1.itemsize == array2.itemsize
1285
assert array1.title == array2.title
1286
assert str(array1.atom) == str(array2.atom)
1292
def test02_copy(self):
1293
"""Checking EArray.copy() method (where specified)"""
1296
print '\n', '-=' * 30
1297
print "Running %s.test02_copy..." % self.__class__.__name__
1299
# Create an instance of an HDF5 Table
1300
file = tempfile.mktemp(".h5")
1301
fileh = openFile(file, "w")
1304
arr = Atom(shape=(0, 2), dtype=Int16)
1305
array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1306
array1.append(array([[456, 2],[3, 457]], type=Int16))
1310
print "(closing file version)"
1312
fileh = openFile(file, mode = "a")
1313
array1 = fileh.root.array1
1315
# Copy to another location
1316
group1 = fileh.createGroup("/", "group1")
1317
array2 = array1.copy(group1, 'array2')
1321
print "(closing file version)"
1323
fileh = openFile(file, mode = "r")
1324
array1 = fileh.root.array1
1325
array2 = fileh.root.group1.array2
1328
print "array1-->", array1.read()
1329
print "array2-->", array2.read()
1330
#print "dirs-->", dir(array1), dir(array2)
1331
print "attrs array1-->", repr(array1.attrs)
1332
print "attrs array2-->", repr(array2.attrs)
1334
# Check that all the elements are equal
1335
assert allequal(array1.read(), array2.read())
1337
# Assert other properties in array
1338
assert array1.nrows == array2.nrows
1339
assert array1.shape == array2.shape
1340
assert array1.extdim == array2.extdim
1341
assert array1.flavor == array2.flavor
1342
assert array1.type == array2.type
1343
assert array1.itemsize == array2.itemsize
1344
assert array1.title == array2.title
1345
assert str(array1.atom) == str(array2.atom)
1351
def test03_copy(self):
1352
"""Checking EArray.copy() method (NumPy flavor)"""
1355
print '\n', '-=' * 30
1356
print "Running %s.test03_copy..." % self.__class__.__name__
1358
# Create an instance of an HDF5 Table
1359
file = tempfile.mktemp(".h5")
1360
fileh = openFile(file, "w")
1363
arr = Atom(shape=(0, 2), dtype=Int16, flavor="numpy")
1365
arr = Atom(shape=(0, 2), dtype=Int16)
1367
array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1368
array1.append(array([[456, 2],[3, 457]], type=Int16))
1372
print "(closing file version)"
1374
fileh = openFile(file, mode = "a")
1375
array1 = fileh.root.array1
1377
# Copy to another location
1378
array2 = array1.copy('/', 'array2')
1382
print "(closing file version)"
1384
fileh = openFile(file, mode = "r")
1385
array1 = fileh.root.array1
1386
array2 = fileh.root.array2
1389
print "attrs array1-->", repr(array1.attrs)
1390
print "attrs array2-->", repr(array2.attrs)
1392
# Assert other properties in array
1393
assert array1.nrows == array2.nrows
1394
assert array1.shape == array2.shape
1395
assert array1.extdim == array2.extdim
1396
assert array1.flavor == array2.flavor # Very important here!
1397
assert array1.type == array2.type
1398
assert array1.itemsize == array2.itemsize
1399
assert array1.title == array2.title
1400
assert str(array1.atom) == str(array2.atom)
1406
def test03a_copy(self):
1407
"""Checking EArray.copy() method (Numeric flavor)"""
1410
print '\n', '-=' * 30
1411
print "Running %s.test03a_copy..." % self.__class__.__name__
1413
# Create an instance of an HDF5 Table
1414
file = tempfile.mktemp(".h5")
1415
fileh = openFile(file, "w")
1418
arr = Atom(shape=(0, 2), dtype=Int16, flavor="numeric")
1420
arr = Atom(shape=(0, 2), dtype=Int16)
1422
array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1423
array1.append(array([[456, 2],[3, 457]], type=Int16))
1427
print "(closing file version)"
1429
fileh = openFile(file, mode = "a")
1430
array1 = fileh.root.array1
1432
# Copy to another location
1433
array2 = array1.copy('/', 'array2')
1437
print "(closing file version)"
1439
fileh = openFile(file, mode = "r")
1440
array1 = fileh.root.array1
1441
array2 = fileh.root.array2
1444
print "attrs array1-->", repr(array1.attrs)
1445
print "attrs array2-->", repr(array2.attrs)
1447
# Assert other properties in array
1448
assert array1.nrows == array2.nrows
1449
assert array1.shape == array2.shape
1450
assert array1.extdim == array2.extdim
1451
assert array1.flavor == array2.flavor # Very important here!
1452
assert array1.type == array2.type
1453
assert array1.itemsize == array2.itemsize
1454
assert array1.title == array2.title
1455
assert str(array1.atom) == str(array2.atom)
1461
def test03b_copy(self):
1462
"""Checking EArray.copy() method (python flavor)"""
1465
print '\n', '-=' * 30
1466
print "Running %s.test03b_copy..." % self.__class__.__name__
1468
# Create an instance of an HDF5 Table
1469
file = tempfile.mktemp(".h5")
1470
fileh = openFile(file, "w")
1472
arr = Atom(shape=(0, 2), dtype=Int16, flavor="python")
1473
array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1474
array1.append(((456, 2),(3, 457)))
1478
print "(closing file version)"
1480
fileh = openFile(file, mode = "a")
1481
array1 = fileh.root.array1
1483
# Copy to another location
1484
array2 = array1.copy('/', 'array2')
1488
print "(closing file version)"
1490
fileh = openFile(file, mode = "r")
1491
array1 = fileh.root.array1
1492
array2 = fileh.root.array2
1495
print "attrs array1-->", repr(array1.attrs)
1496
print "attrs array2-->", repr(array2.attrs)
1498
# Check that all elements are equal
1499
assert array1.read() == array2.read()
1500
# Assert other properties in array
1501
assert array1.nrows == array2.nrows
1502
assert array1.shape == array2.shape
1503
assert array1.extdim == array2.extdim
1504
assert array1.flavor == array2.flavor # Very important here!
1505
assert array1.type == array2.type
1506
assert array1.itemsize == array2.itemsize
1507
assert array1.title == array2.title
1508
assert str(array1.atom) == str(array2.atom)
1514
def test03d_copy(self):
1515
"""Checking EArray.copy() method (python string flavor)"""
1518
print '\n', '-=' * 30
1519
print "Running %s.test03d_copy..." % self.__class__.__name__
1521
# Create an instance of an HDF5 Table
1522
file = tempfile.mktemp(".h5")
1523
fileh = openFile(file, "w")
1525
arr = StringAtom(shape=(0, 2), length=4, flavor="python")
1526
array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1527
array1.append([["456", "2"],["3", "457"]])
1531
print "(closing file version)"
1533
fileh = openFile(file, mode = "a")
1534
array1 = fileh.root.array1
1536
# Copy to another location
1537
array2 = array1.copy('/', 'array2')
1541
print "(closing file version)"
1543
fileh = openFile(file, mode = "r")
1544
array1 = fileh.root.array1
1545
array2 = fileh.root.array2
1548
print "attrs array1-->", repr(array1.attrs)
1549
print "attrs array2-->", repr(array2.attrs)
1551
# Check that all elements are equal
1552
assert array1.read() == array2.read()
1554
# Assert other properties in array
1555
assert array1.nrows == array2.nrows
1556
assert array1.shape == array2.shape
1557
assert array1.extdim == array2.extdim
1558
assert array1.flavor == array2.flavor # Very important here!
1559
assert array1.type == array2.type
1560
assert array1.itemsize == array2.itemsize
1561
assert array1.title == array2.title
1562
assert str(array1.atom) == str(array2.atom)
1568
def test03e_copy(self):
1569
"""Checking EArray.copy() method (CharArray flavor)"""
1572
print '\n', '-=' * 30
1573
print "Running %s.test03e_copy..." % self.__class__.__name__
1575
# Create an instance of an HDF5 Table
1576
file = tempfile.mktemp(".h5")
1577
fileh = openFile(file, "w")
1579
arr = StringAtom(shape=(0, 2), length=4, flavor="numarray")
1580
array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1581
array1.append(strings.array([["456", "2"],["3", "457"]], itemsize=4))
1585
print "(closing file version)"
1587
fileh = openFile(file, mode = "a")
1588
array1 = fileh.root.array1
1590
# Copy to another location
1591
array2 = array1.copy('/', 'array2')
1595
print "(closing file version)"
1597
fileh = openFile(file, mode = "r")
1598
array1 = fileh.root.array1
1599
array2 = fileh.root.array2
1602
print "attrs array1-->", repr(array1.attrs)
1603
print "attrs array2-->", repr(array2.attrs)
1605
# Check that all elements are equal
1606
assert allequal(array1.read(), array2.read())
1607
# Assert other properties in array
1608
assert array1.nrows == array2.nrows
1609
assert array1.shape == array2.shape
1610
assert array1.extdim == array2.extdim
1611
assert array1.flavor == array2.flavor # Very important here!
1612
assert array1.type == array2.type
1613
assert array1.itemsize == array2.itemsize
1614
assert array1.title == array2.title
1615
assert str(array1.atom) == str(array2.atom)
1621
def test04_copy(self):
1622
"""Checking EArray.copy() method (checking title copying)"""
1625
print '\n', '-=' * 30
1626
print "Running %s.test04_copy..." % self.__class__.__name__
1628
# Create an instance of an HDF5 Table
1629
file = tempfile.mktemp(".h5")
1630
fileh = openFile(file, "w")
1633
atom=Int16Atom(shape=(0,2))
1634
array1 = fileh.createEArray(fileh.root, 'array1', atom, "title array1")
1635
array1.append(array([[456, 2],[3, 457]], type=Int16))
1636
# Append some user attrs
1637
array1.attrs.attr1 = "attr1"
1638
array1.attrs.attr2 = 2
1642
print "(closing file version)"
1644
fileh = openFile(file, mode = "a")
1645
array1 = fileh.root.array1
1647
# Copy it to another Array
1648
array2 = array1.copy('/', 'array2', title="title array2")
1652
print "(closing file version)"
1654
fileh = openFile(file, mode = "r")
1655
array1 = fileh.root.array1
1656
array2 = fileh.root.array2
1658
# Assert user attributes
1660
print "title of destination array-->", array2.title
1661
array2.title == "title array2"
1667
def test05_copy(self):
1668
"""Checking EArray.copy() method (user attributes copied)"""
1671
print '\n', '-=' * 30
1672
print "Running %s.test05_copy..." % self.__class__.__name__
1674
# Create an instance of an HDF5 Table
1675
file = tempfile.mktemp(".h5")
1676
fileh = openFile(file, "w")
1679
atom=Int16Atom(shape=(0,2))
1680
array1 = fileh.createEArray(fileh.root, 'array1', atom, "title array1")
1681
array1.append(array([[456, 2],[3, 457]], type=Int16))
1682
# Append some user attrs
1683
array1.attrs.attr1 = "attr1"
1684
array1.attrs.attr2 = 2
1688
print "(closing file version)"
1690
fileh = openFile(file, mode = "a")
1691
array1 = fileh.root.array1
1693
# Copy it to another Array
1694
array2 = array1.copy('/', 'array2', copyuserattrs=1)
1698
print "(closing file version)"
1700
fileh = openFile(file, mode = "r")
1701
array1 = fileh.root.array1
1702
array2 = fileh.root.array2
1705
print "attrs array1-->", repr(array1.attrs)
1706
print "attrs array2-->", repr(array2.attrs)
1708
# Assert user attributes
1709
array2.attrs.attr1 == "attr1"
1710
array2.attrs.attr2 == 2
1716
def test05b_copy(self):
1717
"""Checking EArray.copy() method (user attributes not copied)"""
1720
print '\n', '-=' * 30
1721
print "Running %s.test05b_copy..." % self.__class__.__name__
1723
# Create an instance of an HDF5 Table
1724
file = tempfile.mktemp(".h5")
1725
fileh = openFile(file, "w")
1728
atom=Int16Atom(shape=(0,2))
1729
array1 = fileh.createEArray(fileh.root, 'array1', atom, "title array1")
1730
array1.append(array([[456, 2],[3, 457]], type=Int16))
1731
# Append some user attrs
1732
array1.attrs.attr1 = "attr1"
1733
array1.attrs.attr2 = 2
1737
print "(closing file version)"
1739
fileh = openFile(file, mode = "a")
1740
array1 = fileh.root.array1
1742
# Copy it to another Array
1743
array2 = array1.copy('/', 'array2', copyuserattrs=0)
1747
print "(closing file version)"
1749
fileh = openFile(file, mode = "r")
1750
array1 = fileh.root.array1
1751
array2 = fileh.root.array2
1754
print "attrs array1-->", repr(array1.attrs)
1755
print "attrs array2-->", repr(array2.attrs)
1757
# Assert user attributes
1758
hasattr(array2.attrs, "attr1") == 0
1759
hasattr(array2.attrs, "attr2") == 0
1766
class CloseCopyTestCase(CopyTestCase):
1769
class OpenCopyTestCase(CopyTestCase):
1772
class CopyIndexTestCase(unittest.TestCase):
1775
def test01_index(self):
1776
"""Checking EArray.copy() method with indexes"""
1779
print '\n', '-=' * 30
1780
print "Running %s.test01_index..." % self.__class__.__name__
1782
# Create an instance of an HDF5 Array
1783
file = tempfile.mktemp(".h5")
1784
fileh = openFile(file, "w")
1787
atom = Int32Atom(shape=(0,2))
1788
array1 = fileh.createEArray(fileh.root, 'array1', atom, "title array1")
1789
r = arange(200, type=Int32, shape=(100,2))
1792
# Select a different buffer size:
1793
array1._v_maxTuples = self.maxTuples
1795
# Copy to another array
1796
array2 = array1.copy("/", 'array2',
1801
print "array1-->", array1.read()
1802
print "array2-->", array2.read()
1803
print "attrs array1-->", repr(array1.attrs)
1804
print "attrs array2-->", repr(array2.attrs)
1806
# Check that all the elements are equal
1807
r2 = r[self.start:self.stop:self.step]
1808
assert allequal(r2, array2.read())
1810
# Assert the number of rows in array
1812
print "nrows in array2-->", array2.nrows
1813
print "and it should be-->", r2.shape[0]
1814
assert r2.shape[0] == array2.nrows
1820
def test02_indexclosef(self):
1821
"""Checking EArray.copy() method with indexes (close file version)"""
1824
print '\n', '-=' * 30
1825
print "Running %s.test02_indexclosef..." % self.__class__.__name__
1827
# Create an instance of an HDF5 Array
1828
file = tempfile.mktemp(".h5")
1829
fileh = openFile(file, "w")
1832
atom = Int32Atom(shape=(0,2))
1833
array1 = fileh.createEArray(fileh.root, 'array1', atom, "title array1")
1834
r = arange(200, type=Int32, shape=(100,2))
1837
# Select a different buffer size:
1838
array1._v_maxTuples = self.maxTuples
1840
# Copy to another array
1841
array2 = array1.copy("/", 'array2',
1845
# Close and reopen the file
1847
fileh = openFile(file, mode = "r")
1848
array1 = fileh.root.array1
1849
array2 = fileh.root.array2
1852
print "array1-->", array1.read()
1853
print "array2-->", array2.read()
1854
print "attrs array1-->", repr(array1.attrs)
1855
print "attrs array2-->", repr(array2.attrs)
1857
# Check that all the elements are equal
1858
r2 = r[self.start:self.stop:self.step]
1859
assert allequal(r2, array2.read())
1861
# Assert the number of rows in array
1863
print "nrows in array2-->", array2.nrows
1864
print "and it should be-->", r2.shape[0]
1865
assert r2.shape[0] == array2.nrows
1871
class CopyIndex1TestCase(CopyIndexTestCase):
1877
class CopyIndex2TestCase(CopyIndexTestCase):
1883
class CopyIndex3TestCase(CopyIndexTestCase):
1889
class CopyIndex4TestCase(CopyIndexTestCase):
1895
class CopyIndex5TestCase(CopyIndexTestCase):
1901
class CopyIndex6TestCase(CopyIndexTestCase):
1907
class CopyIndex7TestCase(CopyIndexTestCase):
1912
class CopyIndex8TestCase(CopyIndexTestCase):
1914
stop = -1 # Negative values means starting from the end
1917
class CopyIndex9TestCase(CopyIndexTestCase):
1922
class CopyIndex10TestCase(CopyIndexTestCase):
1928
class CopyIndex11TestCase(CopyIndexTestCase):
1933
class CopyIndex12TestCase(CopyIndexTestCase):
1934
start = -1 # Should point to the last element
1935
stop = None # None should mean the last element (including it)
1938
class TruncateTestCase(unittest.TestCase):
1940
def _test00_truncate(self):
1941
"""Checking EArray.truncate() method (truncating to 0 rows)"""
1944
print '\n', '-=' * 30
1945
print "Running %s.test00_truncate..." % self.__class__.__name__
1947
# Create an instance of an HDF5 Table
1948
file = tempfile.mktemp(".h5")
1949
fileh = openFile(file, "w")
1952
arr = Atom(shape=(0, 2), dtype=Int16)
1953
array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1955
array1.append(array([[456, 2],[3, 457]], type=Int16))
1959
fileh = openFile(file, mode = "a")
1960
array1 = fileh.root.array1
1962
# Truncate to 0 elements
1967
print "(closing file version)"
1969
fileh = openFile(file, mode = "r")
1970
array1 = fileh.root.array1
1973
print "array1-->", array1.read()
1975
assert allequal(array1[:], array([], type=Int16, shape=(0,2)))
1981
def test01_truncate(self):
1982
"""Checking EArray.truncate() method (truncating to 1 rows)"""
1985
print '\n', '-=' * 30
1986
print "Running %s.test01_truncate..." % self.__class__.__name__
1988
# Create an instance of an HDF5 Table
1989
file = tempfile.mktemp(".h5")
1990
fileh = openFile(file, "w")
1993
arr = Atom(shape=(0, 2), dtype=Int16)
1994
array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
1996
array1.append(array([[456, 2],[3, 457]], type=Int16))
2000
fileh = openFile(file, mode = "a")
2001
array1 = fileh.root.array1
2003
# Truncate to 1 element
2008
print "(closing file version)"
2010
fileh = openFile(file, mode = "r")
2011
array1 = fileh.root.array1
2014
print "array1-->", array1.read()
2016
assert allequal(array1.read(), array([[456, 2]], type=Int16))
2022
def test02_truncate(self):
2023
"""Checking EArray.truncate() method (truncating to >= earray.nrows)"""
2026
print '\n', '-=' * 30
2027
print "Running %s.test02_truncate..." % self.__class__.__name__
2029
# Create an instance of an HDF5 Table
2030
file = tempfile.mktemp(".h5")
2031
fileh = openFile(file, "w")
2034
arr = Atom(shape=(0, 2), dtype=Int16)
2035
array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
2037
array1.append(array([[456, 2],[3, 457]], type=Int16))
2041
fileh = openFile(file, mode = "a")
2042
array1 = fileh.root.array1
2044
# Truncate to 2 elements
2049
print "(closing file version)"
2051
fileh = openFile(file, mode = "r")
2052
array1 = fileh.root.array1
2055
print "array1-->", array1.read()
2057
assert allequal(array1.read(), array([[456, 2],[3, 457]], type=Int16))
2063
def test03_truncate(self):
2064
"""Checking EArray.truncate() method (truncating to > earray.nrows)"""
2067
print '\n', '-=' * 30
2068
print "Running %s.test03_truncate..." % self.__class__.__name__
2070
# Create an instance of an HDF5 Table
2071
file = tempfile.mktemp(".h5")
2072
fileh = openFile(file, "w")
2075
arr = Atom(shape=(0, 2), dtype=Int16)
2076
array1 = fileh.createEArray(fileh.root, 'array1', arr, "title array1")
2078
array1.append(array([[456, 2],[3, 457]], type=Int16))
2082
fileh = openFile(file, mode = "a")
2083
array1 = fileh.root.array1
2085
# Truncate to 3 element
2090
print "(closing file version)"
2092
fileh = openFile(file, mode = "r")
2093
array1 = fileh.root.array1
2096
print "array1-->", array1.read()
2098
assert allequal(array1.read(), array([[456, 2],[3, 457]], type=Int16))
2105
class TruncateOpenTestCase(TruncateTestCase):
2108
class TruncateCloseTestCase(TruncateTestCase):
2111
# The next test should be run only in **heavy** mode
2112
class Rows64bitsTestCase(unittest.TestCase):
2113
narows = 1000*1000L # each numarray will have 1 million entries
2114
#narows = 1000L # for testing only
2115
nanumber = 1000*3L # That should account for more than 2**31-1
2119
# Create an instance of an HDF5 Table
2120
self.file = tempfile.mktemp(".h5")
2121
fileh = self.fileh = openFile(self.file, "a")
2123
array = fileh.createEArray(fileh.root, 'array',
2125
filters=Filters(complib='lzo',
2127
# Specifying expectedrows takes more
2128
# CPU, but less disk
2129
expectedrows=self.narows*self.nanumber)
2132
na = arange(self.narows, type='Int8')
2133
for i in range(self.nanumber):
2139
os.remove(self.file)
2142
#----------------------------------------
2144
def test01_basiccheck(self):
2145
"Some basic checks for earrays exceeding 2**31 rows"
2148
array = fileh.root.array
2152
# Check how many entries there are in the array
2153
print "Before closing"
2154
print "Entries:", array.nrows, type(array.nrows)
2155
print "Entries:", array.nrows / (1000*1000), "Millions"
2156
print "Shape:", array.shape
2160
fileh = self.fileh = openFile(self.file)
2161
array = fileh.root.array
2163
print "After re-open"
2165
# Check how many entries there are in the array
2167
print "Entries:", array.nrows, type(array.nrows)
2168
print "Entries:", array.nrows / (1000*1000), "Millions"
2169
print "Shape:", array.shape
2170
print "Last 10 elements-->", array[-10:]
2171
stop = self.narows%256
2175
#print "start, stop-->", start, stop
2176
print "Should look like-->", arange(start, stop, type='Int8')
2178
nrows = self.narows*self.nanumber
2180
assert array.nrows == nrows
2182
assert array.shape == (nrows,)
2183
# check the 10 first elements
2184
assert allequal(array[:10], arange(10, type='Int8'))
2185
# check the 10 last elements
2186
stop = self.narows%256
2190
assert allequal(array[-10:], arange(start, stop, type='Int8'))
2193
class Rows64bitsTestCase1(Rows64bitsTestCase):
2196
class Rows64bitsTestCase2(Rows64bitsTestCase):
2199
#----------------------------------------------------------------------
2202
theSuite = unittest.TestSuite()
2204
global numpy_imported
2206
#heavy = 1 # uncomment this only for testing purposes
2208
#theSuite.addTest(unittest.makeSuite(BasicWriteTestCase))
2209
#theSuite.addTest(unittest.makeSuite(Rows64bitsTestCase1))
2210
#theSuite.addTest(unittest.makeSuite(Rows64bitsTestCase2))
2211
for n in range(niter):
2212
theSuite.addTest(unittest.makeSuite(BasicWriteTestCase))
2213
theSuite.addTest(unittest.makeSuite(BasicWrite2TestCase))
2214
theSuite.addTest(unittest.makeSuite(EmptyEArrayTestCase))
2215
theSuite.addTest(unittest.makeSuite(EmptyEArray2TestCase))
2216
theSuite.addTest(unittest.makeSuite(SlicesEArrayTestCase))
2217
theSuite.addTest(unittest.makeSuite(Slices2EArrayTestCase))
2218
theSuite.addTest(unittest.makeSuite(EllipsisEArrayTestCase))
2219
theSuite.addTest(unittest.makeSuite(Ellipsis2EArrayTestCase))
2220
theSuite.addTest(unittest.makeSuite(Ellipsis3EArrayTestCase))
2221
theSuite.addTest(unittest.makeSuite(ZlibComprTestCase))
2222
theSuite.addTest(unittest.makeSuite(ZlibShuffleTestCase))
2223
theSuite.addTest(unittest.makeSuite(LZOComprTestCase))
2224
theSuite.addTest(unittest.makeSuite(LZOShuffleTestCase))
2225
theSuite.addTest(unittest.makeSuite(BZIP2ComprTestCase))
2226
theSuite.addTest(unittest.makeSuite(BZIP2ShuffleTestCase))
2227
theSuite.addTest(unittest.makeSuite(FloatTypeTestCase))
2228
theSuite.addTest(unittest.makeSuite(ComplexTypeTestCase))
2229
theSuite.addTest(unittest.makeSuite(CharTypeTestCase))
2230
theSuite.addTest(unittest.makeSuite(CharType2TestCase))
2231
theSuite.addTest(unittest.makeSuite(CharTypeComprTestCase))
2233
theSuite.addTest(unittest.makeSuite(Numeric1TestCase))
2234
theSuite.addTest(unittest.makeSuite(Numeric2TestCase))
2235
theSuite.addTest(unittest.makeSuite(NumericComprTestCase))
2237
theSuite.addTest(unittest.makeSuite(Numpy2TestCase))
2238
theSuite.addTest(unittest.makeSuite(NumpyComprTestCase))
2239
theSuite.addTest(unittest.makeSuite(CharTypeNumpyTestCase))
2240
theSuite.addTest(unittest.makeSuite(CharType2NumpyTestCase))
2241
theSuite.addTest(unittest.makeSuite(NP_EmptyEArrayTestCase))
2242
theSuite.addTest(unittest.makeSuite(NP_MD6WriteTestCase))
2243
theSuite.addTest(unittest.makeSuite(NP_MD10WriteTestCase))
2244
theSuite.addTest(unittest.makeSuite(OffsetStrideTestCase))
2245
theSuite.addTest(unittest.makeSuite(Fletcher32TestCase))
2246
theSuite.addTest(unittest.makeSuite(AllFiltersTestCase))
2247
theSuite.addTest(unittest.makeSuite(CloseCopyTestCase))
2248
theSuite.addTest(unittest.makeSuite(OpenCopyTestCase))
2249
theSuite.addTest(unittest.makeSuite(CopyIndex1TestCase))
2250
theSuite.addTest(unittest.makeSuite(CopyIndex2TestCase))
2251
theSuite.addTest(unittest.makeSuite(CopyIndex3TestCase))
2252
theSuite.addTest(unittest.makeSuite(CopyIndex4TestCase))
2253
theSuite.addTest(unittest.makeSuite(CopyIndex5TestCase))
2254
theSuite.addTest(unittest.makeSuite(TruncateOpenTestCase))
2255
theSuite.addTest(unittest.makeSuite(TruncateCloseTestCase))
2257
theSuite.addTest(unittest.makeSuite(Slices3EArrayTestCase))
2258
theSuite.addTest(unittest.makeSuite(Slices4EArrayTestCase))
2259
theSuite.addTest(unittest.makeSuite(Ellipsis4EArrayTestCase))
2260
theSuite.addTest(unittest.makeSuite(Ellipsis5EArrayTestCase))
2261
theSuite.addTest(unittest.makeSuite(Ellipsis6EArrayTestCase))
2262
theSuite.addTest(unittest.makeSuite(Ellipsis7EArrayTestCase))
2263
theSuite.addTest(unittest.makeSuite(MD3WriteTestCase))
2264
theSuite.addTest(unittest.makeSuite(MD5WriteTestCase))
2265
theSuite.addTest(unittest.makeSuite(MD6WriteTestCase))
2266
theSuite.addTest(unittest.makeSuite(MD7WriteTestCase))
2267
theSuite.addTest(unittest.makeSuite(MD10WriteTestCase))
2268
theSuite.addTest(unittest.makeSuite(CopyIndex6TestCase))
2269
theSuite.addTest(unittest.makeSuite(CopyIndex7TestCase))
2270
theSuite.addTest(unittest.makeSuite(CopyIndex8TestCase))
2271
theSuite.addTest(unittest.makeSuite(CopyIndex9TestCase))
2272
theSuite.addTest(unittest.makeSuite(CopyIndex10TestCase))
2273
theSuite.addTest(unittest.makeSuite(CopyIndex11TestCase))
2274
theSuite.addTest(unittest.makeSuite(CopyIndex12TestCase))
2275
theSuite.addTest(unittest.makeSuite(Rows64bitsTestCase1))
2276
theSuite.addTest(unittest.makeSuite(Rows64bitsTestCase2))
2277
# The CharTypeComprNumpyTestCase takes muchs more time than
2278
# its equivalent in numarray CharTypeComprTestCase.
2279
# This should be further analyzed.
2280
# F. Altet 2006-02-03
2282
theSuite.addTest(unittest.makeSuite(CharTypeComprNumpyTestCase))
2287
if __name__ == '__main__':
2288
unittest.main( defaultTest='suite' )
2292
## py-indent-offset: 4