diff --git a/docs/conf.py b/docs/conf.py index fc0964d3..44358848 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,6 +13,7 @@ "autoapi.extension", "m2r2", "sphinx.ext.autodoc", + "sphinx.ext.doctest", "sphinx.ext.intersphinx", "sphinx.ext.napoleon", "sphinx.ext.viewcode", diff --git a/src/nitypes/_arguments.py b/src/nitypes/_arguments.py index 948b729a..9fd2a69e 100644 --- a/src/nitypes/_arguments.py +++ b/src/nitypes/_arguments.py @@ -16,7 +16,12 @@ # Some of these doctests use types introduced in NumPy 2.0 (np.long and np.ulong) or highlight # formatting differences between NumPy 1.x and 2.x (e.g. dtype=int32, 1.23 vs. np.float64(1.23)). -__doctest_requires__ = {("arg_to_float", "is_dtype", "validate_dtype"): ["numpy>=2.0"]} +# The following line is commented out as workaround for technical debt #251. +# __doctest_requires__ = {("arg_to_float", "is_dtype", "validate_dtype"): ["numpy>=2.0"]} +# When the technical debt is resolved, uncomment the line above +# and remove testsetup blocks that include comments like the one below: +# # Workaround for technical debt #251: Skip doctest if numpy<2.0 +# >>> pytest.skip("requires numpy>=2.0") if version_check else None # doctest: +SKIP def arg_to_float( @@ -24,6 +29,14 @@ def arg_to_float( ) -> float: """Convert an argument to a float. + .. testsetup:: + + # Workaround for technical debt #251: Skip doctest if numpy<2.0 + import numpy as np + import pytest + numpy_version = tuple(map(int, np.__version__.split(".")[:2])) < (2, 0) + pytest.skip("requires numpy>=2.0") if numpy_version else None + >>> arg_to_float("xyz", 1.234) 1.234 >>> arg_to_float("xyz", 1234) @@ -143,6 +156,14 @@ def is_dtype(dtype: npt.DTypeLike, supported_dtypes: tuple[npt.DTypeLike, ...]) Unlike :any:`numpy.isdtype`, this function supports structured data types. + .. testsetup:: + + # Workaround for technical debt #251: Skip doctest if numpy<2.0 + import numpy as np + import pytest + numpy_version = tuple(map(int, np.__version__.split(".")[:2])) < (2, 0) + pytest.skip("requires numpy>=2.0") if numpy_version else None + >>> is_dtype(np.float64, (np.float64, np.intc, np.long,)) True >>> is_dtype("float64", (np.float64, np.intc, np.long,)) @@ -172,6 +193,14 @@ def is_dtype(dtype: npt.DTypeLike, supported_dtypes: tuple[npt.DTypeLike, ...]) def validate_dtype(dtype: npt.DTypeLike, supported_dtypes: tuple[npt.DTypeLike, ...]) -> None: """Validate a dtype-like object against a tuple of supported dtype-like objects. + .. testsetup:: + + # Workaround for technical debt #251: Skip doctest if numpy<2.0 + import numpy as np + import pytest + numpy_version = tuple(map(int, np.__version__.split(".")[:2])) < (2, 0) + pytest.skip("requires numpy>=2.0") if numpy_version else None + >>> validate_dtype(np.float64, (np.float64, np.intc, np.long,)) >>> validate_dtype("float64", (np.float64, np.intc, np.long,)) >>> validate_dtype(np.float64, (np.byte, np.short, np.intc, np.int_, np.long, np.longlong)) diff --git a/src/nitypes/complex/__init__.py b/src/nitypes/complex/__init__.py index e904f485..07e2a4e3 100644 --- a/src/nitypes/complex/__init__.py +++ b/src/nitypes/complex/__init__.py @@ -27,6 +27,14 @@ You can construct an array of complex integers from a sequence of tuples using :func:`numpy.array`: +.. testsetup:: + + # Workaround for technical debt #251: Skip doctest if numpy<2.0 + import numpy as np + import pytest + numpy_version = tuple(map(int, np.__version__.split(".")[:2])) < (2, 0) + pytest.skip("requires numpy>=2.0") if numpy_version else None + >>> import numpy as np >>> np.array([(1, 2), (3, 4)], dtype=ComplexInt32DType) array([(1, 2), (3, 4)], dtype=[('real', '=2.0"]} +# The following line is commented out as workaround for technical debt #251. +# __doctest_requires__ = {".": ["numpy>=2.0"]} +# When the technical debt is resolved, uncomment the line above +# and remove testsetup blocks that include comments like the one below: +# # Workaround for technical debt #251: Skip doctest if numpy<2.0