MCPcopy Create free account
hub / github.com/PyTables/PyTables / write_read

Method write_read

tables/tests/test_array.py:22–101  ·  view source on GitHub ↗
(self, testarray)

Source from the content-addressed store, hash-verified

20 endiancheck = False
21
22 def write_read(self, testarray):
23 a = testarray
24 if common.verbose:
25 print("\n", "-=" * 30)
26 print(
27 "Running test for array with type '%s'" % a.dtype.type, end=" "
28 )
29 print("for class check:", self.title)
30
31 # Create an instance of HDF5 file
32 filename = tempfile.mktemp(".h5")
33 try:
34 with tb.open_file(filename, mode="w") as fileh:
35 root = fileh.root
36
37 # Create the array under root and name 'somearray'
38 if self.endiancheck and a.dtype.kind != "S":
39 b = a.byteswap()
40 b.dtype = a.dtype.newbyteorder()
41 a = b
42
43 fileh.create_array(root, "somearray", a, "Some array")
44
45 # Re-open the file in read-only mode
46 with tb.open_file(filename, mode="r") as fileh:
47 root = fileh.root
48
49 # Read the saved array
50 b = root.somearray.read()
51
52 # Compare them. They should be equal.
53 if common.verbose and not common.allequal(a, b):
54 print("Write and read arrays differ!")
55 # print("Array written:", a)
56 print("Array written shape:", a.shape)
57 print("Array written itemsize:", a.itemsize)
58 print("Array written type:", a.dtype.type)
59 # print("Array read:", b)
60 print("Array read shape:", b.shape)
61 print("Array read itemsize:", b.itemsize)
62 print("Array read type:", b.dtype.type)
63 if a.dtype.kind != "S":
64 print("Array written byteorder:", a.dtype.byteorder)
65 print("Array read byteorder:", b.dtype.byteorder)
66
67 # Check strictly the array equality
68 self.assertEqual(a.shape, b.shape)
69 self.assertEqual(a.shape, root.somearray.shape)
70 if a.dtype.kind == "S":
71 self.assertEqual(root.somearray.atom.type, "string")
72 else:
73 self.assertEqual(a.dtype.type, b.dtype.type)
74 self.assertEqual(
75 a.dtype.type, root.somearray.atom.dtype.type
76 )
77 abo = tb.utils.byteorders[a.dtype.byteorder]
78 bbo = tb.utils.byteorders[b.dtype.byteorder]
79 if abo != "irrelevant":

Callers 4

test00_charMethod · 0.95
test01_char_ncMethod · 0.95
test02_typesMethod · 0.95
test03_types_ncMethod · 0.95

Calls 2

create_arrayMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected