|
| 1 | +""" |
| 2 | +These tests are almost certainly overkill, but serve to verify that |
| 3 | +the behavior of _h5py_compat is pass-through in all but a small set of |
| 4 | +well-defined cases |
| 5 | +""" |
| 6 | +import sys |
| 7 | +import os |
| 8 | +from distutils.version import LooseVersion |
| 9 | +import numpy as np |
| 10 | + |
| 11 | +from ..optpkg import optional_package |
| 12 | +from .. import _h5py_compat as compat |
| 13 | +from ..testing import assert_equal, assert_true, assert_false, assert_not_equal |
| 14 | + |
| 15 | +h5py, have_h5py, _ = optional_package('h5py') |
| 16 | + |
| 17 | + |
| 18 | +def test_optpkg_equivalence(): |
| 19 | + # No effect on Linux/OSX |
| 20 | + if os.name == 'posix': |
| 21 | + assert_equal(have_h5py, compat.have_h5py) |
| 22 | + # No effect on Python 2.7 or 3.6+ |
| 23 | + if sys.version_info >= (3, 6) or sys.version_info < (3,): |
| 24 | + assert_equal(have_h5py, compat.have_h5py) |
| 25 | + # Available in a strict subset of cases |
| 26 | + if not have_h5py: |
| 27 | + assert_false(compat.have_h5py) |
| 28 | + # Available when version is high enough |
| 29 | + elif LooseVersion(h5py.__version__) >= '2.10': |
| 30 | + assert_true(compat.have_h5py) |
| 31 | + |
| 32 | + |
| 33 | +def test_disabled_h5py_cases(): |
| 34 | + # On mismatch |
| 35 | + if have_h5py and not compat.have_h5py: |
| 36 | + # Recapitulate min_h5py conditions from _h5py_compat |
| 37 | + assert_equal(os.name, 'nt') |
| 38 | + assert_true((3,) <= sys.version_info < (3, 6)) |
| 39 | + assert_true(LooseVersion(h5py.__version__) < '2.10') |
| 40 | + # Verify that the root cause is present |
| 41 | + # If any tests fail, they will likely be these, so they may be |
| 42 | + # ill-advised... |
| 43 | + assert_equal(str(np.longdouble), str(np.float64)) |
| 44 | + assert_not_equal(np.longdouble, np.float64) |
0 commit comments