From 5bd9d2a192b2741c1d84bfbced9eb4757b34efe3 Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Tue, 5 Dec 2023 13:37:52 +0100 Subject: [PATCH] Add a module script to run h5py tests with a patched dataset class. Since additional dependencies are required by h5py tests, a package extra has been added to require them. --- README.rst | 2 ++ b2h5py/tests/test_patched_h5py.py | 28 ++++++++++++++++++++++++++++ pyproject.toml | 6 ++++++ 3 files changed, 36 insertions(+) create mode 100644 b2h5py/tests/test_patched_h5py.py diff --git a/README.rst b/README.rst index 9d55c43..c1bf532 100644 --- a/README.rst +++ b/README.rst @@ -43,3 +43,5 @@ Running tests If you have installed ``b2h5py``, just run ``python -m unittest discover b2h5py.tests``. Otherwise, just enter its source code directory and run ``python -m unittest``. + +You can also run the h5py tests with the patched ``Dataset`` class to check that patching does not break anything. You may install the ``h5py-test`` extra (e.g. ``pip install b2h5py[h5py-test]`` and run ``python -m b2h5py.tests.test_patched_h5py``. diff --git a/b2h5py/tests/test_patched_h5py.py b/b2h5py/tests/test_patched_h5py.py new file mode 100644 index 0000000..1adcc8f --- /dev/null +++ b/b2h5py/tests/test_patched_h5py.py @@ -0,0 +1,28 @@ +"""Run h5py unit tests with patched dataset class. + +This module does not provide test cases, but it calls the h5py tests directly. +You may run it with ``python -m b2h5py.tests.test_patched_h5py``. + +This module has additional dependencies. You may want to install this +package's ``h5py-test`` extra. +""" + +import os +import unittest + +import b2h5py +import h5py +import h5py.tests + + +def run_h5py_tests(): + """Run h5py unit tests with patched dataset class""" + test_suite = unittest.defaultTestLoader.discover( + os.path.dirname(h5py.tests.__file__), + top_level_dir=os.path.dirname(os.path.dirname(h5py.__file__))) + test_runner = unittest.TextTestRunner() + test_runner.run(test_suite) + + +if __name__ == '__main__': + run_h5py_tests() diff --git a/pyproject.toml b/pyproject.toml index 968a356..d35fad4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,3 +32,9 @@ dependencies = [ [project.urls] Homepage = "https://github.com/Blosc/b2h5py" Issues = "https://github.com/Blosc/b2h5py/issues" + +[project.optional-dependencies] +h5py-test = [ + # "h5py[test]", # no such extra in h5py + "pytest", # to run h5py tests +]