Skip to content

Commit

Permalink
Add a module script to run h5py tests with a patched dataset class.
Browse files Browse the repository at this point in the history
Since additional dependencies are required by h5py tests, a package extra has
been added to require them.
  • Loading branch information
ivilata committed Dec 5, 2023
1 parent 85cc9e6 commit 5bd9d2a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
28 changes: 28 additions & 0 deletions b2h5py/tests/test_patched_h5py.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

0 comments on commit 5bd9d2a

Please sign in to comment.