def test_write_filtered_data(compression, shuffle, fletcher32,
                             gzip_level):

    # Make some random data. The dtype must be restricted so that it can
    # be read back reliably.
    dims = random.randint(1, 4)
    dts = tuple(set(dtypes) - set(['U', 'S', 'bool', 'complex64', \
        'complex128']))

    data = random_numpy(shape=random_numpy_shape(dims,
                        max_array_axis_length),
                        dtype=random.choice(dts))
    # Make a random name.
    name = random_name()

    # Write the data to the file with the given name with the provided
    # filters and read it back.
    with tempfile.TemporaryDirectory() as folder:
        filename = os.path.join(folder, 'data.h5')
        hdf5storage.write(data, path=name, filename=filename,
                          store_python_metadata=False,
                          matlab_compatible=False,
                          compress=True, compress_size_threshold=0,
                          compression_algorithm=compression,
                          gzip_compression_level=gzip_level,
                          shuffle_filter=shuffle,
                          compressed_fletcher32_filter=fletcher32)

        with h5py.File(filename, mode='r') as f:
            d = f[name]
            filts = {'fletcher32': d.fletcher32,
                     'shuffle': d.shuffle,
                     'compression': d.compression,
                     'gzip_level': d.compression_opts}
            out = d[...]

    # Check the filters
    assert fletcher32 == filts['fletcher32']
    assert shuffle == filts['shuffle']
    assert compression == filts['compression']
    if compression == 'gzip':
        assert gzip_level == filts['gzip_level']

    # Compare
    assert_equal(out, data)