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

Method test05b_copy

tables/tests/test_tables.py:6169–6254  ·  view source on GitHub ↗

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

(self)

Source from the content-addressed store, hash-verified

6167 self.assertEqual(table2.attrs.attr2, 2)
6168
6169 def test05b_copy(self):
6170 """Checking Table.copy() method (user attributes not copied)"""
6171
6172 if common.verbose:
6173 print("\n", "-=" * 30)
6174 print("Running %s.test05b_copy..." % self.__class__.__name__)
6175
6176 # Create a recarray
6177 r = np.rec.array(
6178 [(456, b"dbe", 1.2), (2, b"de", 1.3)],
6179 names="col1,col2,col3",
6180 formats="i8,S3,f4",
6181 aligned=self.aligned,
6182 )
6183 # Save it in a table:
6184 table1 = self.h5file.create_table(
6185 self.h5file.root, "table1", r, "title table1"
6186 )
6187
6188 # Add some user attributes
6189 table1.attrs.attr1 = "attr1"
6190 table1.attrs.attr2 = 2
6191
6192 if self.close:
6193 if common.verbose:
6194 print("(closing file version)")
6195 self._reopen(mode="a")
6196 table1 = self.h5file.root.table1
6197
6198 # Copy to another table in another group
6199 group1 = self.h5file.create_group("/", "group1")
6200 table2 = table1.copy(
6201 group1, "table2", copyuserattrs=0, filters=tb.Filters(complevel=6)
6202 )
6203
6204 if self.close:
6205 if common.verbose:
6206 print("(closing file version)")
6207 self._reopen()
6208 table1 = self.h5file.root.table1
6209 table2 = self.h5file.root.group1.table2
6210
6211 if common.verbose:
6212 print("table1-->", table1.read())
6213 print("table2-->", table2.read())
6214 print("attrs table1-->", repr(table1.attrs))
6215 print("attrs table2-->", repr(table2.attrs))
6216
6217 # Check that all the elements are equal
6218 for row1 in table1:
6219 nrow = row1.nrow # current row
6220 for colname in table1.colnames:
6221 # self.assertEqual(row1[colname], table2[nrow][colname))
6222 self.assertEqual(
6223 row1[colname], table2.read(nrow, field=colname)[0]
6224 )
6225
6226 # Assert other properties in table

Callers

nothing calls this directly

Calls 6

create_groupMethod · 0.80
create_tableMethod · 0.45
_reopenMethod · 0.45
copyMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected