Skip to content

Commit

Permalink
Improve codebase coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed May 19, 2024
1 parent 7509b41 commit 5578810
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 27 deletions.
2 changes: 1 addition & 1 deletion colour/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ def __getattr__(self, attribute) -> Any:
# - https://github.com/colour-science/colour/issues/958
# - https://github.com/colour-science/colour/issues/1221
# - https://github.com/vaab/colour/issues/62
for _path in sys.path:
for _path in sys.path: # pragma: no cover
_module_path = os.path.join(_path, "colour.py")
if os.path.exists(_module_path):
import colour # pyright: ignore
Expand Down
11 changes: 11 additions & 0 deletions colour/algebra/tests/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,17 @@ def test_required_methods(self):
for method in required_methods: # pragma: no cover
assert method in dir(PchipInterpolator)

def test_y(self):
"""
Test :attr:`colour.algebra.interpolation.PchipInterpolator.y` property.
"""

interpolator = PchipInterpolator(np.linspace(0, 1, 10), np.linspace(0, 1, 10))

interpolator.y = np.linspace(0, 1, 10)

assert interpolator(5) == 5


class TestNullInterpolator:
"""
Expand Down
2 changes: 1 addition & 1 deletion colour/colorimetry/tests/test_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ def test__eq__(self):
"""

assert SpectralShape(0, 10, 0.1) == SpectralShape(0, 10, 0.1)
assert SpectralShape(0, 10, 0.1) is not None
assert SpectralShape(0, 10, 0.1) != ()

def test__ne__(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion colour/continuous/tests/test_multi_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def test__eq__(self):

assert signal_1 == signal_2

assert signal_1 is not None
assert signal_1 != ()

def test__ne__(self):
"""
Expand Down
6 changes: 3 additions & 3 deletions colour/hints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
NDArrayStr = NDArray[np.str_]


class ProtocolInterpolator(Protocol): # noqa: D101
class ProtocolInterpolator(Protocol): # noqa: D101 # pragma: no cover
@property
def x(self) -> NDArray: # noqa: D102
...
Expand All @@ -167,7 +167,7 @@ def __call__(self, x: ArrayLike) -> NDArray: # noqa: D102
... # pragma: no cover


class ProtocolExtrapolator(Protocol): # noqa: D101
class ProtocolExtrapolator(Protocol): # noqa: D101 # pragma: no cover
@property
def interpolator(self) -> ProtocolInterpolator: # noqa: D102
...
Expand All @@ -184,7 +184,7 @@ def __call__(self, x: ArrayLike) -> NDArray: # noqa: D102


@runtime_checkable
class ProtocolLUTSequenceItem(Protocol): # noqa: D101
class ProtocolLUTSequenceItem(Protocol): # noqa: D101 # pragma: no cover
def apply(self, RGB: ArrayLike, **kwargs: Any) -> NDArray: # noqa: D102
... # pragma: no cover

Expand Down
3 changes: 2 additions & 1 deletion colour/io/tests/test_tm2714.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ def test__eq__(self):
"""Test :meth:`colour.io.tm2714.Header_IESTM2714.__eq__` method."""

header = deepcopy(self._header)

assert self._header == header

assert self._header is not None
assert self._header != ()

def test__ne__(self):
"""Test :meth:`colour.io.tm2714.Header_IESTM2714.__ne__` method."""
Expand Down
4 changes: 2 additions & 2 deletions colour/io/tm2714.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ def __str__(self) -> str:
{"formatter": lambda x: str_parent}, # noqa: ARG005
],
)
except TypeError:
except TypeError: # pragma: no cover
return super().__str__()

def __repr__(self) -> str:
Expand Down Expand Up @@ -1635,7 +1635,7 @@ def __repr__(self) -> str:
{"name": "extrapolator_kwargs"},
],
)
except TypeError:
except TypeError: # pragma: no cover
return super().__repr__()

def read(self) -> SpectralDistribution_IESTM2714:
Expand Down
3 changes: 0 additions & 3 deletions colour/models/rgb/rgb_colourspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,9 +811,6 @@ def _derive_transformation_matrices(self):
matrix and its inverse.
"""

if not hasattr(self, "_primaries") or not hasattr(self, "_whitepoint"):
return

if self._primaries is not None and self._whitepoint is not None:
npm = normalised_primary_matrix(self._primaries, self._whitepoint)

Expand Down
2 changes: 1 addition & 1 deletion colour/plotting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from colour.utilities import is_matplotlib_installed

if not is_matplotlib_installed():
if not is_matplotlib_installed(): # pragma: no cover
import sys
from unittest.mock import MagicMock
from colour.utilities import usage_warning
Expand Down
2 changes: 1 addition & 1 deletion colour/plotting/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def plot_automatic_colour_conversion_graph(
filename: str,
prog: (Literal["circo", "dot", "fdp", "neato", "nop", "twopi"] | str) = "fdp",
args: str = "",
) -> AGraph: # pyright: ignore # noqa: F821
) -> AGraph: # pyright: ignore # noqa: F821 # pragma: no cover
"""
Plot *Colour* automatic colour conversion graph using
`Graphviz <https://www.graphviz.org>`__ and
Expand Down
3 changes: 1 addition & 2 deletions colour/plotting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1989,8 +1989,7 @@ def _linear_equation(
RGB_cr = XYZ_to_RGB(XYZ_cr, colourspace, xy_r, apply_cctf_encoding=True)
RGB_cr = np.clip(np.ravel(RGB_cr), 0, 1)
else:
scatter_settings["c"] = CONSTANTS_COLOUR_STYLE.colour.dark
RGB_cr = CONSTANTS_COLOUR_STYLE.colour.dark
RGB_cr = scatter_settings["c"]

axes.scatter(ijk_ct[..., 0], ijk_ct[..., 1], **scatter_settings)

Expand Down
5 changes: 5 additions & 0 deletions colour/plotting/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,8 @@ def test_plot_constant_hue_loci(self):

assert isinstance(figure, Figure)
assert isinstance(axes, Axes)

figure, axes = plot_constant_hue_loci(data, "IPT", scatter_kwargs={"c": "k"})

assert isinstance(figure, Figure)
assert isinstance(axes, Axes)
11 changes: 9 additions & 2 deletions colour/quality/cfi2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,15 @@ def tcs_colorimetry_data(
Examples
--------
>>> delta_E_to_R_f(4.4410383190) # doctest: +ELLIPSIS
70.1208254...
>>> from colour.colorimetry import SDS_ILLUMINANTS
>>> sd = SDS_ILLUMINANTS["FL2"]
>>> shape = SpectralShape(380, 780, 5)
>>> cmfs = MSDS_CMFS["CIE 1964 10 Degree Standard Observer"].copy().align(shape)
>>> test_tcs_colorimetry_data = tcs_colorimetry_data(
... sd, load_TCS_CIE2017(shape), cmfs
... )
>>> len(test_tcs_colorimetry_data)
1
"""

if isinstance(sd_irradiance, SpectralDistribution):
Expand Down
10 changes: 10 additions & 0 deletions colour/quality/tests/test_cfi2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@
SD_SAMPLE_5NM: SpectralDistribution = SpectralDistribution(DATA_SD_SAMPLE_5NM)

DATA_SD_SAMPLE_1NM: dict = {
370: 0.000,
371: 0.000,
372: 0.000,
373: 0.000,
374: 0.000,
375: 0.000,
376: 0.000,
377: 0.000,
378: 0.000,
379: 0.000,
380: 0.000,
381: 0.000,
382: 0.000,
Expand Down
3 changes: 2 additions & 1 deletion colour/recovery/jakob2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ def __init__(self) -> None:
self._interpolator: RegularGridInterpolator = RegularGridInterpolator(
np.array([]), np.array([])
)

self._size: int = 0
self._lightness_scale: NDArrayFloat = np.array([])
self._coefficients: NDArrayFloat = np.array([])
Expand Down Expand Up @@ -998,7 +999,7 @@ def RGB_to_coefficients(self, RGB: ArrayLike) -> NDArrayFloat:
array([ 1.5013448...e-04, -1.4679754...e-01, 3.4020219...e+01])
"""

if self._interpolator is not None:
if len(self._interpolator.grid) != 0:
RGB = as_float_array(RGB)

value_max = np.max(RGB, axis=-1)
Expand Down
2 changes: 1 addition & 1 deletion colour/recovery/tests/test_jakob2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def test_raise_exception_RGB_to_coefficients(self):

LUT = LUT3D_Jakob2019()

pytest.raises(ValueError, LUT.RGB_to_coefficients, np.array([]))
pytest.raises(RuntimeError, LUT.RGB_to_coefficients, np.array([1, 2, 3, 4]))

def test_raise_exception_read(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion colour/utilities/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def unregister_callback(self, attribute: str, name: str) -> None:
defaultdict(<class 'list'>, {})
"""

if self._callbacks.get(attribute) is None:
if self._callbacks.get(attribute) is None: # pragma: no cover
return

self._callbacks[attribute] = [
Expand Down
2 changes: 1 addition & 1 deletion colour/utilities/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,4 +1611,4 @@ def int_digest(
return -1

else:
int_digest = hash # pyright: ignore
int_digest = hash # pyright: ignore # pragma: no cover
2 changes: 1 addition & 1 deletion colour/utilities/tests/test_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _on_attribute_a_changed(self, name: str, value: str) -> str:
value = value.upper()

if getattr(self, name) != "a":
raise RuntimeError(
raise RuntimeError( # pragma: no cover
'"self" was not able to retrieve class instance value!'
)

Expand Down
6 changes: 3 additions & 3 deletions colour/utilities/verbose.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def __exit__(self, *args: Any):
sys.stdout.close()
sys.stdout = self._stdout

def __call__(self, function: Callable) -> Callable:
def __call__(self, function: Callable) -> Callable: # pragma: no cover
"""Call the wrapped definition."""

@functools.wraps(function)
Expand Down Expand Up @@ -825,7 +825,7 @@ def _get_package_version(package: str, mapping: Mapping) -> str:
lines = value.split("\n")
message += f" {key} : {lines.pop(0)}\n"
indentation = len(f" {key} : ")
for line in lines:
for line in lines: # pragma: no cover
message += f"{' ' * indentation}{line}\n"

message += "\n"
Expand Down Expand Up @@ -937,7 +937,7 @@ def multiline_str(
and not attribute.get("section")
)
)
except ValueError:
except ValueError: # pragma: no cover
justify = 0

representation = []
Expand Down
2 changes: 1 addition & 1 deletion colour/volume/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def XYZ_outer_surface(
)
XYZ = _CACHE_OUTER_SURFACE_XYZ.get(key)

if is_caching_enabled() and XYZ is not None:
if is_caching_enabled() and XYZ is not None: # pragma: no cover
return XYZ

pulse_waves = generate_pulse_waves(
Expand Down

0 comments on commit 5578810

Please sign in to comment.