(self, testarray)
| 101 | Path(filename).unlink() |
| 102 | |
| 103 | def write_read_out_arg(self, testarray): |
| 104 | a = testarray |
| 105 | |
| 106 | if common.verbose: |
| 107 | print("\n", "-=" * 30) |
| 108 | print( |
| 109 | "Running test for array with type '%s'" % a.dtype.type, end=" " |
| 110 | ) |
| 111 | print("for class check:", self.title) |
| 112 | |
| 113 | # Create an instance of HDF5 file |
| 114 | filename = tempfile.mktemp(".h5") |
| 115 | try: |
| 116 | with tb.open_file(filename, mode="w") as fileh: |
| 117 | root = fileh.root |
| 118 | |
| 119 | # Create the array under root and name 'somearray' |
| 120 | if self.endiancheck and a.dtype.kind != "S": |
| 121 | b = a.byteswap() |
| 122 | b.dtype = a.dtype.newbyteorder() |
| 123 | a = b |
| 124 | |
| 125 | fileh.create_array(root, "somearray", a, "Some array") |
| 126 | |
| 127 | # Re-open the file in read-only mode |
| 128 | with tb.open_file(filename, mode="r") as fileh: |
| 129 | root = fileh.root |
| 130 | |
| 131 | # Read the saved array |
| 132 | b = np.empty_like(a, dtype=a.dtype) |
| 133 | root.somearray.read(out=b) |
| 134 | |
| 135 | # Check strictly the array equality |
| 136 | self.assertEqual(a.shape, b.shape) |
| 137 | self.assertEqual(a.shape, root.somearray.shape) |
| 138 | if a.dtype.kind == "S": |
| 139 | self.assertEqual(root.somearray.atom.type, "string") |
| 140 | else: |
| 141 | self.assertEqual(a.dtype.type, b.dtype.type) |
| 142 | self.assertEqual( |
| 143 | a.dtype.type, root.somearray.atom.dtype.type |
| 144 | ) |
| 145 | abo = tb.utils.byteorders[a.dtype.byteorder] |
| 146 | bbo = tb.utils.byteorders[b.dtype.byteorder] |
| 147 | if abo != "irrelevant": |
| 148 | self.assertEqual(abo, root.somearray.byteorder) |
| 149 | self.assertEqual(abo, bbo) |
| 150 | if self.endiancheck: |
| 151 | self.assertNotEqual(bbo, sys.byteorder) |
| 152 | |
| 153 | self.assertTrue(common.allequal(a, b)) |
| 154 | finally: |
| 155 | # Then, delete the file |
| 156 | Path(filename).unlink() |
| 157 | |
| 158 | def write_read_atom_shape_args(self, testarray): |
| 159 | a = testarray |
no test coverage detected