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

Method test04_copy

tables/tests/test_tables.py:5996–6073  ·  view source on GitHub ↗

Checking Table.copy() method (different compress level)

(self)

Source from the content-addressed store, hash-verified

5994 self.assertEqual(table1.filters.fletcher32, table2.filters.fletcher32)
5995
5996 def test04_copy(self):
5997 """Checking Table.copy() method (different compress level)"""
5998
5999 if common.verbose:
6000 print("\n", "-=" * 30)
6001 print("Running %s.test04_copy..." % self.__class__.__name__)
6002
6003 # Create a recarray
6004 r = np.rec.array(
6005 [(1.2, b"dbe", 456), (1.3, b"de", 2)],
6006 names="col1,col2,col3",
6007 formats="f8,S3,i4",
6008 aligned=self.aligned,
6009 )
6010 # Save it in a table:
6011 table1 = self.h5file.create_table(
6012 self.h5file.root, "table1", r, "title table1"
6013 )
6014
6015 if self.close:
6016 if common.verbose:
6017 print("(closing file version)")
6018 self._reopen(mode="a")
6019 table1 = self.h5file.root.table1
6020
6021 # Copy to another table in another group
6022 group1 = self.h5file.create_group("/", "group1")
6023 table2 = table1.copy(group1, "table2", filters=tb.Filters(complevel=6))
6024
6025 if self.close:
6026 if common.verbose:
6027 print("(closing file version)")
6028 self._reopen()
6029 table1 = self.h5file.root.table1
6030 table2 = self.h5file.root.group1.table2
6031
6032 if common.verbose:
6033 print("table1-->", table1.read())
6034 print("table2-->", table2.read())
6035 print("attrs table1-->", repr(table1.attrs))
6036 print("attrs table2-->", repr(table2.attrs))
6037
6038 # Check that all the elements are equal
6039 for row1 in table1:
6040 nrow = row1.nrow # current row
6041 for colname in table1.colnames:
6042 # Both ways to compare work well
6043 # self.assertEqual(row1[colname], table2[nrow][colname))
6044 self.assertEqual(
6045 row1[colname], table2.read(nrow, field=colname)[0]
6046 )
6047
6048 # Assert other properties in table
6049 self.assertEqual(table1.nrows, table2.nrows)
6050 self.assertEqual(table1.shape, table2.shape)
6051 self.assertEqual(table1.colnames, table2.colnames)
6052 self.assertEqual(table1.coldtypes, table2.coldtypes)
6053 self.assertEqualColinstances(table1, table2)

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