test_h5p.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # This file is part of h5py, a Python interface to the HDF5 library.
  2. #
  3. # http://www.h5py.org
  4. #
  5. # Copyright 2008-2013 Andrew Collette and contributors
  6. #
  7. # License: Standard 3-clause BSD; see "license.txt" for full license terms
  8. # and contributor agreement.
  9. import unittest as ut
  10. from h5py import h5p, h5f, version
  11. from .common import TestCase
  12. class TestLibver(TestCase):
  13. """
  14. Feature: Setting/getting lib ver bounds
  15. """
  16. def test_libver(self):
  17. """ Test libver bounds set/get """
  18. plist = h5p.create(h5p.FILE_ACCESS)
  19. plist.set_libver_bounds(h5f.LIBVER_EARLIEST, h5f.LIBVER_LATEST)
  20. self.assertEqual((h5f.LIBVER_EARLIEST, h5f.LIBVER_LATEST),
  21. plist.get_libver_bounds())
  22. @ut.skipIf(version.hdf5_version_tuple < (1, 10, 2),
  23. 'Requires HDF5 1.10.2 or later')
  24. def test_libver_v18(self):
  25. """ Test libver bounds set/get for H5F_LIBVER_V18"""
  26. plist = h5p.create(h5p.FILE_ACCESS)
  27. plist.set_libver_bounds(h5f.LIBVER_EARLIEST, h5f.LIBVER_V18)
  28. self.assertEqual((h5f.LIBVER_EARLIEST, h5f.LIBVER_V18),
  29. plist.get_libver_bounds())
  30. @ut.skipIf(version.hdf5_version_tuple < (1, 10, 2),
  31. 'Requires HDF5 1.10.2 or later')
  32. def test_libver_v110(self):
  33. """ Test libver bounds set/get for H5F_LIBVER_V110"""
  34. plist = h5p.create(h5p.FILE_ACCESS)
  35. plist.set_libver_bounds(h5f.LIBVER_V18, h5f.LIBVER_V110)
  36. self.assertEqual((h5f.LIBVER_V18, h5f.LIBVER_V110),
  37. plist.get_libver_bounds())
  38. @ut.skipIf(version.hdf5_version_tuple < (1, 11, 4),
  39. 'Requires HDF5 1.11.4 or later')
  40. def test_libver_v112(self):
  41. """ Test libver bounds set/get for H5F_LIBVER_V112"""
  42. plist = h5p.create(h5p.FILE_ACCESS)
  43. plist.set_libver_bounds(h5f.LIBVER_V18, h5f.LIBVER_V112)
  44. self.assertEqual((h5f.LIBVER_V18, h5f.LIBVER_V112),
  45. plist.get_libver_bounds())
  46. class TestDA(TestCase):
  47. '''
  48. Feature: setting/getting chunk cache size on a dataset access property list
  49. '''
  50. def test_chunk_cache(self):
  51. '''test get/set chunk cache '''
  52. dalist = h5p.create(h5p.DATASET_ACCESS)
  53. nslots = 10000 # 40kb hash table
  54. nbytes = 1000000 # 1MB cache size
  55. w0 = .5 # even blend of eviction strategy
  56. dalist.set_chunk_cache(nslots, nbytes, w0)
  57. self.assertEqual((nslots, nbytes, w0),
  58. dalist.get_chunk_cache())
  59. class TestFA(TestCase):
  60. '''
  61. Feature: setting/getting mdc config on a file access property list
  62. '''
  63. def test_mdc_config(self):
  64. '''test get/set mdc config '''
  65. falist = h5p.create(h5p.FILE_ACCESS)
  66. config = falist.get_mdc_config()
  67. falist.set_mdc_config(config)
  68. def test_set_alignment(self):
  69. '''test get/set chunk cache '''
  70. falist = h5p.create(h5p.FILE_ACCESS)
  71. threshold = 10 * 1024 # threshold of 10kiB
  72. alignment = 1024 * 1024 # threshold of 1kiB
  73. falist.set_alignment(threshold, alignment)
  74. self.assertEqual((threshold, alignment),
  75. falist.get_alignment())
  76. class TestPL(TestCase):
  77. def test_obj_track_times(self):
  78. """
  79. tests if the object track times set/get
  80. """
  81. # test for groups
  82. gcid = h5p.create(h5p.GROUP_CREATE)
  83. gcid.set_obj_track_times(False)
  84. self.assertEqual(False, gcid.get_obj_track_times())
  85. gcid.set_obj_track_times(True)
  86. self.assertEqual(True, gcid.get_obj_track_times())
  87. # test for datasets
  88. dcid = h5p.create(h5p.DATASET_CREATE)
  89. dcid.set_obj_track_times(False)
  90. self.assertEqual(False, dcid.get_obj_track_times())
  91. dcid.set_obj_track_times(True)
  92. self.assertEqual(True, dcid.get_obj_track_times())
  93. # test for generic objects
  94. ocid = h5p.create(h5p.OBJECT_CREATE)
  95. ocid.set_obj_track_times(False)
  96. self.assertEqual(False, ocid.get_obj_track_times())
  97. ocid.set_obj_track_times(True)
  98. self.assertEqual(True, ocid.get_obj_track_times())
  99. def test_link_creation_tracking(self):
  100. """
  101. tests the link creation order set/get
  102. """
  103. gcid = h5p.create(h5p.GROUP_CREATE)
  104. gcid.set_link_creation_order(0)
  105. self.assertEqual(0, gcid.get_link_creation_order())
  106. flags = h5p.CRT_ORDER_TRACKED | h5p.CRT_ORDER_INDEXED
  107. gcid.set_link_creation_order(flags)
  108. self.assertEqual(flags, gcid.get_link_creation_order())
  109. # test for file creation
  110. fcpl = h5p.create(h5p.FILE_CREATE)
  111. fcpl.set_link_creation_order(flags)
  112. self.assertEqual(flags, fcpl.get_link_creation_order())
  113. def test_attr_phase_change(self):
  114. """
  115. test the attribute phase change
  116. """
  117. cid = h5p.create(h5p.OBJECT_CREATE)
  118. # test default value
  119. ret = cid.get_attr_phase_change()
  120. self.assertEqual((8,6), ret)
  121. # max_compact must < 65536 (64kb)
  122. with self.assertRaises(ValueError):
  123. cid.set_attr_phase_change(65536, 6)
  124. # Using dense attributes storage to avoid 64kb size limitation
  125. # for a single attribute in compact attribute storage.
  126. cid.set_attr_phase_change(0, 0)
  127. self.assertEqual((0,0), cid.get_attr_phase_change())