test_h5z.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. from ctypes import (
  2. addressof,
  3. c_char_p,
  4. c_int,
  5. c_long,
  6. c_uint,
  7. c_void_p,
  8. CFUNCTYPE,
  9. POINTER,
  10. Structure,
  11. )
  12. import pytest
  13. import h5py
  14. from h5py import h5z
  15. from .common import insubprocess
  16. # Type of filter callback function of H5Z_class2_t
  17. H5ZFuncT = CFUNCTYPE(
  18. c_long, # restype
  19. # argtypes
  20. c_uint, # flags
  21. c_long, # cd_nelemts
  22. POINTER(c_uint), # cd_values
  23. c_long, # nbytes
  24. POINTER(c_long), # buf_size
  25. POINTER(c_void_p), # buf
  26. )
  27. class H5ZClass2T(Structure):
  28. """H5Z_class2_t structure defining a filter"""
  29. _fields_ = [
  30. ("version", c_int),
  31. ("id_", c_int),
  32. ("encoder_present", c_uint),
  33. ("decoder_present", c_uint),
  34. ("name", c_char_p),
  35. ("can_apply", c_void_p),
  36. ("set_local", c_void_p),
  37. ("filter_", H5ZFuncT),
  38. ]
  39. @pytest.mark.thread_unsafe(reason="fixed filter_id")
  40. def test_register_filter():
  41. filter_id = 256 # Test ID
  42. @H5ZFuncT
  43. def failing_filter_callback(flags, cd_nelemts, cd_values, nbytes, buf_size, buf):
  44. return 0
  45. dummy_filter_class = H5ZClass2T(
  46. version=h5z.CLASS_T_VERS,
  47. id_=filter_id,
  48. encoder_present=1,
  49. decoder_present=1,
  50. name=b"dummy filter",
  51. can_apply=None,
  52. set_local=None,
  53. filter_=failing_filter_callback,
  54. )
  55. h5z.register_filter(addressof(dummy_filter_class))
  56. try:
  57. assert h5z.filter_avail(filter_id)
  58. filter_flags = h5z.get_filter_info(filter_id)
  59. assert (
  60. filter_flags
  61. == h5z.FILTER_CONFIG_ENCODE_ENABLED | h5z.FILTER_CONFIG_DECODE_ENABLED
  62. )
  63. finally:
  64. h5z.unregister_filter(filter_id)
  65. assert not h5z.filter_avail(filter_id)
  66. @pytest.mark.mpi_skip
  67. @insubprocess
  68. def test_unregister_filter(request):
  69. if h5py.h5z.filter_avail(h5py.h5z.FILTER_LZF):
  70. res = h5py.h5z.unregister_filter(h5py.h5z.FILTER_LZF)
  71. assert res