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

Method test02_Attrs

tables/tests/test_create.py:1359–1417  ·  view source on GitHub ↗

Checking copy of a File (attributes copied)

(self)

Source from the content-addressed store, hash-verified

1357 print("The attrs contents has been copied correctly")
1358
1359 def test02_Attrs(self):
1360 """Checking copy of a File (attributes copied)"""
1361
1362 if common.verbose:
1363 print("\n", "-=" * 30)
1364 print("Running %s.test02_Attrs..." % self.__class__.__name__)
1365
1366 # Copy the file to the destination
1367 self.h5file.copy_file(
1368 self.h5fname2,
1369 title=self.title,
1370 copyuserattrs=1,
1371 filters=self.filters,
1372 )
1373
1374 # Close the original file, if needed
1375 if self.close:
1376 self._reopen()
1377
1378 # ...and open the destination file
1379 self.h5file2 = tb.open_file(self.h5fname2, "r")
1380
1381 # Check that the copy has been done correctly
1382 srcgroup = self.h5file.root
1383 dstgroup = self.h5file2.root
1384 for srcnode in srcgroup:
1385 dstnode = getattr(dstgroup, srcnode._v_name)
1386 srcattrs = srcnode._v_attrs
1387 srcattrskeys = srcattrs._f_list("all")
1388 dstattrs = dstnode._v_attrs
1389 dstattrskeys = dstattrs._f_list("all")
1390 # These lists should already be ordered
1391 if common.verbose:
1392 print(
1393 f"srcattrskeys for node {srcnode._v_name}: "
1394 f"{srcattrskeys}"
1395 )
1396 print(
1397 f"dstattrskeys for node {dstnode._v_name}: "
1398 f"{dstattrskeys}"
1399 )
1400
1401 # Filters may differ, do not take into account
1402 if self.filters is not None:
1403 dstattrskeys.remove("FILTERS")
1404 self.assertEqual(srcattrskeys, dstattrskeys)
1405 if common.verbose:
1406 print("The attrs names has been copied correctly")
1407
1408 # Now, for the contents of attributes
1409 for srcattrname in srcattrskeys:
1410 srcattrvalue = str(getattr(srcattrs, srcattrname))
1411 dstattrvalue = str(getattr(dstattrs, srcattrname))
1412 self.assertEqual(srcattrvalue, dstattrvalue)
1413 if self.filters is not None:
1414 self.assertEqual(dstattrs.FILTERS, self.filters)
1415
1416 if common.verbose:

Callers

nothing calls this directly

Calls 4

copy_fileMethod · 0.80
_f_listMethod · 0.80
_reopenMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected