(self, testarray)
| 156 | Path(filename).unlink() |
| 157 | |
| 158 | def write_read_atom_shape_args(self, testarray): |
| 159 | a = testarray |
| 160 | atom = tb.Atom.from_dtype(a.dtype) |
| 161 | shape = a.shape |
| 162 | byteorder = None |
| 163 | |
| 164 | if common.verbose: |
| 165 | print("\n", "-=" * 30) |
| 166 | print( |
| 167 | "Running test for array with type '%s'" % a.dtype.type, end=" " |
| 168 | ) |
| 169 | print("for class check:", self.title) |
| 170 | |
| 171 | # Create an instance of HDF5 file |
| 172 | filename = tempfile.mktemp(".h5") |
| 173 | try: |
| 174 | with tb.open_file(filename, mode="w") as fileh: |
| 175 | root = fileh.root |
| 176 | |
| 177 | # Create the array under root and name 'somearray' |
| 178 | if self.endiancheck and a.dtype.kind != "S": |
| 179 | b = a.byteswap() |
| 180 | b.dtype = a.dtype.newbyteorder() |
| 181 | if b.dtype.byteorder in (">", "<"): |
| 182 | byteorder = tb.utils.byteorders[b.dtype.byteorder] |
| 183 | a = b |
| 184 | |
| 185 | ptarr = fileh.create_array( |
| 186 | root, |
| 187 | "somearray", |
| 188 | atom=atom, |
| 189 | shape=shape, |
| 190 | title="Some array", |
| 191 | # specify the byteorder explicitly |
| 192 | # since there is no way to deduce |
| 193 | # it in this case |
| 194 | byteorder=byteorder, |
| 195 | ) |
| 196 | self.assertEqual(shape, ptarr.shape) |
| 197 | self.assertEqual(atom, ptarr.atom) |
| 198 | ptarr[...] = a |
| 199 | |
| 200 | # Re-open the file in read-only mode |
| 201 | with tb.open_file(filename, mode="r") as fileh: |
| 202 | root = fileh.root |
| 203 | |
| 204 | # Read the saved array |
| 205 | b = root.somearray.read() |
| 206 | |
| 207 | # Compare them. They should be equal. |
| 208 | if common.verbose and not common.allequal(a, b): |
| 209 | print("Write and read arrays differ!") |
| 210 | # print("Array written:", a) |
| 211 | print("Array written shape:", a.shape) |
| 212 | print("Array written itemsize:", a.itemsize) |
| 213 | print("Array written type:", a.dtype.type) |
| 214 | # print("Array read:", b) |
| 215 | print("Array read shape:", b.shape) |
no test coverage detected