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

Method test05_copy

tables/tests/test_tables.py:6075–6167  ·  view source on GitHub ↗

Checking Table.copy() method (user attributes copied)

(self)

Source from the content-addressed store, hash-verified

6073 self.assertEqual(table1.filters.fletcher32, table2.filters.fletcher32)
6074
6075 def test05_copy(self):
6076 """Checking Table.copy() method (user attributes copied)"""
6077
6078 if common.verbose:
6079 print("\n", "-=" * 30)
6080 print("Running %s.test05_copy..." % self.__class__.__name__)
6081
6082 # Create a recarray
6083 r = np.rec.array(
6084 [(456, b"dbe", 1.2), (2, b"de", 1.3)],
6085 names="col1,col2,col3",
6086 formats="i8,S3,f8",
6087 aligned=self.aligned,
6088 )
6089 # Save it in a table:
6090 table1 = self.h5file.create_table(
6091 self.h5file.root, "table1", r, "title table1"
6092 )
6093 # Add some user attributes
6094 table1.attrs.attr1 = "attr1"
6095 table1.attrs.attr2 = 2
6096
6097 if self.close:
6098 if common.verbose:
6099 print("(closing file version)")
6100 self._reopen(mode="a")
6101 table1 = self.h5file.root.table1
6102
6103 # Copy to another table in another group
6104 group1 = self.h5file.create_group("/", "group1")
6105 table2 = table1.copy(
6106 group1, "table2", copyuserattrs=1, filters=tb.Filters(complevel=6)
6107 )
6108
6109 if self.close:
6110 if common.verbose:
6111 print("(closing file version)")
6112 self._reopen()
6113 table1 = self.h5file.root.table1
6114 table2 = self.h5file.root.group1.table2
6115
6116 if common.verbose:
6117 print("table1-->", table1.read())
6118 print("table2-->", table2.read())
6119 print("attrs table1-->", repr(table1.attrs))
6120 print("attrs table2-->", repr(table2.attrs))
6121
6122 # Check that all the elements are equal
6123 for row1 in table1:
6124 nrow = row1.nrow # current row
6125 for colname in table1.colnames:
6126 # self.assertEqual(row1[colname], table2[nrow][colname))
6127 self.assertEqual(
6128 row1[colname], table2.read(nrow, field=colname)[0]
6129 )
6130
6131 # Assert other properties in table
6132 self.assertEqual(table1.nrows, table2.nrows)

Callers

nothing calls this directly

Calls 8

is_os_64bitFunction · 0.85
is_python_64bitFunction · 0.85
create_groupMethod · 0.80
create_tableMethod · 0.45
_reopenMethod · 0.45
copyMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected