1# -*- coding: utf-8 -*- 2 3 4import os 5import sys 6import tempfile 7import warnings 8 9import numpy 10from numpy import testing as npt 11 12 13import tables 14from tables import Atom, ClosedNodeError, NoSuchNodeError 15from tables.utils import byteorders 16from tables.tests import common 17from tables.tests.common import allequal 18from tables.tests.common import unittest, test_filename 19from tables.tests.common import PyTablesTestCase as TestCase 20 21 22#warnings.resetwarnings() 23 24 25class BasicTestCase(TestCase): 26 """Basic test for all the supported typecodes present in numpy. 27 28 All of them are included on pytables. 29 30 """ 31 endiancheck = False 32 33 def write_read(self, testarray): 34 a = testarray 35 if common.verbose: 36 print('\n', '-=' * 30) 37 print("Running test for array with type '%s'" % a.dtype.type, 38 end=' ') 39 print("for class check:", self.title) 40 41 # Create an instance of HDF5 file 42 filename = tempfile.mktemp(".h5") 43 try: 44 with tables.open_file(filename, mode="w") as fileh: 45 root = fileh.root 46 47 # Create the array under root and name 'somearray' 48 if self.endiancheck and a.dtype.kind != "S": 49 b = a.byteswap() 50 b.dtype = a.dtype.newbyteorder() 51 a = b 52 53 fileh.create_array(root, 'somearray', a, "Some array") 54 55 # Re-open the file in read-only mode 56 with tables.open_file(filename, mode="r") as fileh: 57 root = fileh.root 58 59 # Read the saved array 60 b = root.somearray.read() 61 62 # Compare them. They should be equal. 63 if common.verbose and not allequal(a, b): 64 print("Write and read arrays differ!") 65 # print("Array written:", a) 66 print("Array written shape:", a.shape) 67 print("Array written itemsize:", a.itemsize) 68 print("Array written type:", a.dtype.type) 69 # print("Array read:", b) 70 print("Array read shape:", b.shape) 71 print("Array read itemsize:", b.itemsize) 72 print("Array read type:", b.dtype.type) 73 if a.dtype.kind != "S": 74 print("Array written byteorder:", a.dtype.byteorder) 75 print("Array read byteorder:", b.dtype.byteorder) 76 77 # Check strictly the array equality 78 self.assertEqual(a.shape, b.shape) 79 self.assertEqual(a.shape, root.somearray.shape) 80 if a.dtype.kind == "S": 81 self.assertEqual(root.somearray.atom.type, "string") 82 else: 83 self.assertEqual(a.dtype.type, b.dtype.type) 84 self.assertEqual(a.dtype.type, 85 root.somearray.atom.dtype.type) 86 abo = byteorders[a.dtype.byteorder] 87 bbo = byteorders[b.dtype.byteorder] 88 if abo != "irrelevant": 89 self.assertEqual(abo, root.somearray.byteorder) 90 self.assertEqual(bbo, sys.byteorder) 91 if self.endiancheck: 92 self.assertNotEqual(bbo, abo) 93 94 obj = root.somearray 95 self.assertEqual(obj.flavor, 'numpy') 96 self.assertEqual(obj.shape, a.shape) 97 self.assertEqual(obj.ndim, a.ndim) 98 self.assertEqual(obj.chunkshape, None) 99 if a.shape: 100 nrows = a.shape[0] 101 else: 102 # scalar 103 nrows = 1 104 105 self.assertEqual(obj.nrows, nrows) 106 107 self.assertTrue(allequal(a, b)) 108 finally: 109 # Then, delete the file 110 os.remove(filename) 111 112 def write_read_out_arg(self, testarray): 113 a = testarray 114 115 if common.verbose: 116 print('\n', '-=' * 30) 117 print("Running test for array with type '%s'" % a.dtype.type, 118 end=' ') 119 print("for class check:", self.title) 120 121 # Create an instance of HDF5 file 122 filename = tempfile.mktemp(".h5") 123 try: 124 with tables.open_file(filename, mode="w") as fileh: 125 root = fileh.root 126 127 # Create the array under root and name 'somearray' 128 if self.endiancheck and a.dtype.kind != "S": 129 b = a.byteswap() 130 b.dtype = a.dtype.newbyteorder() 131 a = b 132 133 fileh.create_array(root, 'somearray', a, "Some array") 134 135 # Re-open the file in read-only mode 136 with tables.open_file(filename, mode="r") as fileh: 137 root = fileh.root 138 139 # Read the saved array 140 b = numpy.empty_like(a, dtype=a.dtype) 141 root.somearray.read(out=b) 142 143 # Check strictly the array equality 144 self.assertEqual(a.shape, b.shape) 145 self.assertEqual(a.shape, root.somearray.shape) 146 if a.dtype.kind == "S": 147 self.assertEqual(root.somearray.atom.type, "string") 148 else: 149 self.assertEqual(a.dtype.type, b.dtype.type) 150 self.assertEqual(a.dtype.type, 151 root.somearray.atom.dtype.type) 152 abo = byteorders[a.dtype.byteorder] 153 bbo = byteorders[b.dtype.byteorder] 154 if abo != "irrelevant": 155 self.assertEqual(abo, root.somearray.byteorder) 156 self.assertEqual(abo, bbo) 157 if self.endiancheck: 158 self.assertNotEqual(bbo, sys.byteorder) 159 160 self.assertTrue(allequal(a, b)) 161 finally: 162 # Then, delete the file 163 os.remove(filename) 164 165 def write_read_atom_shape_args(self, testarray): 166 a = testarray 167 atom = Atom.from_dtype(a.dtype) 168 shape = a.shape 169 byteorder = None 170 171 if common.verbose: 172 print('\n', '-=' * 30) 173 print("Running test for array with type '%s'" % a.dtype.type, 174 end=' ') 175 print("for class check:", self.title) 176 177 # Create an instance of HDF5 file 178 filename = tempfile.mktemp(".h5") 179 try: 180 with tables.open_file(filename, mode="w") as fileh: 181 root = fileh.root 182 183 # Create the array under root and name 'somearray' 184 if self.endiancheck and a.dtype.kind != "S": 185 b = a.byteswap() 186 b.dtype = a.dtype.newbyteorder() 187 if b.dtype.byteorder in ('>', '<'): 188 byteorder = byteorders[b.dtype.byteorder] 189 a = b 190 191 ptarr = fileh.create_array(root, 'somearray', 192 atom=atom, shape=shape, 193 title="Some array", 194 # specify the byteorder explicitly 195 # since there is no way to deduce 196 # it in this case 197 byteorder=byteorder) 198 self.assertEqual(shape, ptarr.shape) 199 self.assertEqual(atom, ptarr.atom) 200 ptarr[...] = a 201 202 # Re-open the file in read-only mode 203 with tables.open_file(filename, mode="r") as fileh: 204 root = fileh.root 205 206 # Read the saved array 207 b = root.somearray.read() 208 209 # Compare them. They should be equal. 210 if common.verbose and not allequal(a, b): 211 print("Write and read arrays differ!") 212 # print("Array written:", a) 213 print("Array written shape:", a.shape) 214 print("Array written itemsize:", a.itemsize) 215 print("Array written type:", a.dtype.type) 216 # print("Array read:", b) 217 print("Array read shape:", b.shape) 218 print("Array read itemsize:", b.itemsize) 219 print("Array read type:", b.dtype.type) 220 if a.dtype.kind != "S": 221 print("Array written byteorder:", a.dtype.byteorder) 222 print("Array read byteorder:", b.dtype.byteorder) 223 224 # Check strictly the array equality 225 self.assertEqual(a.shape, b.shape) 226 self.assertEqual(a.shape, root.somearray.shape) 227 if a.dtype.kind == "S": 228 self.assertEqual(root.somearray.atom.type, "string") 229 else: 230 self.assertEqual(a.dtype.type, b.dtype.type) 231 self.assertEqual(a.dtype.type, 232 root.somearray.atom.dtype.type) 233 abo = byteorders[a.dtype.byteorder] 234 bbo = byteorders[b.dtype.byteorder] 235 if abo != "irrelevant": 236 self.assertEqual(abo, root.somearray.byteorder) 237 self.assertEqual(bbo, sys.byteorder) 238 if self.endiancheck: 239 self.assertNotEqual(bbo, abo) 240 241 obj = root.somearray 242 self.assertEqual(obj.flavor, 'numpy') 243 self.assertEqual(obj.shape, a.shape) 244 self.assertEqual(obj.ndim, a.ndim) 245 self.assertEqual(obj.chunkshape, None) 246 if a.shape: 247 nrows = a.shape[0] 248 else: 249 # scalar 250 nrows = 1 251 252 self.assertEqual(obj.nrows, nrows) 253 254 self.assertTrue(allequal(a, b)) 255 finally: 256 # Then, delete the file 257 os.remove(filename) 258 259 def setup00_char(self): 260 """Data integrity during recovery (character objects)""" 261 262 if not isinstance(self.tupleChar, numpy.ndarray): 263 a = numpy.array(self.tupleChar, dtype="S") 264 else: 265 a = self.tupleChar 266 267 return a 268 269 def test00_char(self): 270 a = self.setup00_char() 271 self.write_read(a) 272 273 def test00_char_out_arg(self): 274 a = self.setup00_char() 275 self.write_read_out_arg(a) 276 277 def test00_char_atom_shape_args(self): 278 a = self.setup00_char() 279 self.write_read_atom_shape_args(a) 280 281 def test00b_char(self): 282 """Data integrity during recovery (string objects)""" 283 284 a = self.tupleChar 285 286 filename = tempfile.mktemp(".h5") 287 try: 288 # Create an instance of HDF5 file 289 with tables.open_file(filename, mode="w") as fileh: 290 fileh.create_array(fileh.root, 'somearray', a, "Some array") 291 292 # Re-open the file in read-only mode 293 with tables.open_file(filename, mode="r") as fileh: 294 # Read the saved array 295 b = fileh.root.somearray.read() 296 if isinstance(a, bytes): 297 self.assertEqual(type(b), bytes) 298 self.assertEqual(a, b) 299 else: 300 # If a is not a python string, then it should be a list 301 # or ndarray 302 self.assertIn(type(b), [list, numpy.ndarray]) 303 finally: 304 # Then, delete the file 305 os.remove(filename) 306 307 def test00b_char_out_arg(self): 308 """Data integrity during recovery (string objects)""" 309 310 a = self.tupleChar 311 312 filename = tempfile.mktemp(".h5") 313 try: 314 # Create an instance of HDF5 file 315 with tables.open_file(filename, mode="w") as fileh: 316 fileh.create_array(fileh.root, 'somearray', a, "Some array") 317 318 # Re-open the file in read-only mode 319 with tables.open_file(filename, mode="r") as fileh: 320 # Read the saved array 321 b = numpy.empty_like(a) 322 if fileh.root.somearray.flavor != 'numpy': 323 self.assertRaises(TypeError, 324 lambda: fileh.root.somearray.read(out=b)) 325 else: 326 fileh.root.somearray.read(out=b) 327 self.assertIsInstance(b, numpy.ndarray) 328 finally: 329 # Then, delete the file 330 os.remove(filename) 331 332 def test00b_char_atom_shape_args(self): 333 """Data integrity during recovery (string objects)""" 334 335 a = self.tupleChar 336 337 filename = tempfile.mktemp(".h5") 338 try: 339 # Create an instance of HDF5 file 340 with tables.open_file(filename, mode="w") as fileh: 341 nparr = numpy.asarray(a) 342 atom = Atom.from_dtype(nparr.dtype) 343 shape = nparr.shape 344 if nparr.dtype.byteorder in ('>', '<'): 345 byteorder = byteorders[nparr.dtype.byteorder] 346 else: 347 byteorder = None 348 349 ptarr = fileh.create_array(fileh.root, 'somearray', 350 atom=atom, shape=shape, 351 byteorder=byteorder, 352 title="Some array") 353 self.assertEqual(shape, ptarr.shape) 354 self.assertEqual(atom, ptarr.atom) 355 ptarr[...] = a 356 357 # Re-open the file in read-only mode 358 with tables.open_file(filename, mode="r") as fileh: 359 # Read the saved array 360 b = numpy.empty_like(a) 361 if fileh.root.somearray.flavor != 'numpy': 362 self.assertRaises(TypeError, 363 lambda: fileh.root.somearray.read(out=b)) 364 else: 365 fileh.root.somearray.read(out=b) 366 self.assertIsInstance(b, numpy.ndarray) 367 finally: 368 # Then, delete the file 369 os.remove(filename) 370 371 def setup01_char_nc(self): 372 """Data integrity during recovery (non-contiguous character objects)""" 373 374 if not isinstance(self.tupleChar, numpy.ndarray): 375 a = numpy.array(self.tupleChar, dtype="S") 376 else: 377 a = self.tupleChar 378 if a.ndim == 0: 379 b = a.copy() 380 else: 381 b = a[::2] 382 # Ensure that this numpy string is non-contiguous 383 if len(b) > 1: 384 self.assertEqual(b.flags.contiguous, False) 385 return b 386 387 def test01_char_nc(self): 388 b = self.setup01_char_nc() 389 self.write_read(b) 390 391 def test01_char_nc_out_arg(self): 392 b = self.setup01_char_nc() 393 self.write_read_out_arg(b) 394 395 def test01_char_nc_atom_shape_args(self): 396 b = self.setup01_char_nc() 397 self.write_read_atom_shape_args(b) 398 399 def test02_types(self): 400 """Data integrity during recovery (numerical types)""" 401 402 typecodes = ['int8', 'int16', 'int32', 'int64', 403 'uint8', 'uint16', 'uint32', 'uint64', 404 'float32', 'float64', 405 'complex64', 'complex128'] 406 407 for name in ('float16', 'float96', 'float128', 408 'complex192', 'complex256'): 409 atomname = name.capitalize() + 'Atom' 410 if hasattr(tables, atomname): 411 typecodes.append(name) 412 413 for typecode in typecodes: 414 a = numpy.array(self.tupleInt, typecode) 415 self.write_read(a) 416 b = numpy.array(self.tupleInt, typecode) 417 self.write_read_out_arg(b) 418 c = numpy.array(self.tupleInt, typecode) 419 self.write_read_atom_shape_args(c) 420 421 def test03_types_nc(self): 422 """Data integrity during recovery (non-contiguous numerical types)""" 423 424 typecodes = ['int8', 'int16', 'int32', 'int64', 425 'uint8', 'uint16', 'uint32', 'uint64', 426 'float32', 'float64', 427 'complex64', 'complex128', ] 428 429 for name in ('float16', 'float96', 'float128', 430 'complex192', 'complex256'): 431 atomname = name.capitalize() + 'Atom' 432 if hasattr(tables, atomname): 433 typecodes.append(name) 434 435 for typecode in typecodes: 436 a = numpy.array(self.tupleInt, typecode) 437 if a.ndim == 0: 438 b1 = a.copy() 439 b2 = a.copy() 440 b3 = a.copy() 441 else: 442 b1 = a[::2] 443 b2 = a[::2] 444 b3 = a[::2] 445 # Ensure that this array is non-contiguous 446 if len(b1) > 1: 447 self.assertEqual(b1.flags.contiguous, False) 448 if len(b2) > 1: 449 self.assertEqual(b2.flags.contiguous, False) 450 if len(b3) > 1: 451 self.assertEqual(b3.flags.contiguous, False) 452 self.write_read(b1) 453 self.write_read_out_arg(b2) 454 self.write_read_atom_shape_args(b3) 455 456 457class Basic0DOneTestCase(BasicTestCase): 458 # Scalar case 459 title = "Rank-0 case 1" 460 tupleInt = 3 461 tupleChar = b"3" 462 endiancheck = True 463 464 465class Basic0DTwoTestCase(BasicTestCase): 466 # Scalar case 467 title = "Rank-0 case 2" 468 tupleInt = 33 469 tupleChar = b"33" 470 endiancheck = True 471 472 473class Basic1DZeroTestCase(BasicTestCase): 474 # This test case is not supported by PyTables (HDF5 limitations) 475 # 1D case 476 title = "Rank-1 case 0" 477 tupleInt = () 478 tupleChar = () 479 endiancheck = False 480 481 482class Basic1DOneTestCase(BasicTestCase): 483 # 1D case 484 title = "Rank-1 case 1" 485 tupleInt = (3,) 486 tupleChar = (b"a",) 487 endiancheck = True 488 489 490class Basic1DTwoTestCase(BasicTestCase): 491 # 1D case 492 title = "Rank-1 case 2" 493 tupleInt = (3, 4) 494 tupleChar = (b"aaa",) 495 endiancheck = True 496 497 498class Basic1DThreeTestCase(BasicTestCase): 499 # 1D case 500 title = "Rank-1 case 3" 501 tupleInt = (3, 4, 5) 502 tupleChar = (b"aaa", b"bbb",) 503 endiancheck = True 504 505 506class Basic2DOneTestCase(BasicTestCase): 507 # 2D case 508 title = "Rank-2 case 1" 509 tupleInt = numpy.array(numpy.arange((4)**2)) 510 tupleInt.shape = (4,)*2 511 tupleChar = numpy.array(["abc"]*3**2, dtype="S3") 512 tupleChar.shape = (3,)*2 513 endiancheck = True 514 515 516class Basic2DTwoTestCase(BasicTestCase): 517 # 2D case, with a multidimensional dtype 518 title = "Rank-2 case 2" 519 tupleInt = numpy.array(numpy.arange((4)), dtype=(numpy.int_, (4,))) 520 tupleChar = numpy.array(["abc"]*3, dtype=("S3", (3,))) 521 endiancheck = True 522 523 524class Basic10DTestCase(BasicTestCase): 525 # 10D case 526 title = "Rank-10 test" 527 tupleInt = numpy.array(numpy.arange((2)**10)) 528 tupleInt.shape = (2,)*10 529 tupleChar = numpy.array( 530 ["abc"]*2**10, dtype="S3") 531 tupleChar.shape = (2,)*10 532 endiancheck = True 533 534 535class Basic32DTestCase(BasicTestCase): 536 # 32D case (maximum) 537 title = "Rank-32 test" 538 tupleInt = numpy.array((32,)) 539 tupleInt.shape = (1,)*32 540 tupleChar = numpy.array(["121"], dtype="S3") 541 tupleChar.shape = (1,)*32 542 543 544class ReadOutArgumentTests(common.TempFileMixin, TestCase): 545 546 def setUp(self): 547 super(ReadOutArgumentTests, self).setUp() 548 self.size = 1000 549 550 def create_array(self): 551 array = numpy.arange(self.size, dtype='f8') 552 disk_array = self.h5file.create_array('/', 'array', array) 553 return array, disk_array 554 555 def test_read_entire_array(self): 556 array, disk_array = self.create_array() 557 out_buffer = numpy.empty((self.size, ), 'f8') 558 disk_array.read(out=out_buffer) 559 numpy.testing.assert_equal(out_buffer, array) 560 561 def test_read_contiguous_slice1(self): 562 array, disk_array = self.create_array() 563 out_buffer = numpy.arange(self.size, dtype='f8') 564 out_buffer = numpy.random.permutation(out_buffer) 565 out_buffer_orig = out_buffer.copy() 566 start = self.size // 2 567 disk_array.read(start=start, stop=self.size, out=out_buffer[start:]) 568 numpy.testing.assert_equal(out_buffer[start:], array[start:]) 569 numpy.testing.assert_equal(out_buffer[:start], out_buffer_orig[:start]) 570 571 def test_read_contiguous_slice2(self): 572 array, disk_array = self.create_array() 573 out_buffer = numpy.arange(self.size, dtype='f8') 574 out_buffer = numpy.random.permutation(out_buffer) 575 out_buffer_orig = out_buffer.copy() 576 start = self.size // 4 577 stop = self.size - start 578 disk_array.read(start=start, stop=stop, out=out_buffer[start:stop]) 579 numpy.testing.assert_equal(out_buffer[start:stop], array[start:stop]) 580 numpy.testing.assert_equal(out_buffer[:start], out_buffer_orig[:start]) 581 numpy.testing.assert_equal(out_buffer[stop:], out_buffer_orig[stop:]) 582 583 def test_read_non_contiguous_slice_contiguous_buffer(self): 584 array, disk_array = self.create_array() 585 out_buffer = numpy.empty((self.size // 2, ), dtype='f8') 586 disk_array.read(start=0, stop=self.size, step=2, out=out_buffer) 587 numpy.testing.assert_equal(out_buffer, array[0:self.size:2]) 588 589 def test_read_non_contiguous_buffer(self): 590 array, disk_array = self.create_array() 591 out_buffer = numpy.empty((self.size, ), 'f8') 592 out_buffer_slice = out_buffer[0:self.size:2] 593 # once Python 2.6 support is dropped, this could change 594 # to assertRaisesRegexp to check exception type and message at once 595 self.assertRaises(ValueError, disk_array.read, 0, self.size, 2, 596 out_buffer_slice) 597 try: 598 disk_array.read(0, self.size, 2, out_buffer_slice) 599 except ValueError as exc: 600 self.assertEqual('output array not C contiguous', str(exc)) 601 602 def test_buffer_too_small(self): 603 array, disk_array = self.create_array() 604 out_buffer = numpy.empty((self.size // 2, ), 'f8') 605 self.assertRaises(ValueError, disk_array.read, 0, self.size, 1, 606 out_buffer) 607 try: 608 disk_array.read(0, self.size, 1, out_buffer) 609 except ValueError as exc: 610 self.assertIn('output array size invalid, got', str(exc)) 611 612 def test_buffer_too_large(self): 613 array, disk_array = self.create_array() 614 out_buffer = numpy.empty((self.size + 1, ), 'f8') 615 self.assertRaises(ValueError, disk_array.read, 0, self.size, 1, 616 out_buffer) 617 try: 618 disk_array.read(0, self.size, 1, out_buffer) 619 except ValueError as exc: 620 self.assertIn('output array size invalid, got', str(exc)) 621 622 623class SizeOnDiskInMemoryPropertyTestCase(common.TempFileMixin, TestCase): 624 625 def setUp(self): 626 super(SizeOnDiskInMemoryPropertyTestCase, self).setUp() 627 self.array_size = (10, 10) 628 self.array = self.h5file.create_array( 629 '/', 'somearray', numpy.zeros(self.array_size, 'i4')) 630 631 def test_all_zeros(self): 632 self.assertEqual(self.array.size_on_disk, 10 * 10 * 4) 633 self.assertEqual(self.array.size_in_memory, 10 * 10 * 4) 634 635 636class UnalignedAndComplexTestCase(common.TempFileMixin, TestCase): 637 """Basic test for all the supported typecodes present in numpy. 638 639 Most of them are included on PyTables. 640 641 """ 642 643 def setUp(self): 644 super(UnalignedAndComplexTestCase, self).setUp() 645 self.root = self.h5file.root 646 647 def write_read(self, testArray): 648 if common.verbose: 649 print('\n', '-=' * 30) 650 print("\nRunning test for array with type '%s'" % 651 testArray.dtype.type) 652 653 # Create the array under root and name 'somearray' 654 a = testArray 655 if self.endiancheck: 656 byteorder = {"little": "big", "big": "little"}[sys.byteorder] 657 else: 658 byteorder = sys.byteorder 659 660 self.h5file.create_array(self.root, 'somearray', a, "Some array", 661 byteorder=byteorder) 662 663 if self.reopen: 664 self._reopen() 665 self.root = self.h5file.root 666 667 # Read the saved array 668 b = self.root.somearray.read() 669 670 # Get an array to be compared in the correct byteorder 671 c = a.newbyteorder(byteorder) 672 673 # Compare them. They should be equal. 674 if not allequal(c, b) and common.verbose: 675 print("Write and read arrays differ!") 676 print("Array written:", a) 677 print("Array written shape:", a.shape) 678 print("Array written itemsize:", a.itemsize) 679 print("Array written type:", a.dtype.type) 680 print("Array read:", b) 681 print("Array read shape:", b.shape) 682 print("Array read itemsize:", b.itemsize) 683 print("Array read type:", b.dtype.type) 684 685 # Check strictly the array equality 686 self.assertEqual(a.shape, b.shape) 687 self.assertEqual(a.shape, self.root.somearray.shape) 688 if a.dtype.byteorder != "|": 689 self.assertEqual(a.dtype, b.dtype) 690 self.assertEqual(a.dtype, self.root.somearray.atom.dtype) 691 self.assertEqual(byteorders[b.dtype.byteorder], sys.byteorder) 692 self.assertEqual(self.root.somearray.byteorder, byteorder) 693 694 self.assertTrue(allequal(c, b)) 695 696 def test01_signedShort_unaligned(self): 697 """Checking an unaligned signed short integer array""" 698 699 r = numpy.rec.array(b'a'*200, formats='i1,f4,i2', shape=10) 700 a = r["f2"] 701 # Ensure that this array is non-aligned 702 self.assertEqual(a.flags.aligned, False) 703 self.assertEqual(a.dtype.type, numpy.int16) 704 self.write_read(a) 705 706 def test02_float_unaligned(self): 707 """Checking an unaligned single precision array""" 708 709 r = numpy.rec.array(b'a'*200, formats='i1,f4,i2', shape=10) 710 a = r["f1"] 711 # Ensure that this array is non-aligned 712 self.assertEqual(a.flags.aligned, 0) 713 self.assertEqual(a.dtype.type, numpy.float32) 714 self.write_read(a) 715 716 def test03_byte_offset(self): 717 """Checking an offsetted byte array""" 718 719 r = numpy.arange(100, dtype=numpy.int8) 720 r.shape = (10, 10) 721 a = r[2] 722 self.write_read(a) 723 724 def test04_short_offset(self): 725 """Checking an offsetted unsigned short int precision array""" 726 727 r = numpy.arange(100, dtype=numpy.uint32) 728 r.shape = (10, 10) 729 a = r[2] 730 self.write_read(a) 731 732 def test05_int_offset(self): 733 """Checking an offsetted integer array""" 734 735 r = numpy.arange(100, dtype=numpy.int32) 736 r.shape = (10, 10) 737 a = r[2] 738 self.write_read(a) 739 740 def test06_longlongint_offset(self): 741 """Checking an offsetted long long integer array""" 742 743 r = numpy.arange(100, dtype=numpy.int64) 744 r.shape = (10, 10) 745 a = r[2] 746 self.write_read(a) 747 748 def test07_float_offset(self): 749 """Checking an offsetted single precision array""" 750 751 r = numpy.arange(100, dtype=numpy.float32) 752 r.shape = (10, 10) 753 a = r[2] 754 self.write_read(a) 755 756 def test08_double_offset(self): 757 """Checking an offsetted double precision array""" 758 759 r = numpy.arange(100, dtype=numpy.float64) 760 r.shape = (10, 10) 761 a = r[2] 762 self.write_read(a) 763 764 def test09_float_offset_unaligned(self): 765 """Checking an unaligned and offsetted single precision array""" 766 767 r = numpy.rec.array(b'a'*200, formats='i1,3f4,i2', shape=10) 768 a = r["f1"][3] 769 # Ensure that this array is non-aligned 770 self.assertEqual(a.flags.aligned, False) 771 self.assertEqual(a.dtype.type, numpy.float32) 772 self.write_read(a) 773 774 def test10_double_offset_unaligned(self): 775 """Checking an unaligned and offsetted double precision array""" 776 777 r = numpy.rec.array(b'a'*400, formats='i1,3f8,i2', shape=10) 778 a = r["f1"][3] 779 # Ensure that this array is non-aligned 780 self.assertEqual(a.flags.aligned, False) 781 self.assertEqual(a.dtype.type, numpy.float64) 782 self.write_read(a) 783 784 def test11_int_byteorder(self): 785 """Checking setting data with different byteorder in a range 786 (integer)""" 787 788 # Save an array with the reversed byteorder on it 789 a = numpy.arange(25, dtype=numpy.int32).reshape(5, 5) 790 a = a.byteswap() 791 a = a.newbyteorder() 792 array = self.h5file.create_array( 793 self.h5file.root, 'array', a, "byteorder (int)") 794 # Read a subarray (got an array with the machine byteorder) 795 b = array[2:4, 3:5] 796 b = b.byteswap() 797 b = b.newbyteorder() 798 # Set this subarray back to the array 799 array[2:4, 3:5] = b 800 b = b.byteswap() 801 b = b.newbyteorder() 802 # Set this subarray back to the array 803 array[2:4, 3:5] = b 804 # Check that the array is back in the correct byteorder 805 c = array[...] 806 if common.verbose: 807 print("byteorder of array on disk-->", array.byteorder) 808 print("byteorder of subarray-->", b.dtype.byteorder) 809 print("subarray-->", b) 810 print("retrieved array-->", c) 811 self.assertTrue(allequal(a, c)) 812 813 def test12_float_byteorder(self): 814 """Checking setting data with different byteorder in a range (float)""" 815 816 # Save an array with the reversed byteorder on it 817 a = numpy.arange(25, dtype=numpy.float64).reshape(5, 5) 818 a = a.byteswap() 819 a = a.newbyteorder() 820 array = self.h5file.create_array( 821 self.h5file.root, 'array', a, "byteorder (float)") 822 # Read a subarray (got an array with the machine byteorder) 823 b = array[2:4, 3:5] 824 b = b.byteswap() 825 b = b.newbyteorder() 826 # Set this subarray back to the array 827 array[2:4, 3:5] = b 828 b = b.byteswap() 829 b = b.newbyteorder() 830 # Set this subarray back to the array 831 array[2:4, 3:5] = b 832 # Check that the array is back in the correct byteorder 833 c = array[...] 834 if common.verbose: 835 print("byteorder of array on disk-->", array.byteorder) 836 print("byteorder of subarray-->", b.dtype.byteorder) 837 print("subarray-->", b) 838 print("retrieved array-->", c) 839 self.assertTrue(allequal(a, c)) 840 841 842class ComplexNotReopenNotEndianTestCase(UnalignedAndComplexTestCase): 843 endiancheck = False 844 reopen = False 845 846 847class ComplexReopenNotEndianTestCase(UnalignedAndComplexTestCase): 848 endiancheck = False 849 reopen = True 850 851 852class ComplexNotReopenEndianTestCase(UnalignedAndComplexTestCase): 853 endiancheck = True 854 reopen = False 855 856 857class ComplexReopenEndianTestCase(UnalignedAndComplexTestCase): 858 endiancheck = True 859 reopen = True 860 861 862class GroupsArrayTestCase(common.TempFileMixin, TestCase): 863 """This test class checks combinations of arrays with groups.""" 864 865 def test00_iterativeGroups(self): 866 """Checking combinations of arrays with groups.""" 867 868 if common.verbose: 869 print('\n', '-=' * 30) 870 print("Running %s.test00_iterativeGroups..." % 871 self.__class__.__name__) 872 873 # Get the root group 874 group = self.h5file.root 875 876 # Set the type codes to test 877 # The typecodes below does expose an ambiguity that is reported in: 878 # http://projects.scipy.org/scipy/numpy/ticket/283 and 879 # http://projects.scipy.org/scipy/numpy/ticket/290 880 typecodes = ['b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'f', 'd', 881 'F', 'D'] 882 if hasattr(tables, 'Float16Atom'): 883 typecodes.append('e') 884 if hasattr(tables, 'Float96Atom') or hasattr(tables, 'Float128Atom'): 885 typecodes.append('g') 886 if (hasattr(tables, 'Complex192Atom') or 887 hasattr(tables, 'Complex256Atom')): 888 typecodes.append('G') 889 890 for i, typecode in enumerate(typecodes): 891 a = numpy.ones((3,), typecode) 892 dsetname = 'array_' + typecode 893 if common.verbose: 894 print("Creating dataset:", group._g_join(dsetname)) 895 self.h5file.create_array(group, dsetname, a, "Large array") 896 group = self.h5file.create_group(group, 'group' + str(i)) 897 898 # Reopen the file 899 self._reopen() 900 901 # Get the root group 902 group = self.h5file.root 903 904 # Get the metadata on the previosly saved arrays 905 for i in range(len(typecodes)): 906 # Create an array for later comparison 907 a = numpy.ones((3,), typecodes[i]) 908 # Get the dset object hanging from group 909 dset = getattr(group, 'array_' + typecodes[i]) 910 # Get the actual array 911 b = dset.read() 912 if common.verbose: 913 print("Info from dataset:", dset._v_pathname) 914 print(" shape ==>", dset.shape, end=' ') 915 print(" type ==> %s" % dset.atom.dtype) 916 print("Array b read from file. Shape: ==>", b.shape, end=' ') 917 print(". Type ==> %s" % b.dtype) 918 self.assertEqual(a.shape, b.shape) 919 self.assertEqual(a.dtype, b.dtype) 920 self.assertTrue(allequal(a, b)) 921 922 # Iterate over the next group 923 group = getattr(group, 'group' + str(i)) 924 925 def test01_largeRankArrays(self): 926 """Checking creation of large rank arrays (0 < rank <= 32) 927 It also uses arrays ranks which ranges until maxrank. 928 """ 929 930 # maximum level of recursivity (deepest group level) achieved: 931 # maxrank = 32 (for a effective maximum rank of 32) 932 # This limit is due to HDF5 library limitations. 933 minrank = 1 934 maxrank = 32 935 936 if common.verbose: 937 print('\n', '-=' * 30) 938 print("Running %s.test01_largeRankArrays..." % 939 self.__class__.__name__) 940 print("Maximum rank for tested arrays:", maxrank) 941 942 group = self.h5file.root 943 if common.verbose: 944 print("Rank array writing progress: ", end=' ') 945 for rank in range(minrank, maxrank + 1): 946 # Create an array of integers, with incrementally bigger ranges 947 a = numpy.ones((1,) * rank, numpy.int32) 948 if common.verbose: 949 print("%3d," % (rank), end=' ') 950 self.h5file.create_array(group, "array", a, "Rank: %s" % rank) 951 group = self.h5file.create_group(group, 'group' + str(rank)) 952 953 # Reopen the file 954 self._reopen() 955 956 group = self.h5file.root 957 if common.verbose: 958 print() 959 print("Rank array reading progress: ") 960 # Get the metadata on the previosly saved arrays 961 for rank in range(minrank, maxrank + 1): 962 # Create an array for later comparison 963 a = numpy.ones((1,) * rank, numpy.int32) 964 # Get the actual array 965 b = group.array.read() 966 if common.verbose: 967 print("%3d," % (rank), end=' ') 968 if common.verbose and not allequal(a, b): 969 print("Info from dataset:", group.array._v_pathname) 970 print(" Shape: ==>", group.array.shape, end=' ') 971 print(" typecode ==> %c" % group.array.typecode) 972 print("Array b read from file. Shape: ==>", b.shape, end=' ') 973 print(". Type ==> %c" % b.dtype) 974 975 self.assertEqual(a.shape, b.shape) 976 self.assertEqual(a.dtype, b.dtype) 977 self.assertTrue(allequal(a, b)) 978 979 # print(self.h5file) 980 # Iterate over the next group 981 group = self.h5file.get_node(group, 'group' + str(rank)) 982 983 if common.verbose: 984 print() # This flush the stdout buffer 985 986 987class CopyTestCase(common.TempFileMixin, TestCase): 988 989 def test01_copy(self): 990 """Checking Array.copy() method.""" 991 992 if common.verbose: 993 print('\n', '-=' * 30) 994 print("Running %s.test01_copy..." % self.__class__.__name__) 995 996 # Create an Array 997 arr = numpy.array([[456, 2], [3, 457]], dtype='int16') 998 array1 = self.h5file.create_array( 999 self.h5file.root, 'array1', arr, "title array1") 1000 1001 # Copy to another Array 1002 array2 = array1.copy('/', 'array2') 1003 1004 if self.close: 1005 if common.verbose: 1006 print("(closing file version)") 1007 self._reopen() 1008 array1 = self.h5file.root.array1 1009 array2 = self.h5file.root.array2 1010 1011 if common.verbose: 1012 print("array1-->", array1.read()) 1013 print("array2-->", array2.read()) 1014 # print("dirs-->", dir(array1), dir(array2)) 1015 print("attrs array1-->", repr(array1.attrs)) 1016 print("attrs array2-->", repr(array2.attrs)) 1017 1018 # Check that all the elements are equal 1019 self.assertTrue(allequal(array1.read(), array2.read())) 1020 1021 # Assert other properties in array 1022 self.assertEqual(array1.nrows, array2.nrows) 1023 self.assertEqual(array1.flavor, array2.flavor) 1024 self.assertEqual(array1.atom.dtype, array2.atom.dtype) 1025 self.assertEqual(array1.title, array2.title) 1026 1027 def test02_copy(self): 1028 """Checking Array.copy() method (where specified)""" 1029 1030 if common.verbose: 1031 print('\n', '-=' * 30) 1032 print("Running %s.test02_copy..." % self.__class__.__name__) 1033 1034 # Create an Array 1035 arr = numpy.array([[456, 2], [3, 457]], dtype='int16') 1036 array1 = self.h5file.create_array( 1037 self.h5file.root, 'array1', arr, "title array1") 1038 1039 # Copy to another Array 1040 group1 = self.h5file.create_group("/", "group1") 1041 array2 = array1.copy(group1, 'array2') 1042 1043 if self.close: 1044 if common.verbose: 1045 print("(closing file version)") 1046 self._reopen() 1047 array1 = self.h5file.root.array1 1048 array2 = self.h5file.root.group1.array2 1049 1050 if common.verbose: 1051 print("array1-->", array1.read()) 1052 print("array2-->", array2.read()) 1053 # print("dirs-->", dir(array1), dir(array2)) 1054 print("attrs array1-->", repr(array1.attrs)) 1055 print("attrs array2-->", repr(array2.attrs)) 1056 1057 # Check that all the elements are equal 1058 self.assertTrue(allequal(array1.read(), array2.read())) 1059 1060 # Assert other properties in array 1061 self.assertEqual(array1.nrows, array2.nrows) 1062 self.assertEqual(array1.flavor, array2.flavor) 1063 self.assertEqual(array1.atom.dtype, array2.atom.dtype) 1064 self.assertEqual(array1.title, array2.title) 1065 1066 def test03_copy(self): 1067 """Checking Array.copy() method (checking title copying)""" 1068 1069 if common.verbose: 1070 print('\n', '-=' * 30) 1071 print("Running %s.test04_copy..." % self.__class__.__name__) 1072 1073 # Create an Array 1074 arr = numpy.array([[456, 2], [3, 457]], dtype='int16') 1075 array1 = self.h5file.create_array( 1076 self.h5file.root, 'array1', arr, "title array1") 1077 # Append some user attrs 1078 array1.attrs.attr1 = "attr1" 1079 array1.attrs.attr2 = 2 1080 # Copy it to another Array 1081 array2 = array1.copy('/', 'array2', title="title array2") 1082 1083 if self.close: 1084 if common.verbose: 1085 print("(closing file version)") 1086 self._reopen() 1087 array1 = self.h5file.root.array1 1088 array2 = self.h5file.root.array2 1089 1090 # Assert user attributes 1091 if common.verbose: 1092 print("title of destination array-->", array2.title) 1093 self.assertEqual(array2.title, "title array2") 1094 1095 def test04_copy(self): 1096 """Checking Array.copy() method (user attributes copied)""" 1097 1098 if common.verbose: 1099 print('\n', '-=' * 30) 1100 print("Running %s.test05_copy..." % self.__class__.__name__) 1101 1102 # Create an Array 1103 arr = numpy.array([[456, 2], [3, 457]], dtype='int16') 1104 array1 = self.h5file.create_array( 1105 self.h5file.root, 'array1', arr, "title array1") 1106 # Append some user attrs 1107 array1.attrs.attr1 = "attr1" 1108 array1.attrs.attr2 = 2 1109 # Copy it to another Array 1110 array2 = array1.copy('/', 'array2', copyuserattrs=1) 1111 1112 if self.close: 1113 if common.verbose: 1114 print("(closing file version)") 1115 self._reopen() 1116 array1 = self.h5file.root.array1 1117 array2 = self.h5file.root.array2 1118 1119 if common.verbose: 1120 print("attrs array1-->", repr(array1.attrs)) 1121 print("attrs array2-->", repr(array2.attrs)) 1122 1123 # Assert user attributes 1124 self.assertEqual(array2.attrs.attr1, "attr1") 1125 self.assertEqual(array2.attrs.attr2, 2) 1126 1127 def test04b_copy(self): 1128 """Checking Array.copy() method (user attributes not copied)""" 1129 1130 if common.verbose: 1131 print('\n', '-=' * 30) 1132 print("Running %s.test05b_copy..." % self.__class__.__name__) 1133 1134 # Create an Array 1135 arr = numpy.array([[456, 2], [3, 457]], dtype='int16') 1136 array1 = self.h5file.create_array( 1137 self.h5file.root, 'array1', arr, "title array1") 1138 # Append some user attrs 1139 array1.attrs.attr1 = "attr1" 1140 array1.attrs.attr2 = 2 1141 # Copy it to another Array 1142 array2 = array1.copy('/', 'array2', copyuserattrs=0) 1143 1144 if self.close: 1145 if common.verbose: 1146 print("(closing file version)") 1147 self._reopen() 1148 array1 = self.h5file.root.array1 1149 array2 = self.h5file.root.array2 1150 1151 if common.verbose: 1152 print("attrs array1-->", repr(array1.attrs)) 1153 print("attrs array2-->", repr(array2.attrs)) 1154 1155 # Assert user attributes 1156 self.assertEqual(hasattr(array2.attrs, "attr1"), 0) 1157 self.assertEqual(hasattr(array2.attrs, "attr2"), 0) 1158 1159 1160class CloseCopyTestCase(CopyTestCase): 1161 close = 1 1162 1163 1164class OpenCopyTestCase(CopyTestCase): 1165 close = 0 1166 1167 1168class CopyIndexTestCase(common.TempFileMixin, TestCase): 1169 1170 def test01_index(self): 1171 """Checking Array.copy() method with indexes.""" 1172 1173 if common.verbose: 1174 print('\n', '-=' * 30) 1175 print("Running %s.test01_index..." % self.__class__.__name__) 1176 1177 # Create a numpy 1178 r = numpy.arange(200, dtype='int32') 1179 r.shape = (100, 2) 1180 # Save it in a array: 1181 array1 = self.h5file.create_array( 1182 self.h5file.root, 'array1', r, "title array1") 1183 1184 # Copy to another array 1185 array2 = array1.copy("/", 'array2', 1186 start=self.start, 1187 stop=self.stop, 1188 step=self.step) 1189 if common.verbose: 1190 print("array1-->", array1.read()) 1191 print("array2-->", array2.read()) 1192 print("attrs array1-->", repr(array1.attrs)) 1193 print("attrs array2-->", repr(array2.attrs)) 1194 1195 # Check that all the elements are equal 1196 r2 = r[self.start:self.stop:self.step] 1197 self.assertTrue(allequal(r2, array2.read())) 1198 1199 # Assert the number of rows in array 1200 if common.verbose: 1201 print("nrows in array2-->", array2.nrows) 1202 print("and it should be-->", r2.shape[0]) 1203 self.assertEqual(r2.shape[0], array2.nrows) 1204 1205 def test02_indexclosef(self): 1206 """Checking Array.copy() method with indexes (close file version)""" 1207 1208 if common.verbose: 1209 print('\n', '-=' * 30) 1210 print("Running %s.test02_indexclosef..." % self.__class__.__name__) 1211 1212 # Create a numpy 1213 r = numpy.arange(200, dtype='int32') 1214 r.shape = (100, 2) 1215 # Save it in a array: 1216 array1 = self.h5file.create_array( 1217 self.h5file.root, 'array1', r, "title array1") 1218 1219 # Copy to another array 1220 array2 = array1.copy("/", 'array2', 1221 start=self.start, 1222 stop=self.stop, 1223 step=self.step) 1224 # Close and reopen the file 1225 self._reopen() 1226 array1 = self.h5file.root.array1 1227 array2 = self.h5file.root.array2 1228 1229 if common.verbose: 1230 print("array1-->", array1.read()) 1231 print("array2-->", array2.read()) 1232 print("attrs array1-->", repr(array1.attrs)) 1233 print("attrs array2-->", repr(array2.attrs)) 1234 1235 # Check that all the elements are equal 1236 r2 = r[self.start:self.stop:self.step] 1237 self.assertTrue(allequal(r2, array2.read())) 1238 1239 # Assert the number of rows in array 1240 if common.verbose: 1241 print("nrows in array2-->", array2.nrows) 1242 print("and it should be-->", r2.shape[0]) 1243 self.assertEqual(r2.shape[0], array2.nrows) 1244 1245 1246class CopyIndex1TestCase(CopyIndexTestCase): 1247 start = 0 1248 stop = 7 1249 step = 1 1250 1251 1252class CopyIndex2TestCase(CopyIndexTestCase): 1253 start = 0 1254 stop = -1 1255 step = 1 1256 1257 1258class CopyIndex3TestCase(CopyIndexTestCase): 1259 start = 1 1260 stop = 7 1261 step = 1 1262 1263 1264class CopyIndex4TestCase(CopyIndexTestCase): 1265 start = 0 1266 stop = 6 1267 step = 1 1268 1269 1270class CopyIndex5TestCase(CopyIndexTestCase): 1271 start = 3 1272 stop = 7 1273 step = 1 1274 1275 1276class CopyIndex6TestCase(CopyIndexTestCase): 1277 start = 3 1278 stop = 6 1279 step = 2 1280 1281 1282class CopyIndex7TestCase(CopyIndexTestCase): 1283 start = 0 1284 stop = 7 1285 step = 10 1286 1287 1288class CopyIndex8TestCase(CopyIndexTestCase): 1289 start = 6 1290 stop = -1 # Negative values means starting from the end 1291 step = 1 1292 1293 1294class CopyIndex9TestCase(CopyIndexTestCase): 1295 start = 3 1296 stop = 4 1297 step = 1 1298 1299 1300class CopyIndex10TestCase(CopyIndexTestCase): 1301 start = 3 1302 stop = 4 1303 step = 2 1304 1305 1306class CopyIndex11TestCase(CopyIndexTestCase): 1307 start = -3 1308 stop = -1 1309 step = 2 1310 1311 1312class CopyIndex12TestCase(CopyIndexTestCase): 1313 start = -1 # Should point to the last element 1314 stop = None # None should mean the last element (including it) 1315 step = 1 1316 1317 1318class GetItemTestCase(common.TempFileMixin, TestCase): 1319 1320 def test00_single(self): 1321 """Single element access (character types)""" 1322 1323 # Create the array under root and name 'somearray' 1324 a = self.charList 1325 arr = self.h5file.create_array( 1326 self.h5file.root, 'somearray', a, "Some array") 1327 1328 if self.close: 1329 self._reopen() 1330 arr = self.h5file.root.somearray 1331 1332 # Get and compare an element 1333 if common.verbose: 1334 print("Original first element:", a[0], type(a[0])) 1335 print("Read first element:", arr[0], type(arr[0])) 1336 self.assertTrue(allequal(a[0], arr[0])) 1337 self.assertEqual(type(a[0]), type(arr[0])) 1338 1339 def test01_single(self): 1340 """Single element access (numerical types)""" 1341 1342 # Create the array under root and name 'somearray' 1343 a = self.numericalList 1344 arr = self.h5file.create_array( 1345 self.h5file.root, 'somearray', a, "Some array") 1346 1347 if self.close: 1348 self._reopen() 1349 arr = self.h5file.root.somearray 1350 1351 # Get and compare an element 1352 if common.verbose: 1353 print("Original first element:", a[0], type(a[0])) 1354 print("Read first element:", arr[0], type(arr[0])) 1355 self.assertEqual(a[0], arr[0]) 1356 self.assertEqual(type(a[0]), type(arr[0])) 1357 1358 def test02_range(self): 1359 """Range element access (character types)""" 1360 1361 # Create the array under root and name 'somearray' 1362 a = self.charListME 1363 arr = self.h5file.create_array( 1364 self.h5file.root, 'somearray', a, "Some array") 1365 1366 if self.close: 1367 self._reopen() 1368 arr = self.h5file.root.somearray 1369 1370 # Get and compare an element 1371 if common.verbose: 1372 print("Original elements:", a[1:4]) 1373 print("Read elements:", arr[1:4]) 1374 self.assertTrue(allequal(a[1:4], arr[1:4])) 1375 1376 def test03_range(self): 1377 """Range element access (numerical types)""" 1378 1379 # Create the array under root and name 'somearray' 1380 a = self.numericalListME 1381 arr = self.h5file.create_array( 1382 self.h5file.root, 'somearray', a, "Some array") 1383 1384 if self.close: 1385 self._reopen() 1386 arr = self.h5file.root.somearray 1387 1388 # Get and compare an element 1389 if common.verbose: 1390 print("Original elements:", a[1:4]) 1391 print("Read elements:", arr[1:4]) 1392 self.assertTrue(allequal(a[1:4], arr[1:4])) 1393 1394 def test04_range(self): 1395 """Range element access, strided (character types)""" 1396 1397 # Create the array under root and name 'somearray' 1398 a = self.charListME 1399 arr = self.h5file.create_array( 1400 self.h5file.root, 'somearray', a, "Some array") 1401 1402 if self.close: 1403 self._reopen() 1404 arr = self.h5file.root.somearray 1405 1406 # Get and compare an element 1407 if common.verbose: 1408 print("Original elements:", a[1:4:2]) 1409 print("Read elements:", arr[1:4:2]) 1410 self.assertTrue(allequal(a[1:4:2], arr[1:4:2])) 1411 1412 def test05_range(self): 1413 """Range element access, strided (numerical types)""" 1414 1415 # Create the array under root and name 'somearray' 1416 a = self.numericalListME 1417 arr = self.h5file.create_array( 1418 self.h5file.root, 'somearray', a, "Some array") 1419 1420 if self.close: 1421 self._reopen() 1422 arr = self.h5file.root.somearray 1423 1424 # Get and compare an element 1425 if common.verbose: 1426 print("Original elements:", a[1:4:2]) 1427 print("Read elements:", arr[1:4:2]) 1428 self.assertTrue(allequal(a[1:4:2], arr[1:4:2])) 1429 1430 def test06_negativeIndex(self): 1431 """Negative Index element access (character types)""" 1432 1433 # Create the array under root and name 'somearray' 1434 a = self.charListME 1435 arr = self.h5file.create_array( 1436 self.h5file.root, 'somearray', a, "Some array") 1437 1438 if self.close: 1439 self._reopen() 1440 arr = self.h5file.root.somearray 1441 1442 # Get and compare an element 1443 if common.verbose: 1444 print("Original last element:", a[-1]) 1445 print("Read last element:", arr[-1]) 1446 self.assertTrue(allequal(a[-1], arr[-1])) 1447 1448 def test07_negativeIndex(self): 1449 """Negative Index element access (numerical types)""" 1450 1451 # Create the array under root and name 'somearray' 1452 a = self.numericalListME 1453 arr = self.h5file.create_array( 1454 self.h5file.root, 'somearray', a, "Some array") 1455 1456 if self.close: 1457 self._reopen() 1458 arr = self.h5file.root.somearray 1459 1460 # Get and compare an element 1461 if common.verbose: 1462 print("Original before last element:", a[-2]) 1463 print("Read before last element:", arr[-2]) 1464 if isinstance(a[-2], numpy.ndarray): 1465 self.assertTrue(allequal(a[-2], arr[-2])) 1466 else: 1467 self.assertEqual(a[-2], arr[-2]) 1468 1469 def test08_negativeRange(self): 1470 """Negative range element access (character types)""" 1471 1472 # Create the array under root and name 'somearray' 1473 a = self.charListME 1474 arr = self.h5file.create_array( 1475 self.h5file.root, 'somearray', a, "Some array") 1476 1477 if self.close: 1478 self._reopen() 1479 arr = self.h5file.root.somearray 1480 1481 # Get and compare an element 1482 if common.verbose: 1483 print("Original last elements:", a[-4:-1]) 1484 print("Read last elements:", arr[-4:-1]) 1485 self.assertTrue(allequal(a[-4:-1], arr[-4:-1])) 1486 1487 def test09_negativeRange(self): 1488 """Negative range element access (numerical types)""" 1489 1490 # Create the array under root and name 'somearray' 1491 a = self.numericalListME 1492 arr = self.h5file.create_array( 1493 self.h5file.root, 'somearray', a, "Some array") 1494 1495 if self.close: 1496 self._reopen() 1497 arr = self.h5file.root.somearray 1498 1499 # Get and compare an element 1500 if common.verbose: 1501 print("Original last elements:", a[-4:-1]) 1502 print("Read last elements:", arr[-4:-1]) 1503 self.assertTrue(allequal(a[-4:-1], arr[-4:-1])) 1504 1505 1506class GI1NATestCase(GetItemTestCase, TestCase): 1507 title = "Rank-1 case 1" 1508 numericalList = numpy.array([3]) 1509 numericalListME = numpy.array([3, 2, 1, 0, 4, 5, 6]) 1510 charList = numpy.array(["3"], 'S') 1511 charListME = numpy.array( 1512 ["321", "221", "121", "021", "421", "521", "621"], 'S') 1513 1514 1515class GI1NAOpenTestCase(GI1NATestCase): 1516 close = 0 1517 1518 1519class GI1NACloseTestCase(GI1NATestCase): 1520 close = 1 1521 1522 1523class GI2NATestCase(GetItemTestCase): 1524 # A more complex example 1525 title = "Rank-1,2 case 2" 1526 numericalList = numpy.array([3, 4]) 1527 numericalListME = numpy.array([[3, 2, 1, 0, 4, 5, 6], 1528 [2, 1, 0, 4, 5, 6, 7], 1529 [4, 3, 2, 1, 0, 4, 5], 1530 [3, 2, 1, 0, 4, 5, 6], 1531 [3, 2, 1, 0, 4, 5, 6]]) 1532 1533 charList = numpy.array(["a", "b"], 'S') 1534 charListME = numpy.array( 1535 [["321", "221", "121", "021", "421", "521", "621"], 1536 ["21", "21", "11", "02", "42", "21", "61"], 1537 ["31", "21", "12", "21", "41", "51", "621"], 1538 ["321", "221", "121", "021", 1539 "421", "521", "621"], 1540 ["3241", "2321", "13216", 1541 "0621", "4421", "5421", "a621"], 1542 ["a321", "s221", "d121", "g021", "b421", "5vvv21", "6zxzxs21"]], 'S') 1543 1544 1545class GI2NAOpenTestCase(GI2NATestCase): 1546 close = 0 1547 1548 1549class GI2NACloseTestCase(GI2NATestCase): 1550 close = 1 1551 1552 1553class SetItemTestCase(common.TempFileMixin, TestCase): 1554 1555 def test00_single(self): 1556 """Single element update (character types)""" 1557 1558 # Create the array under root and name 'somearray' 1559 a = self.charList 1560 arr = self.h5file.create_array( 1561 self.h5file.root, 'somearray', a, "Some array") 1562 1563 if self.close: 1564 self._reopen('a') 1565 arr = self.h5file.root.somearray 1566 1567 # Modify a single element of a and arr: 1568 a[0] = b"b" 1569 arr[0] = b"b" 1570 1571 # Get and compare an element 1572 if common.verbose: 1573 print("Original first element:", a[0]) 1574 print("Read first element:", arr[0]) 1575 self.assertTrue(allequal(a[0], arr[0])) 1576 1577 def test01_single(self): 1578 """Single element update (numerical types)""" 1579 1580 # Create the array under root and name 'somearray' 1581 a = self.numericalList 1582 arr = self.h5file.create_array( 1583 self.h5file.root, 'somearray', a, "Some array") 1584 1585 if self.close: 1586 self._reopen('a') 1587 arr = self.h5file.root.somearray 1588 1589 # Modify elements of a and arr: 1590 a[0] = 333 1591 arr[0] = 333 1592 1593 # Get and compare an element 1594 if common.verbose: 1595 print("Original first element:", a[0]) 1596 print("Read first element:", arr[0]) 1597 self.assertEqual(a[0], arr[0]) 1598 1599 def test02_range(self): 1600 """Range element update (character types)""" 1601 1602 # Create the array under root and name 'somearray' 1603 a = self.charListME 1604 arr = self.h5file.create_array( 1605 self.h5file.root, 'somearray', a, "Some array") 1606 1607 if self.close: 1608 self._reopen('a') 1609 arr = self.h5file.root.somearray 1610 1611 # Modify elements of a and arr: 1612 a[1:3] = b"xXx" 1613 arr[1:3] = b"xXx" 1614 1615 # Get and compare an element 1616 if common.verbose: 1617 print("Original elements:", a[1:4]) 1618 print("Read elements:", arr[1:4]) 1619 self.assertTrue(allequal(a[1:4], arr[1:4])) 1620 1621 def test03_range(self): 1622 """Range element update (numerical types)""" 1623 1624 # Create the array under root and name 'somearray' 1625 a = self.numericalListME 1626 arr = self.h5file.create_array( 1627 self.h5file.root, 'somearray', a, "Some array") 1628 1629 if self.close: 1630 self._reopen('a') 1631 arr = self.h5file.root.somearray 1632 1633 # Modify elements of a and arr: 1634 s = slice(1, 3, None) 1635 rng = numpy.arange(a[s].size)*2 + 3 1636 rng.shape = a[s].shape 1637 a[s] = rng 1638 arr[s] = rng 1639 1640 # Get and compare an element 1641 if common.verbose: 1642 print("Original elements:", a[1:4]) 1643 print("Read elements:", arr[1:4]) 1644 self.assertTrue(allequal(a[1:4], arr[1:4])) 1645 1646 def test04_range(self): 1647 """Range element update, strided (character types)""" 1648 1649 # Create the array under root and name 'somearray' 1650 a = self.charListME 1651 arr = self.h5file.create_array( 1652 self.h5file.root, 'somearray', a, "Some array") 1653 1654 if self.close: 1655 self._reopen('a') 1656 arr = self.h5file.root.somearray 1657 1658 # Modify elements of a and arr: 1659 s = slice(1, 4, 2) 1660 a[s] = b"xXx" 1661 arr[s] = b"xXx" 1662 1663 # Get and compare an element 1664 if common.verbose: 1665 print("Original elements:", a[1:4:2]) 1666 print("Read elements:", arr[1:4:2]) 1667 self.assertTrue(allequal(a[1:4:2], arr[1:4:2])) 1668 1669 def test05_range(self): 1670 """Range element update, strided (numerical types)""" 1671 1672 # Create the array under root and name 'somearray' 1673 a = self.numericalListME 1674 arr = self.h5file.create_array( 1675 self.h5file.root, 'somearray', a, "Some array") 1676 1677 if self.close: 1678 self._reopen('a') 1679 arr = self.h5file.root.somearray 1680 1681 # Modify elements of a and arr: 1682 s = slice(1, 4, 2) 1683 rng = numpy.arange(a[s].size)*2 + 3 1684 rng.shape = a[s].shape 1685 a[s] = rng 1686 arr[s] = rng 1687 1688 # Get and compare an element 1689 if common.verbose: 1690 print("Original elements:", a[1:4:2]) 1691 print("Read elements:", arr[1:4:2]) 1692 self.assertTrue(allequal(a[1:4:2], arr[1:4:2])) 1693 1694 def test06_negativeIndex(self): 1695 """Negative Index element update (character types)""" 1696 1697 # Create the array under root and name 'somearray' 1698 a = self.charListME 1699 arr = self.h5file.create_array( 1700 self.h5file.root, 'somearray', a, "Some array") 1701 1702 if self.close: 1703 self._reopen('a') 1704 arr = self.h5file.root.somearray 1705 1706 # Modify elements of a and arr: 1707 s = -1 1708 a[s] = b"xXx" 1709 arr[s] = b"xXx" 1710 1711 # Get and compare an element 1712 if common.verbose: 1713 print("Original last element:", a[-1]) 1714 print("Read last element:", arr[-1]) 1715 self.assertTrue(allequal(a[-1], arr[-1])) 1716 1717 def test07_negativeIndex(self): 1718 """Negative Index element update (numerical types)""" 1719 1720 # Create the array under root and name 'somearray' 1721 a = self.numericalListME 1722 arr = self.h5file.create_array( 1723 self.h5file.root, 'somearray', a, "Some array") 1724 1725 if self.close: 1726 self._reopen('a') 1727 arr = self.h5file.root.somearray 1728 1729 # Modify elements of a and arr: 1730 s = -2 1731 a[s] = a[s]*2 + 3 1732 arr[s] = arr[s]*2 + 3 1733 1734 # Get and compare an element 1735 if common.verbose: 1736 print("Original before last element:", a[-2]) 1737 print("Read before last element:", arr[-2]) 1738 if isinstance(a[-2], numpy.ndarray): 1739 self.assertTrue(allequal(a[-2], arr[-2])) 1740 else: 1741 self.assertEqual(a[-2], arr[-2]) 1742 1743 def test08_negativeRange(self): 1744 """Negative range element update (character types)""" 1745 1746 # Create the array under root and name 'somearray' 1747 a = self.charListME 1748 arr = self.h5file.create_array( 1749 self.h5file.root, 'somearray', a, "Some array") 1750 1751 if self.close: 1752 self._reopen('a') 1753 arr = self.h5file.root.somearray 1754 1755 # Modify elements of a and arr: 1756 s = slice(-4, -1, None) 1757 a[s] = b"xXx" 1758 arr[s] = b"xXx" 1759 1760 # Get and compare an element 1761 if common.verbose: 1762 print("Original last elements:", a[-4:-1]) 1763 print("Read last elements:", arr[-4:-1]) 1764 self.assertTrue(allequal(a[-4:-1], arr[-4:-1])) 1765 1766 def test09_negativeRange(self): 1767 """Negative range element update (numerical types)""" 1768 1769 # Create the array under root and name 'somearray' 1770 a = self.numericalListME 1771 arr = self.h5file.create_array( 1772 self.h5file.root, 'somearray', a, "Some array") 1773 1774 if self.close: 1775 self._reopen('a') 1776 arr = self.h5file.root.somearray 1777 1778 # Modify elements of a and arr: 1779 s = slice(-3, -1, None) 1780 rng = numpy.arange(a[s].size)*2 + 3 1781 rng.shape = a[s].shape 1782 a[s] = rng 1783 arr[s] = rng 1784 1785 # Get and compare an element 1786 if common.verbose: 1787 print("Original last elements:", a[-4:-1]) 1788 print("Read last elements:", arr[-4:-1]) 1789 self.assertTrue(allequal(a[-4:-1], arr[-4:-1])) 1790 1791 def test10_outOfRange(self): 1792 """Out of range update (numerical types)""" 1793 1794 # Create the array under root and name 'somearray' 1795 a = self.numericalListME 1796 arr = self.h5file.create_array( 1797 self.h5file.root, 'somearray', a, "Some array") 1798 1799 if self.close: 1800 self._reopen('a') 1801 arr = self.h5file.root.somearray 1802 1803 # Modify elements of arr that are out of range: 1804 s = slice(1, a.shape[0]+1, None) 1805 s2 = slice(1, 1000, None) 1806 rng = numpy.arange(a[s].size)*2 + 3 1807 rng.shape = a[s].shape 1808 a[s] = rng 1809 rng2 = numpy.arange(a[s2].size)*2 + 3 1810 rng2.shape = a[s2].shape 1811 arr[s2] = rng2 1812 1813 # Get and compare an element 1814 if common.verbose: 1815 print("Original last elements:", a[-4:-1]) 1816 print("Read last elements:", arr[-4:-1]) 1817 self.assertTrue(allequal(a[-4:-1], arr[-4:-1])) 1818 1819 1820class SI1NATestCase(SetItemTestCase, TestCase): 1821 title = "Rank-1 case 1" 1822 numericalList = numpy.array([3]) 1823 numericalListME = numpy.array([3, 2, 1, 0, 4, 5, 6]) 1824 charList = numpy.array(["3"], 'S') 1825 charListME = numpy.array( 1826 ["321", "221", "121", "021", "421", "521", "621"], 'S') 1827 1828 1829class SI1NAOpenTestCase(SI1NATestCase): 1830 close = 0 1831 1832 1833class SI1NACloseTestCase(SI1NATestCase): 1834 close = 1 1835 1836 1837class SI2NATestCase(SetItemTestCase): 1838 # A more complex example 1839 title = "Rank-1,2 case 2" 1840 numericalList = numpy.array([3, 4]) 1841 numericalListME = numpy.array([[3, 2, 1, 0, 4, 5, 6], 1842 [2, 1, 0, 4, 5, 6, 7], 1843 [4, 3, 2, 1, 0, 4, 5], 1844 [3, 2, 1, 0, 4, 5, 6], 1845 [3, 2, 1, 0, 4, 5, 6]]) 1846 1847 charList = numpy.array(["a", "b"], 'S') 1848 charListME = numpy.array( 1849 [["321", "221", "121", "021", "421", "521", "621"], 1850 ["21", "21", "11", "02", "42", "21", "61"], 1851 ["31", "21", "12", "21", "41", "51", "621"], 1852 ["321", "221", "121", "021", 1853 "421", "521", "621"], 1854 ["3241", "2321", "13216", 1855 "0621", "4421", "5421", "a621"], 1856 ["a321", "s221", "d121", "g021", "b421", "5vvv21", "6zxzxs21"]], 'S') 1857 1858 1859class SI2NAOpenTestCase(SI2NATestCase): 1860 close = 0 1861 1862 1863class SI2NACloseTestCase(SI2NATestCase): 1864 close = 1 1865 1866 1867class GeneratorTestCase(common.TempFileMixin, TestCase): 1868 1869 def test00a_single(self): 1870 """Testing generator access to Arrays, single elements (char)""" 1871 1872 # Create the array under root and name 'somearray' 1873 a = self.charList 1874 arr = self.h5file.create_array( 1875 self.h5file.root, 'somearray', a, "Some array") 1876 1877 if self.close: 1878 self._reopen() 1879 arr = self.h5file.root.somearray 1880 1881 # Get and compare an element 1882 ga = [i for i in a] 1883 garr = [i for i in arr] 1884 if common.verbose: 1885 print("Result of original iterator:", ga) 1886 print("Result of read generator:", garr) 1887 self.assertEqual(ga, garr) 1888 1889 def test00b_me(self): 1890 """Testing generator access to Arrays, multiple elements (char)""" 1891 1892 # Create the array under root and name 'somearray' 1893 a = self.charListME 1894 arr = self.h5file.create_array( 1895 self.h5file.root, 'somearray', a, "Some array") 1896 1897 if self.close: 1898 self._reopen() 1899 arr = self.h5file.root.somearray 1900 1901 # Get and compare an element 1902 ga = [i for i in a] 1903 garr = [i for i in arr] 1904 1905 if common.verbose: 1906 print("Result of original iterator:", ga) 1907 print("Result of read generator:", garr) 1908 for i in range(len(ga)): 1909 self.assertTrue(allequal(ga[i], garr[i])) 1910 1911 def test01a_single(self): 1912 """Testing generator access to Arrays, single elements (numeric)""" 1913 1914 # Create the array under root and name 'somearray' 1915 a = self.numericalList 1916 arr = self.h5file.create_array( 1917 self.h5file.root, 'somearray', a, "Some array") 1918 1919 if self.close: 1920 self._reopen() 1921 arr = self.h5file.root.somearray 1922 1923 # Get and compare an element 1924 ga = [i for i in a] 1925 garr = [i for i in arr] 1926 if common.verbose: 1927 print("Result of original iterator:", ga) 1928 print("Result of read generator:", garr) 1929 self.assertEqual(ga, garr) 1930 1931 def test01b_me(self): 1932 """Testing generator access to Arrays, multiple elements (numeric)""" 1933 1934 # Create the array under root and name 'somearray' 1935 a = self.numericalListME 1936 arr = self.h5file.create_array( 1937 self.h5file.root, 'somearray', a, "Some array") 1938 1939 if self.close: 1940 self._reopen() 1941 arr = self.h5file.root.somearray 1942 1943 # Get and compare an element 1944 ga = [i for i in a] 1945 garr = [i for i in arr] 1946 if common.verbose: 1947 print("Result of original iterator:", ga) 1948 print("Result of read generator:", garr) 1949 for i in range(len(ga)): 1950 self.assertTrue(allequal(ga[i], garr[i])) 1951 1952 1953class GE1NATestCase(GeneratorTestCase): 1954 title = "Rank-1 case 1" 1955 numericalList = numpy.array([3]) 1956 numericalListME = numpy.array([3, 2, 1, 0, 4, 5, 6]) 1957 charList = numpy.array(["3"], 'S') 1958 charListME = numpy.array( 1959 ["321", "221", "121", "021", "421", "521", "621"], 'S') 1960 1961 1962class GE1NAOpenTestCase(GE1NATestCase): 1963 close = 0 1964 1965 1966class GE1NACloseTestCase(GE1NATestCase): 1967 close = 1 1968 1969 1970class GE2NATestCase(GeneratorTestCase): 1971 # A more complex example 1972 title = "Rank-1,2 case 2" 1973 numericalList = numpy.array([3, 4]) 1974 numericalListME = numpy.array([[3, 2, 1, 0, 4, 5, 6], 1975 [2, 1, 0, 4, 5, 6, 7], 1976 [4, 3, 2, 1, 0, 4, 5], 1977 [3, 2, 1, 0, 4, 5, 6], 1978 [3, 2, 1, 0, 4, 5, 6]]) 1979 1980 charList = numpy.array(["a", "b"], 'S') 1981 charListME = numpy.array( 1982 [["321", "221", "121", "021", "421", "521", "621"], 1983 ["21", "21", "11", "02", "42", "21", "61"], 1984 ["31", "21", "12", "21", "41", "51", "621"], 1985 ["321", "221", "121", "021", 1986 "421", "521", "621"], 1987 ["3241", "2321", "13216", 1988 "0621", "4421", "5421", "a621"], 1989 ["a321", "s221", "d121", "g021", "b421", "5vvv21", "6zxzxs21"]], 'S') 1990 1991 1992class GE2NAOpenTestCase(GE2NATestCase): 1993 close = 0 1994 1995 1996class GE2NACloseTestCase(GE2NATestCase): 1997 close = 1 1998 1999 2000class NonHomogeneousTestCase(common.TempFileMixin, TestCase): 2001 def test(self): 2002 """Test for creation of non-homogeneous arrays.""" 2003 2004 # This checks ticket #12. 2005 self.assertRaises((ValueError, TypeError), 2006 self.h5file.create_array, '/', 'test', [1, [2, 3]]) 2007 self.assertRaises(NoSuchNodeError, self.h5file.remove_node, '/test') 2008 2009 2010class TruncateTestCase(common.TempFileMixin, TestCase): 2011 def test(self): 2012 """Test for unability to truncate Array objects.""" 2013 2014 array1 = self.h5file.create_array('/', 'array1', [0, 2]) 2015 self.assertRaises(TypeError, array1.truncate, 0) 2016 2017 2018class PointSelectionTestCase(common.TempFileMixin, TestCase): 2019 2020 def setUp(self): 2021 super(PointSelectionTestCase, self).setUp() 2022 # Limits for selections 2023 self.limits = [ 2024 (0, 1), # just one element 2025 (20, -10), # no elements 2026 (-10, 4), # several elements 2027 (0, 10), # several elements (again) 2028 ] 2029 2030 # Create a sample array 2031 size = numpy.prod(self.shape) 2032 nparr = numpy.arange(size, dtype=numpy.int32).reshape(self.shape) 2033 self.nparr = nparr 2034 self.tbarr = self.h5file.create_array(self.h5file.root, 'array', nparr) 2035 2036 def test01a_read(self): 2037 """Test for point-selections (read, boolean keys).""" 2038 2039 nparr = self.nparr 2040 tbarr = self.tbarr 2041 for value1, value2 in self.limits: 2042 key = (nparr >= value1) & (nparr < value2) 2043 if common.verbose: 2044 print("Selection to test:", key) 2045 a = nparr[key] 2046 b = tbarr[key] 2047 self.assertTrue( 2048 numpy.alltrue(a == b), 2049 "NumPy array and PyTables selections does not match.") 2050 2051 def test01b_read(self): 2052 """Test for point-selections (read, integer keys).""" 2053 2054 nparr = self.nparr 2055 tbarr = self.tbarr 2056 for value1, value2 in self.limits: 2057 key = numpy.where((nparr >= value1) & (nparr < value2)) 2058 if common.verbose: 2059 print("Selection to test:", key) 2060 a = nparr[key] 2061 b = tbarr[key] 2062 self.assertTrue( 2063 numpy.alltrue(a == b), 2064 "NumPy array and PyTables selections does not match.") 2065 2066 def test01c_read(self): 2067 """Test for point-selections (read, float keys).""" 2068 2069 nparr = self.nparr 2070 tbarr = self.tbarr 2071 for value1, value2 in self.limits: 2072 key = numpy.where((nparr >= value1) & (nparr < value2)) 2073 if common.verbose: 2074 print("Selection to test:", key) 2075 # a = nparr[key] 2076 fkey = numpy.array(key, "f4") 2077 self.assertRaises((IndexError, TypeError), tbarr.__getitem__, fkey) 2078 2079 def test01d_read(self): 2080 nparr = self.nparr 2081 tbarr = self.tbarr 2082 2083 for key in self.working_keyset: 2084 if nparr.ndim > 1: 2085 key = tuple(key) 2086 if common.verbose: 2087 print("Selection to test:", key) 2088 a = nparr[key] 2089 b = tbarr[key] 2090 npt.assert_array_equal( 2091 a, b, "NumPy array and PyTables selections does not match.") 2092 2093 def test01e_read(self): 2094 tbarr = self.tbarr 2095 2096 for key in self.not_working_keyset: 2097 if common.verbose: 2098 print("Selection to test:", key) 2099 2100 self.assertRaises(IndexError, tbarr.__getitem__, key) 2101 2102 def test02a_write(self): 2103 """Test for point-selections (write, boolean keys).""" 2104 2105 nparr = self.nparr 2106 tbarr = self.tbarr 2107 for value1, value2 in self.limits: 2108 key = (nparr >= value1) & (nparr < value2) 2109 if common.verbose: 2110 print("Selection to test:", key) 2111 s = nparr[key] 2112 nparr[key] = s * 2 2113 tbarr[key] = s * 2 2114 a = nparr[:] 2115 b = tbarr[:] 2116 self.assertTrue( 2117 numpy.alltrue(a == b), 2118 "NumPy array and PyTables modifications does not match.") 2119 2120 def test02b_write(self): 2121 """Test for point-selections (write, integer keys).""" 2122 2123 nparr = self.nparr 2124 tbarr = self.tbarr 2125 for value1, value2 in self.limits: 2126 key = numpy.where((nparr >= value1) & (nparr < value2)) 2127 if common.verbose: 2128 print("Selection to test:", key) 2129 s = nparr[key] 2130 nparr[key] = s * 2 2131 tbarr[key] = s * 2 2132 a = nparr[:] 2133 b = tbarr[:] 2134 self.assertTrue( 2135 numpy.alltrue(a == b), 2136 "NumPy array and PyTables modifications does not match.") 2137 2138 def test02c_write(self): 2139 """Test for point-selections (write, integer values, broadcast).""" 2140 2141 nparr = self.nparr 2142 tbarr = self.tbarr 2143 for value1, value2 in self.limits: 2144 key = numpy.where((nparr >= value1) & (nparr < value2)) 2145 if common.verbose: 2146 print("Selection to test:", key) 2147 # s = nparr[key] 2148 nparr[key] = 2 # force a broadcast 2149 tbarr[key] = 2 # force a broadcast 2150 a = nparr[:] 2151 b = tbarr[:] 2152 self.assertTrue( 2153 numpy.alltrue(a == b), 2154 "NumPy array and PyTables modifications does not match.") 2155 2156 2157class PointSelection0(PointSelectionTestCase): 2158 shape = (3,) 2159 working_keyset = [ 2160 [0, 1], 2161 [0, -1], 2162 ] 2163 not_working_keyset = [ 2164 [0, 3], 2165 [0, 4], 2166 [0, -4], 2167 ] 2168 2169 2170class PointSelection1(PointSelectionTestCase): 2171 shape = (5, 3, 3) 2172 working_keyset = [ 2173 [(0, 0), (0, 1), (0, 0)], 2174 [(0, 0), (0, -1), (0, 0)], 2175 ] 2176 not_working_keyset = [ 2177 [(0, 0), (0, 3), (0, 0)], 2178 [(0, 0), (0, 4), (0, 0)], 2179 [(0, 0), (0, -4), (0, 0)], 2180 [(0, 0), (0, -5), (0, 0)] 2181 ] 2182 2183 2184class PointSelection2(PointSelectionTestCase): 2185 shape = (7, 3) 2186 working_keyset = [ 2187 [(0, 0), (0, 1)], 2188 [(0, 0), (0, -1)], 2189 [(0, 0), (0, -2)], 2190 ] 2191 not_working_keyset = [ 2192 [(0, 0), (0, 3)], 2193 [(0, 0), (0, 4)], 2194 [(0, 0), (0, -4)], 2195 [(0, 0), (0, -5)], 2196 ] 2197 2198 2199class PointSelection3(PointSelectionTestCase): 2200 shape = (4, 3, 2, 1) 2201 working_keyset = [ 2202 [(0, 0), (0, 1), (0, 0), (0, 0)], 2203 [(0, 0), (0, -1), (0, 0), (0, 0)], 2204 ] 2205 not_working_keyset = [ 2206 [(0, 0), (0, 3), (0, 0), (0, 0)], 2207 [(0, 0), (0, 4), (0, 0), (0, 0)], 2208 [(0, 0), (0, -4), (0, 0), (0, 0)], 2209 ] 2210 2211 2212class PointSelection4(PointSelectionTestCase): 2213 shape = (1, 3, 2, 5, 6) 2214 working_keyset = [ 2215 [(0, 0), (0, 1), (0, 0), (0, 0), (0, 0)], 2216 [(0, 0), (0, -1), (0, 0), (0, 0), (0, 0)], 2217 ] 2218 not_working_keyset = [ 2219 [(0, 0), (0, 3), (0, 0), (0, 0), (0, 0)], 2220 [(0, 0), (0, 4), (0, 0), (0, 0), (0, 0)], 2221 [(0, 0), (0, -4), (0, 0), (0, 0), (0, 0)], 2222 ] 2223 2224 2225class FancySelectionTestCase(common.TempFileMixin, TestCase): 2226 2227 def setUp(self): 2228 super(FancySelectionTestCase, self).setUp() 2229 2230 M, N, O = self.shape 2231 2232 # The next are valid selections for both NumPy and PyTables 2233 self.working_keyset = [ 2234 ([1, 3], slice(1, N-1), 2), 2235 ([M-1, 1, 3, 2], slice(None), 2), # unordered lists supported 2236 (slice(M), [N-1, 1, 0], slice(None)), 2237 (slice(1, M, 3), slice(1, N), [O-1, 1, 0]), 2238 (M-1, [2, 1], 1), 2239 (1, 2, 1), # regular selection 2240 ([1, 2], -2, -1), # negative indices 2241 ([1, -2], 2, -1), # more negative indices 2242 ([1, -2], 2, Ellipsis), # one ellipsis 2243 (Ellipsis, [1, 2]), # one ellipsis 2244 (numpy.array( 2245 [1, -2], 'i4'), 2, -1), # array 32-bit instead of list 2246 (numpy.array( 2247 [-1, 2], 'i8'), 2, -1), # array 64-bit instead of list 2248 ] 2249 2250 # Using booleans instead of ints is deprecated since numpy 1.8 2251 # Tests for keys that have to support the __index__ attribute 2252 #self.working_keyset.append( 2253 # (False, True), # equivalent to (0,1) ;-) 2254 #) 2255 2256 # Valid selections for NumPy, but not for PyTables (yet) 2257 # The next should raise an IndexError 2258 self.not_working_keyset = [ 2259 numpy.array([False, True], dtype="b1"), # boolean arrays 2260 ([1, 2, 1], 2, 1), # repeated values 2261 ([1, 2], 2, [1, 2]), # several lists 2262 ([], 2, 1), # empty selections 2263 (Ellipsis, [1, 2], Ellipsis), # several ellipsis 2264 # Using booleans instead of ints is deprecated since numpy 1.8 2265 ([False, True]), # boolean values with incompatible shape 2266 ] 2267 2268 # The next should raise an IndexError in both NumPy and PyTables 2269 self.not_working_oob = [ 2270 ([1, 2], 2, 1000), # out-of-bounds selections 2271 ([1, 2], 2000, 1), # out-of-bounds selections 2272 ] 2273 2274 # The next should raise a IndexError in both NumPy and PyTables 2275 self.not_working_too_many = [ 2276 ([1, 2], 2, 1, 1), 2277 ] 2278 2279 # Create a sample array 2280 nparr = numpy.empty(self.shape, dtype=numpy.int32) 2281 data = numpy.arange(N * O, dtype=numpy.int32).reshape(N, O) 2282 for i in range(M): 2283 nparr[i] = data * i 2284 self.nparr = nparr 2285 self.tbarr = self.h5file.create_array(self.h5file.root, 'array', nparr) 2286 2287 def test01a_read(self): 2288 """Test for fancy-selections (working selections, read).""" 2289 2290 nparr = self.nparr 2291 tbarr = self.tbarr 2292 for key in self.working_keyset: 2293 if common.verbose: 2294 print("Selection to test:", key) 2295 a = nparr[key] 2296 b = tbarr[key] 2297 self.assertTrue( 2298 numpy.alltrue(a == b), 2299 "NumPy array and PyTables selections does not match.") 2300 2301 def test01b_read(self): 2302 """Test for fancy-selections (not working selections, read).""" 2303 2304 # nparr = self.nparr 2305 tbarr = self.tbarr 2306 for key in self.not_working_keyset: 2307 if common.verbose: 2308 print("Selection to test:", key) 2309 # a = nparr[key] 2310 self.assertRaises(IndexError, tbarr.__getitem__, key) 2311 2312 def test01c_read(self): 2313 """Test for fancy-selections (out-of-bound indexes, read).""" 2314 2315 nparr = self.nparr 2316 tbarr = self.tbarr 2317 for key in self.not_working_oob: 2318 if common.verbose: 2319 print("Selection to test:", key) 2320 self.assertRaises(IndexError, nparr.__getitem__, key) 2321 self.assertRaises(IndexError, tbarr.__getitem__, key) 2322 2323 def test01d_read(self): 2324 """Test for fancy-selections (too many indexes, read).""" 2325 2326 nparr = self.nparr 2327 tbarr = self.tbarr 2328 for key in self.not_working_too_many: 2329 if common.verbose: 2330 print("Selection to test:", key) 2331 # ValueError for numpy 1.6.x and earlier 2332 # IndexError in numpy > 1.8.0 2333 self.assertRaises((ValueError, IndexError), nparr.__getitem__, key) 2334 self.assertRaises(IndexError, tbarr.__getitem__, key) 2335 2336 def test02a_write(self): 2337 """Test for fancy-selections (working selections, write).""" 2338 2339 nparr = self.nparr 2340 tbarr = self.tbarr 2341 for key in self.working_keyset: 2342 if common.verbose: 2343 print("Selection to test:", key) 2344 s = nparr[key] 2345 nparr[key] = s * 2 2346 tbarr[key] = s * 2 2347 a = nparr[:] 2348 b = tbarr[:] 2349 self.assertTrue( 2350 numpy.alltrue(a == b), 2351 "NumPy array and PyTables modifications does not match.") 2352 2353 def test02b_write(self): 2354 """Test for fancy-selections (working selections, write, broadcast).""" 2355 2356 nparr = self.nparr 2357 tbarr = self.tbarr 2358 for key in self.working_keyset: 2359 if common.verbose: 2360 print("Selection to test:", key) 2361 # s = nparr[key] 2362 nparr[key] = 2 # broadcast value 2363 tbarr[key] = 2 # broadcast value 2364 a = nparr[:] 2365 b = tbarr[:] 2366# if common.verbose: 2367# print("NumPy modified array:", a) 2368# print("PyTables modifyied array:", b) 2369 self.assertTrue( 2370 numpy.alltrue(a == b), 2371 "NumPy array and PyTables modifications does not match.") 2372 2373 2374class FancySelection1(FancySelectionTestCase): 2375 shape = (5, 3, 3) # Minimum values 2376 2377 2378class FancySelection2(FancySelectionTestCase): 2379 # shape = (5, 3, 3) # Minimum values 2380 shape = (7, 3, 3) 2381 2382 2383class FancySelection3(FancySelectionTestCase): 2384 # shape = (5, 3, 3) # Minimum values 2385 shape = (7, 4, 5) 2386 2387 2388class FancySelection4(FancySelectionTestCase): 2389 # shape = (5, 3, 3) # Minimum values 2390 shape = (5, 3, 10) 2391 2392 2393class CopyNativeHDF5MDAtom(TestCase): 2394 2395 def setUp(self): 2396 super(CopyNativeHDF5MDAtom, self).setUp() 2397 filename = test_filename("array_mdatom.h5") 2398 self.h5file = tables.open_file(filename, "r") 2399 self.arr = self.h5file.root.arr 2400 self.copy = tempfile.mktemp(".h5") 2401 self.copyh = tables.open_file(self.copy, mode="w") 2402 self.arr2 = self.arr.copy(self.copyh.root, newname="arr2") 2403 2404 def tearDown(self): 2405 self.h5file.close() 2406 self.copyh.close() 2407 os.remove(self.copy) 2408 super(CopyNativeHDF5MDAtom, self).tearDown() 2409 2410 def test01_copy(self): 2411 """Checking that native MD atoms are copied as-is""" 2412 2413 self.assertEqual(self.arr.atom, self.arr2.atom) 2414 self.assertEqual(self.arr.shape, self.arr2.shape) 2415 2416 def test02_reopen(self): 2417 """Checking that native MD atoms are copied as-is (re-open)""" 2418 2419 self.copyh.close() 2420 self.copyh = tables.open_file(self.copy, mode="r") 2421 self.arr2 = self.copyh.root.arr2 2422 self.assertEqual(self.arr.atom, self.arr2.atom) 2423 self.assertEqual(self.arr.shape, self.arr2.shape) 2424 2425 2426class AccessClosedTestCase(common.TempFileMixin, TestCase): 2427 2428 def setUp(self): 2429 super(AccessClosedTestCase, self).setUp() 2430 2431 a = numpy.zeros((10, 10)) 2432 self.array = self.h5file.create_array(self.h5file.root, 'array', a) 2433 2434 def test_read(self): 2435 self.h5file.close() 2436 self.assertRaises(ClosedNodeError, self.array.read) 2437 2438 def test_getitem(self): 2439 self.h5file.close() 2440 self.assertRaises(ClosedNodeError, self.array.__getitem__, 0) 2441 2442 def test_setitem(self): 2443 self.h5file.close() 2444 self.assertRaises(ClosedNodeError, self.array.__setitem__, 0, 0) 2445 2446 2447class BroadcastTest(common.TempFileMixin, TestCase): 2448 2449 def test(self): 2450 """Test correct broadcasting when the array atom is not scalar.""" 2451 2452 array_shape = (2, 3) 2453 element_shape = (3,) 2454 2455 dtype = numpy.dtype((numpy.int, element_shape)) 2456 atom = Atom.from_dtype(dtype) 2457 h5arr = self.h5file.create_array(self.h5file.root, 'array', 2458 atom=atom, shape=array_shape) 2459 2460 size = numpy.prod(element_shape) 2461 nparr = numpy.arange(size).reshape(element_shape) 2462 2463 h5arr[0] = nparr 2464 self.assertTrue(numpy.all(h5arr[0] == nparr)) 2465 2466 2467class TestCreateArrayArgs(common.TempFileMixin, TestCase): 2468 where = '/' 2469 name = 'array' 2470 obj = numpy.array([[1, 2], [3, 4]]) 2471 title = 'title' 2472 byteorder = None 2473 createparents = False 2474 atom = Atom.from_dtype(obj.dtype) 2475 shape = obj.shape 2476 2477 def test_positional_args(self): 2478 self.h5file.create_array(self.where, self.name, self.obj, self.title) 2479 self.h5file.close() 2480 2481 self.h5file = tables.open_file(self.h5fname) 2482 ptarr = self.h5file.get_node(self.where, self.name) 2483 nparr = ptarr.read() 2484 2485 self.assertEqual(ptarr.title, self.title) 2486 self.assertEqual(ptarr.shape, self.shape) 2487 self.assertEqual(ptarr.atom, self.atom) 2488 self.assertEqual(ptarr.atom.dtype, self.atom.dtype) 2489 self.assertTrue(allequal(self.obj, nparr)) 2490 2491 def test_positional_args_atom_shape(self): 2492 self.h5file.create_array(self.where, self.name, None, self.title, 2493 self.byteorder, self.createparents, 2494 self.atom, self.shape) 2495 self.h5file.close() 2496 2497 self.h5file = tables.open_file(self.h5fname) 2498 ptarr = self.h5file.get_node(self.where, self.name) 2499 nparr = ptarr.read() 2500 2501 self.assertEqual(ptarr.title, self.title) 2502 self.assertEqual(ptarr.shape, self.shape) 2503 self.assertEqual(ptarr.atom, self.atom) 2504 self.assertEqual(ptarr.atom.dtype, self.atom.dtype) 2505 self.assertTrue(allequal(numpy.zeros_like(self.obj), nparr)) 2506 2507 def test_kwargs_obj(self): 2508 self.h5file.create_array(self.where, self.name, title=self.title, 2509 obj=self.obj) 2510 self.h5file.close() 2511 2512 self.h5file = tables.open_file(self.h5fname) 2513 ptarr = self.h5file.get_node(self.where, self.name) 2514 nparr = ptarr.read() 2515 2516 self.assertEqual(ptarr.title, self.title) 2517 self.assertEqual(ptarr.shape, self.shape) 2518 self.assertEqual(ptarr.atom, self.atom) 2519 self.assertEqual(ptarr.atom.dtype, self.atom.dtype) 2520 self.assertTrue(allequal(self.obj, nparr)) 2521 2522 def test_kwargs_atom_shape_01(self): 2523 ptarr = self.h5file.create_array(self.where, self.name, 2524 title=self.title, 2525 atom=self.atom, shape=self.shape) 2526 ptarr[...] = self.obj 2527 self.h5file.close() 2528 2529 self.h5file = tables.open_file(self.h5fname) 2530 ptarr = self.h5file.get_node(self.where, self.name) 2531 nparr = ptarr.read() 2532 2533 self.assertEqual(ptarr.title, self.title) 2534 self.assertEqual(ptarr.shape, self.shape) 2535 self.assertEqual(ptarr.atom, self.atom) 2536 self.assertEqual(ptarr.atom.dtype, self.atom.dtype) 2537 self.assertTrue(allequal(self.obj, nparr)) 2538 2539 def test_kwargs_atom_shape_02(self): 2540 ptarr = self.h5file.create_array(self.where, self.name, 2541 title=self.title, 2542 atom=self.atom, shape=self.shape) 2543 #ptarr[...] = self.obj 2544 self.h5file.close() 2545 2546 self.h5file = tables.open_file(self.h5fname) 2547 ptarr = self.h5file.get_node(self.where, self.name) 2548 nparr = ptarr.read() 2549 2550 self.assertEqual(ptarr.title, self.title) 2551 self.assertEqual(ptarr.shape, self.shape) 2552 self.assertEqual(ptarr.atom, self.atom) 2553 self.assertEqual(ptarr.atom.dtype, self.atom.dtype) 2554 self.assertTrue(allequal(numpy.zeros_like(self.obj), nparr)) 2555 2556 def test_kwargs_obj_atom(self): 2557 ptarr = self.h5file.create_array(self.where, self.name, 2558 title=self.title, 2559 obj=self.obj, 2560 atom=self.atom) 2561 self.h5file.close() 2562 2563 self.h5file = tables.open_file(self.h5fname) 2564 ptarr = self.h5file.get_node(self.where, self.name) 2565 nparr = ptarr.read() 2566 2567 self.assertEqual(ptarr.title, self.title) 2568 self.assertEqual(ptarr.shape, self.shape) 2569 self.assertEqual(ptarr.atom, self.atom) 2570 self.assertEqual(ptarr.atom.dtype, self.atom.dtype) 2571 self.assertTrue(allequal(self.obj, nparr)) 2572 2573 def test_kwargs_obj_shape(self): 2574 ptarr = self.h5file.create_array(self.where, self.name, 2575 title=self.title, 2576 obj=self.obj, 2577 shape=self.shape) 2578 self.h5file.close() 2579 2580 self.h5file = tables.open_file(self.h5fname) 2581 ptarr = self.h5file.get_node(self.where, self.name) 2582 nparr = ptarr.read() 2583 2584 self.assertEqual(ptarr.title, self.title) 2585 self.assertEqual(ptarr.shape, self.shape) 2586 self.assertEqual(ptarr.atom, self.atom) 2587 self.assertEqual(ptarr.atom.dtype, self.atom.dtype) 2588 self.assertTrue(allequal(self.obj, nparr)) 2589 2590 def test_kwargs_obj_atom_shape(self): 2591 ptarr = self.h5file.create_array(self.where, self.name, 2592 title=self.title, 2593 obj=self.obj, 2594 atom=self.atom, 2595 shape=self.shape) 2596 self.h5file.close() 2597 2598 self.h5file = tables.open_file(self.h5fname) 2599 ptarr = self.h5file.get_node(self.where, self.name) 2600 nparr = ptarr.read() 2601 2602 self.assertEqual(ptarr.title, self.title) 2603 self.assertEqual(ptarr.shape, self.shape) 2604 self.assertEqual(ptarr.atom, self.atom) 2605 self.assertEqual(ptarr.atom.dtype, self.atom.dtype) 2606 self.assertTrue(allequal(self.obj, nparr)) 2607 2608 def test_kwargs_obj_atom_error(self): 2609 atom = Atom.from_dtype(numpy.dtype('complex')) 2610 #shape = self.shape + self.shape 2611 self.assertRaises(TypeError, 2612 self.h5file.create_array, 2613 self.where, 2614 self.name, 2615 title=self.title, 2616 obj=self.obj, 2617 atom=atom) 2618 2619 def test_kwargs_obj_shape_error(self): 2620 #atom = Atom.from_dtype(numpy.dtype('complex')) 2621 shape = self.shape + self.shape 2622 self.assertRaises(TypeError, 2623 self.h5file.create_array, 2624 self.where, 2625 self.name, 2626 title=self.title, 2627 obj=self.obj, 2628 shape=shape) 2629 2630 def test_kwargs_obj_atom_shape_error_01(self): 2631 atom = Atom.from_dtype(numpy.dtype('complex')) 2632 #shape = self.shape + self.shape 2633 self.assertRaises(TypeError, 2634 self.h5file.create_array, 2635 self.where, 2636 self.name, 2637 title=self.title, 2638 obj=self.obj, 2639 atom=atom, 2640 shape=self.shape) 2641 2642 def test_kwargs_obj_atom_shape_error_02(self): 2643 #atom = Atom.from_dtype(numpy.dtype('complex')) 2644 shape = self.shape + self.shape 2645 self.assertRaises(TypeError, 2646 self.h5file.create_array, 2647 self.where, 2648 self.name, 2649 title=self.title, 2650 obj=self.obj, 2651 atom=self.atom, 2652 shape=shape) 2653 2654 def test_kwargs_obj_atom_shape_error_03(self): 2655 atom = Atom.from_dtype(numpy.dtype('complex')) 2656 shape = self.shape + self.shape 2657 self.assertRaises(TypeError, 2658 self.h5file.create_array, 2659 self.where, 2660 self.name, 2661 title=self.title, 2662 obj=self.obj, 2663 atom=atom, 2664 shape=shape) 2665 2666 2667def suite(): 2668 theSuite = unittest.TestSuite() 2669 niter = 1 2670 2671 for i in range(niter): 2672 # The scalar case test should be refined in order to work 2673 theSuite.addTest(unittest.makeSuite(Basic0DOneTestCase)) 2674 theSuite.addTest(unittest.makeSuite(Basic0DTwoTestCase)) 2675 # theSuite.addTest(unittest.makeSuite(Basic1DZeroTestCase)) 2676 theSuite.addTest(unittest.makeSuite(Basic1DOneTestCase)) 2677 theSuite.addTest(unittest.makeSuite(Basic1DTwoTestCase)) 2678 theSuite.addTest(unittest.makeSuite(Basic1DThreeTestCase)) 2679 theSuite.addTest(unittest.makeSuite(Basic2DOneTestCase)) 2680 theSuite.addTest(unittest.makeSuite(Basic2DTwoTestCase)) 2681 theSuite.addTest(unittest.makeSuite(Basic10DTestCase)) 2682 # The 32 dimensions case is tested on GroupsArray 2683 # theSuite.addTest(unittest.makeSuite(Basic32DTestCase)) 2684 theSuite.addTest(unittest.makeSuite(ReadOutArgumentTests)) 2685 theSuite.addTest(unittest.makeSuite( 2686 SizeOnDiskInMemoryPropertyTestCase)) 2687 theSuite.addTest(unittest.makeSuite(GroupsArrayTestCase)) 2688 theSuite.addTest(unittest.makeSuite(ComplexNotReopenNotEndianTestCase)) 2689 theSuite.addTest(unittest.makeSuite(ComplexReopenNotEndianTestCase)) 2690 theSuite.addTest(unittest.makeSuite(ComplexNotReopenEndianTestCase)) 2691 theSuite.addTest(unittest.makeSuite(ComplexReopenEndianTestCase)) 2692 theSuite.addTest(unittest.makeSuite(CloseCopyTestCase)) 2693 theSuite.addTest(unittest.makeSuite(OpenCopyTestCase)) 2694 theSuite.addTest(unittest.makeSuite(CopyIndex1TestCase)) 2695 theSuite.addTest(unittest.makeSuite(CopyIndex2TestCase)) 2696 theSuite.addTest(unittest.makeSuite(CopyIndex3TestCase)) 2697 theSuite.addTest(unittest.makeSuite(CopyIndex4TestCase)) 2698 theSuite.addTest(unittest.makeSuite(CopyIndex5TestCase)) 2699 theSuite.addTest(unittest.makeSuite(CopyIndex6TestCase)) 2700 theSuite.addTest(unittest.makeSuite(CopyIndex7TestCase)) 2701 theSuite.addTest(unittest.makeSuite(CopyIndex8TestCase)) 2702 theSuite.addTest(unittest.makeSuite(CopyIndex9TestCase)) 2703 theSuite.addTest(unittest.makeSuite(CopyIndex10TestCase)) 2704 theSuite.addTest(unittest.makeSuite(CopyIndex11TestCase)) 2705 theSuite.addTest(unittest.makeSuite(CopyIndex12TestCase)) 2706 theSuite.addTest(unittest.makeSuite(GI1NAOpenTestCase)) 2707 theSuite.addTest(unittest.makeSuite(GI1NACloseTestCase)) 2708 theSuite.addTest(unittest.makeSuite(GI2NAOpenTestCase)) 2709 theSuite.addTest(unittest.makeSuite(GI2NACloseTestCase)) 2710 theSuite.addTest(unittest.makeSuite(SI1NAOpenTestCase)) 2711 theSuite.addTest(unittest.makeSuite(SI1NACloseTestCase)) 2712 theSuite.addTest(unittest.makeSuite(SI2NAOpenTestCase)) 2713 theSuite.addTest(unittest.makeSuite(SI2NACloseTestCase)) 2714 theSuite.addTest(unittest.makeSuite(GE1NAOpenTestCase)) 2715 theSuite.addTest(unittest.makeSuite(GE1NACloseTestCase)) 2716 theSuite.addTest(unittest.makeSuite(GE2NAOpenTestCase)) 2717 theSuite.addTest(unittest.makeSuite(GE2NACloseTestCase)) 2718 theSuite.addTest(unittest.makeSuite(NonHomogeneousTestCase)) 2719 theSuite.addTest(unittest.makeSuite(TruncateTestCase)) 2720 theSuite.addTest(unittest.makeSuite(FancySelection1)) 2721 theSuite.addTest(unittest.makeSuite(FancySelection2)) 2722 theSuite.addTest(unittest.makeSuite(FancySelection3)) 2723 theSuite.addTest(unittest.makeSuite(FancySelection4)) 2724 theSuite.addTest(unittest.makeSuite(PointSelection0)) 2725 theSuite.addTest(unittest.makeSuite(PointSelection1)) 2726 theSuite.addTest(unittest.makeSuite(PointSelection2)) 2727 theSuite.addTest(unittest.makeSuite(PointSelection3)) 2728 theSuite.addTest(unittest.makeSuite(PointSelection4)) 2729 theSuite.addTest(unittest.makeSuite(CopyNativeHDF5MDAtom)) 2730 theSuite.addTest(unittest.makeSuite(AccessClosedTestCase)) 2731 theSuite.addTest(unittest.makeSuite(TestCreateArrayArgs)) 2732 theSuite.addTest(unittest.makeSuite(BroadcastTest)) 2733 2734 return theSuite 2735 2736 2737if __name__ == '__main__': 2738 common.parse_argv(sys.argv) 2739 common.print_versions() 2740 unittest.main(defaultTest='suite') 2741