1import unittest
2from unittest.mock import patch
3import os
4
5from ont_fast5_api.compression_settings import register_plugin
6
7class TestCheckCompression(unittest.TestCase):
8
9    def test_register_plugin_no_prepend(self):
10        # GIVEN a version of h5py that has the h5pl module
11        with patch('h5py.h5pl', create=True) as mock:
12
13            # WHEN h5py.h5pl doesn't have the prepend method
14            del mock.prepend
15            # and the hdf5 plugin path variable hasn't been set
16            if 'HDF5_PLUGIN_PATH' in os.environ:
17                del os.environ['HDF5_PLUGIN_PATH']
18            self.assertTrue('HDF5_PLUGIN_PATH' not in os.environ)
19
20            # THEN when we try and register the vbz plugin we fall back to setting
21            # HDF5_PLUGIN_PATH (because we can't use prepend)
22            plugin_path = register_plugin()
23            self.assertTrue(os.environ['HDF5_PLUGIN_PATH'] == plugin_path)
24
25
26