silx-kit / h5web

React components for data visualization and exploration
https://h5web.panosc.eu/
MIT License
167 stars 17 forks source link

Test `H5WasmApi` #1550

Closed axelboc closed 5 months ago

axelboc commented 5 months ago

The goal of this PR is to test the low-level H5WasmApi class — more specifically, the metadata and values it returns for HDF5 datasets with various types and shapes.

To do so, I've written a Python script (inspired from silx' script) to generate a sample HDF5 file with h5py. In this file, I try to generate HDF5 datasets of as many kinds as I can (H5T_INTEGER, H5T_COMPOUND, etc.) and with as many interesting dtype combinations as I can think of (int8, complex64, etc.).

The idea is to be able to test:

More specifically, this test will help identify:

I purposely did not to add any attributes to the sample file, as they didn't seem to add any testing value (the dtype parsing is the same, and h5wasm reads/processes datasets and attributes values the same way ... I hope). I also did not add groups, links, datatypes, and NeXus/RGB/scatter data as this falls out of the scope of what I'm wanting to test (at least for the moment).

You can explore the sample file here: https://h5web.panosc.eu/h5wasm?url=https%3A%2F%2Fwww.silx.org%2Fpub%2Fh5web%2Fsample.h5

The test itself consists in a single, very basic snapshot test:

  1. I start by loading the sample file, initialising the API and calling api.getEntity('/') to get the metadata of the root group and its children;
  2. Then, for each child dataset, I get the metadata I'm interested in and request the dataset's value with api.getValue({ dataset }). (I've kept the sample file flat to keep this test code as concise as possible.)
  3. Finally, I take a snapshot of this array of dataset metadata+values. If the snapshot matches the existing, committed snapshot, then the test passes; otherwise it fails.