Skip to content

Commit

Permalink
Merge pull request #1338 from effigies/mnt/coverage-fixes
Browse files Browse the repository at this point in the history
MNT: Update coverage config
  • Loading branch information
effigies authored Jul 9, 2024
2 parents 0a700fe + ee1c9c4 commit 08f5c44
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 52 deletions.
13 changes: 11 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
[run]
branch = True
source = nibabel
include = */nibabel/*
omit =
*/externals/*
*/benchmarks/*
*/tests/*
nibabel/_version.py

[report]
exclude_also =
def __repr__
if (ty\.|typing\.)?TYPE_CHECKING:
class .*\((ty\.|typing\.)Protocol\):
@(ty\.|typing\.)overload
if 0:
if __name__ == .__main__.:
@(abc\.)?abstractmethod
raise NotImplementedError
2 changes: 1 addition & 1 deletion nibabel/_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from .optpkg import optional_package

if ty.TYPE_CHECKING: # pragma: no cover
if ty.TYPE_CHECKING:
import indexed_gzip # type: ignore[import]
import pyzstd

Expand Down
12 changes: 5 additions & 7 deletions nibabel/arrayproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
KEEP_FILE_OPEN_DEFAULT = False


if ty.TYPE_CHECKING: # pragma: no cover
if ty.TYPE_CHECKING:
import numpy.typing as npt
from typing_extensions import Self # PY310

Expand All @@ -75,19 +75,17 @@ class ArrayLike(ty.Protocol):
shape: tuple[int, ...]

@property
def ndim(self) -> int: ... # pragma: no cover
def ndim(self) -> int: ...

# If no dtype is passed, any dtype might be returned, depending on the array-like
@ty.overload
def __array__(
self, dtype: None = ..., /
) -> np.ndarray[ty.Any, np.dtype[ty.Any]]: ... # pragma: no cover
def __array__(self, dtype: None = ..., /) -> np.ndarray[ty.Any, np.dtype[ty.Any]]: ...

# Any dtype might be passed, and *that* dtype must be returned
@ty.overload
def __array__(self, dtype: _DType, /) -> np.ndarray[ty.Any, _DType]: ... # pragma: no cover
def __array__(self, dtype: _DType, /) -> np.ndarray[ty.Any, _DType]: ...

def __getitem__(self, key, /) -> npt.NDArray: ... # pragma: no cover
def __getitem__(self, key, /) -> npt.NDArray: ...


class ArrayProxy(ArrayLike):
Expand Down
2 changes: 1 addition & 1 deletion nibabel/dataobj_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from .filebasedimages import FileBasedHeader, FileBasedImage
from .fileholders import FileMap

if ty.TYPE_CHECKING: # pragma: no cover
if ty.TYPE_CHECKING:
import numpy.typing as npt

from .filename_parser import FileSpec
Expand Down
2 changes: 1 addition & 1 deletion nibabel/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .deprecator import Deprecator
from .pkg_info import cmp_pkg_version

if ty.TYPE_CHECKING: # pragma: no cover
if ty.TYPE_CHECKING:
P = ty.ParamSpec('P')


Expand Down
2 changes: 1 addition & 1 deletion nibabel/deprecator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import warnings
from textwrap import dedent

if ty.TYPE_CHECKING: # pragma: no cover
if ty.TYPE_CHECKING:
T = ty.TypeVar('T')
P = ty.ParamSpec('P')

Expand Down
14 changes: 7 additions & 7 deletions nibabel/filebasedimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .filename_parser import TypesFilenamesError, _stringify_path, splitext_addext, types_filenames
from .openers import ImageOpener

if ty.TYPE_CHECKING: # pragma: no cover
if ty.TYPE_CHECKING:
from .filename_parser import ExtensionSpec, FileSpec

FileSniff = ty.Tuple[bytes, str]
Expand Down Expand Up @@ -54,13 +54,13 @@ def from_header(klass: type[HdrT], header: FileBasedHeader | ty.Mapping | None =

@classmethod
def from_fileobj(klass: type[HdrT], fileobj: io.IOBase) -> HdrT:
raise NotImplementedError # pragma: no cover
raise NotImplementedError

def write_to(self, fileobj: io.IOBase) -> None:
raise NotImplementedError # pragma: no cover
raise NotImplementedError

def __eq__(self, other: object) -> bool:
raise NotImplementedError # pragma: no cover
raise NotImplementedError

def __ne__(self, other: object) -> bool:
return not self == other
Expand Down Expand Up @@ -251,7 +251,7 @@ def from_filename(klass: type[ImgT], filename: FileSpec) -> ImgT:

@classmethod
def from_file_map(klass: type[ImgT], file_map: FileMap) -> ImgT:
raise NotImplementedError # pragma: no cover
raise NotImplementedError

@classmethod
def filespec_to_file_map(klass, filespec: FileSpec) -> FileMap:
Expand Down Expand Up @@ -308,7 +308,7 @@ def to_filename(self, filename: FileSpec, **kwargs) -> None:
self.to_file_map(**kwargs)

def to_file_map(self, file_map: FileMap | None = None, **kwargs) -> None:
raise NotImplementedError # pragma: no cover
raise NotImplementedError

@classmethod
def make_file_map(klass, mapping: ty.Mapping[str, str | io.IOBase] | None = None) -> FileMap:
Expand Down Expand Up @@ -373,7 +373,7 @@ def from_image(klass: type[ImgT], img: FileBasedImage) -> ImgT:
img : ``FileBasedImage`` instance
Image, of our own class
"""
raise NotImplementedError # pragma: no cover
raise NotImplementedError

@classmethod
def _sniff_meta_for(
Expand Down
2 changes: 1 addition & 1 deletion nibabel/filename_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pathlib
import typing as ty

if ty.TYPE_CHECKING: # pragma: no cover
if ty.TYPE_CHECKING:
FileSpec = str | os.PathLike[str]
ExtensionSpec = tuple[str, str | None]

Expand Down
2 changes: 1 addition & 1 deletion nibabel/loadsave.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
_compressed_suffixes = ('.gz', '.bz2', '.zst')


if ty.TYPE_CHECKING: # pragma: no cover
if ty.TYPE_CHECKING:
from .filebasedimages import FileBasedImage
from .filename_parser import FileSpec

Expand Down
6 changes: 2 additions & 4 deletions nibabel/onetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,10 @@ def __init__(self, func: ty.Callable[[InstanceT], T]) -> None:
@ty.overload
def __get__(
self, obj: None, objtype: type[InstanceT] | None = None
) -> ty.Callable[[InstanceT], T]: ... # pragma: no cover
) -> ty.Callable[[InstanceT], T]: ...

@ty.overload
def __get__(
self, obj: InstanceT, objtype: type[InstanceT] | None = None
) -> T: ... # pragma: no cover
def __get__(self, obj: InstanceT, objtype: type[InstanceT] | None = None) -> T: ...

def __get__(
self, obj: InstanceT | None, objtype: type[InstanceT] | None = None
Expand Down
7 changes: 3 additions & 4 deletions nibabel/openers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from ._compression import HAVE_INDEXED_GZIP, IndexedGzipFile, pyzstd

if ty.TYPE_CHECKING: # pragma: no cover
if ty.TYPE_CHECKING:
from types import TracebackType

from _typeshed import WriteableBuffer
Expand All @@ -36,9 +36,8 @@

@ty.runtime_checkable
class Fileish(ty.Protocol):
def read(self, size: int = -1, /) -> bytes: ... # pragma: no cover

def write(self, b: bytes, /) -> int | None: ... # pragma: no cover
def read(self, size: int = -1, /) -> bytes: ...
def write(self, b: bytes, /) -> int | None: ...


class DeterministicGzipFile(gzip.GzipFile):
Expand Down
8 changes: 3 additions & 5 deletions nibabel/pointset.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from nibabel.fileslice import strided_scalar
from nibabel.spatialimages import SpatialImage

if ty.TYPE_CHECKING: # pragma: no cover
if ty.TYPE_CHECKING:
from typing_extensions import Self

_DType = ty.TypeVar('_DType', bound=np.dtype[ty.Any])
Expand All @@ -41,12 +41,10 @@ class CoordinateArray(ty.Protocol):
shape: tuple[int, int]

@ty.overload
def __array__(
self, dtype: None = ..., /
) -> np.ndarray[ty.Any, np.dtype[ty.Any]]: ... # pragma: no cover
def __array__(self, dtype: None = ..., /) -> np.ndarray[ty.Any, np.dtype[ty.Any]]: ...

@ty.overload
def __array__(self, dtype: _DType, /) -> np.ndarray[ty.Any, _DType]: ... # pragma: no cover
def __array__(self, dtype: _DType, /) -> np.ndarray[ty.Any, _DType]: ...


@dataclass
Expand Down
15 changes: 6 additions & 9 deletions nibabel/spatialimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,23 @@
except ImportError: # PY38
from functools import lru_cache as cache

if ty.TYPE_CHECKING: # pragma: no cover
if ty.TYPE_CHECKING:
import numpy.typing as npt

SpatialImgT = ty.TypeVar('SpatialImgT', bound='SpatialImage')
SpatialHdrT = ty.TypeVar('SpatialHdrT', bound='SpatialHeader')


class HasDtype(ty.Protocol):
def get_data_dtype(self) -> np.dtype: ... # pragma: no cover

def set_data_dtype(self, dtype: npt.DTypeLike) -> None: ... # pragma: no cover
def get_data_dtype(self) -> np.dtype: ...
def set_data_dtype(self, dtype: npt.DTypeLike) -> None: ...


@ty.runtime_checkable
class SpatialProtocol(ty.Protocol):
def get_data_dtype(self) -> np.dtype: ... # pragma: no cover

def get_data_shape(self) -> ty.Tuple[int, ...]: ... # pragma: no cover

def get_zooms(self) -> ty.Tuple[float, ...]: ... # pragma: no cover
def get_data_dtype(self) -> np.dtype: ...
def get_data_shape(self) -> ty.Tuple[int, ...]: ...
def get_zooms(self) -> ty.Tuple[float, ...]: ...


class HeaderDataError(Exception):
Expand Down
6 changes: 3 additions & 3 deletions nibabel/volumeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .casting import OK_FLOATS, shared_range
from .externals.oset import OrderedSet

if ty.TYPE_CHECKING: # pragma: no cover
if ty.TYPE_CHECKING:
import numpy.typing as npt

Scalar = np.number | float
Expand Down Expand Up @@ -1191,13 +1191,13 @@ def _ftype4scaled_finite(
@ty.overload
def finite_range(
arr: npt.ArrayLike, check_nan: ty.Literal[False] = False
) -> tuple[Scalar, Scalar]: ... # pragma: no cover
) -> tuple[Scalar, Scalar]: ...


@ty.overload
def finite_range(
arr: npt.ArrayLike, check_nan: ty.Literal[True]
) -> tuple[Scalar, Scalar, bool]: ... # pragma: no cover
) -> tuple[Scalar, Scalar, bool]: ...


def finite_range(
Expand Down
8 changes: 4 additions & 4 deletions nibabel/xmlutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class XmlSerializable:

def _to_xml_element(self) -> Element:
"""Output should be a xml.etree.ElementTree.Element"""
raise NotImplementedError # pragma: no cover
raise NotImplementedError

def to_xml(self, enc='utf-8', **kwargs) -> bytes:
r"""Generate an XML bytestring with a given encoding.
Expand Down Expand Up @@ -109,10 +109,10 @@ def parse(self, string=None, fname=None, fptr=None):
parser.ParseFile(fptr)

def StartElementHandler(self, name, attrs):
raise NotImplementedError # pragma: no cover
raise NotImplementedError

def EndElementHandler(self, name):
raise NotImplementedError # pragma: no cover
raise NotImplementedError

def CharacterDataHandler(self, data):
raise NotImplementedError # pragma: no cover
raise NotImplementedError
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ doc = [
"tomli; python_version < '3.11'",
]
test = [
"pytest<8.1", # relax once pytest-doctestplus releases 1.2.0
"pytest",
"pytest-doctestplus",
"pytest-cov",
"pytest-httpserver",
"pytest-xdist",
"coverage>=7.2",
]
# Remaining: Simpler to centralize in tox
dev = ["tox"]
Expand Down

0 comments on commit 08f5c44

Please sign in to comment.