Checking Table.copy() method.
(self)
| 5742 | self.assertEqual(col1._v_colpathnames, col2._v_colpathnames) |
| 5743 | |
| 5744 | def test01_copy(self): |
| 5745 | """Checking Table.copy() method.""" |
| 5746 | |
| 5747 | if common.verbose: |
| 5748 | print("\n", "-=" * 30) |
| 5749 | print("Running %s.test01_copy..." % self.__class__.__name__) |
| 5750 | |
| 5751 | # Create a recarray |
| 5752 | r = np.rec.array( |
| 5753 | [(456, b"dbe", 1.2), (2, b"de", 1.3)], |
| 5754 | names="col1,col2,col3", |
| 5755 | formats=("i4,S3,f8"), |
| 5756 | aligned=self.aligned, |
| 5757 | ) |
| 5758 | # Save it in a table: |
| 5759 | table1 = self.h5file.create_table( |
| 5760 | self.h5file.root, "table1", r, "title table1" |
| 5761 | ) |
| 5762 | |
| 5763 | if self.close: |
| 5764 | if common.verbose: |
| 5765 | print("(closing file version)") |
| 5766 | self._reopen(mode="a") |
| 5767 | table1 = self.h5file.root.table1 |
| 5768 | |
| 5769 | # Copy to another table |
| 5770 | table2 = table1.copy("/", "table2") |
| 5771 | |
| 5772 | if self.close: |
| 5773 | if common.verbose: |
| 5774 | print("(closing file version)") |
| 5775 | self._reopen(mode="a") |
| 5776 | table1 = self.h5file.root.table1 |
| 5777 | table2 = self.h5file.root.table2 |
| 5778 | |
| 5779 | if common.verbose: |
| 5780 | print("table1-->", table1.read()) |
| 5781 | print("table2-->", table2.read()) |
| 5782 | # print "dirs-->", dir(table1), dir(table2) |
| 5783 | print("attrs table1-->", repr(table1.attrs)) |
| 5784 | print("attrs table2-->", repr(table2.attrs)) |
| 5785 | |
| 5786 | # Check that all the elements are equal |
| 5787 | for row1 in table1: |
| 5788 | nrow = row1.nrow # current row |
| 5789 | # row1 is a Row instance, while table2[] is a |
| 5790 | # RecArray.Record instance |
| 5791 | # print "reprs-->", repr(row1), repr(table2.read(nrow)) |
| 5792 | for colname in table1.colnames: |
| 5793 | # Both ways to compare work well |
| 5794 | # self.assertEqual(row1[colname], table2[nrow][colname)) |
| 5795 | self.assertEqual( |
| 5796 | row1[colname], table2.read(nrow, field=colname)[0] |
| 5797 | ) |
| 5798 | |
| 5799 | # Assert other properties in table |
| 5800 | self.assertEqual(table1.nrows, table2.nrows) |
| 5801 | self.assertEqual(table1.shape, table2.shape) |
nothing calls this directly
no test coverage detected