From 55788108895e9e5cf738b5d3aa1d7d432e413512 Mon Sep 17 00:00:00 2001 From: Thomas Mansencal Date: Sun, 19 May 2024 21:08:05 +1200 Subject: [PATCH] Improve codebase coverage. --- colour/__init__.py | 2 +- colour/algebra/tests/test_interpolation.py | 11 +++++++++++ colour/colorimetry/tests/test_spectrum.py | 2 +- colour/continuous/tests/test_multi_signal.py | 2 +- colour/hints/__init__.py | 6 +++--- colour/io/tests/test_tm2714.py | 3 ++- colour/io/tm2714.py | 4 ++-- colour/models/rgb/rgb_colourspace.py | 3 --- colour/plotting/__init__.py | 2 +- colour/plotting/graph.py | 2 +- colour/plotting/models.py | 3 +-- colour/plotting/tests/test_models.py | 5 +++++ colour/quality/cfi2017.py | 11 +++++++++-- colour/quality/tests/test_cfi2017.py | 10 ++++++++++ colour/recovery/jakob2019.py | 3 ++- colour/recovery/tests/test_jakob2019.py | 2 +- colour/utilities/callback.py | 2 +- colour/utilities/common.py | 2 +- colour/utilities/tests/test_callback.py | 2 +- colour/utilities/verbose.py | 6 +++--- colour/volume/spectrum.py | 2 +- 21 files changed, 58 insertions(+), 27 deletions(-) diff --git a/colour/__init__.py b/colour/__init__.py index eb2338739..62c6abfdf 100644 --- a/colour/__init__.py +++ b/colour/__init__.py @@ -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 diff --git a/colour/algebra/tests/test_interpolation.py b/colour/algebra/tests/test_interpolation.py index 479a69b66..de0106389 100644 --- a/colour/algebra/tests/test_interpolation.py +++ b/colour/algebra/tests/test_interpolation.py @@ -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: """ diff --git a/colour/colorimetry/tests/test_spectrum.py b/colour/colorimetry/tests/test_spectrum.py index e82743cf0..4007f3323 100644 --- a/colour/colorimetry/tests/test_spectrum.py +++ b/colour/colorimetry/tests/test_spectrum.py @@ -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): """ diff --git a/colour/continuous/tests/test_multi_signal.py b/colour/continuous/tests/test_multi_signal.py index e768b8de6..5897d4b2f 100644 --- a/colour/continuous/tests/test_multi_signal.py +++ b/colour/continuous/tests/test_multi_signal.py @@ -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): """ diff --git a/colour/hints/__init__.py b/colour/hints/__init__.py index 3c8761c12..13ff1ee78 100644 --- a/colour/hints/__init__.py +++ b/colour/hints/__init__.py @@ -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 ... @@ -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 ... @@ -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 diff --git a/colour/io/tests/test_tm2714.py b/colour/io/tests/test_tm2714.py index be0a970ee..7f04da4df 100644 --- a/colour/io/tests/test_tm2714.py +++ b/colour/io/tests/test_tm2714.py @@ -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.""" diff --git a/colour/io/tm2714.py b/colour/io/tm2714.py index 8507c87a6..707caa8f7 100644 --- a/colour/io/tm2714.py +++ b/colour/io/tm2714.py @@ -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: @@ -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: diff --git a/colour/models/rgb/rgb_colourspace.py b/colour/models/rgb/rgb_colourspace.py index be07a70f5..5e2fac73c 100644 --- a/colour/models/rgb/rgb_colourspace.py +++ b/colour/models/rgb/rgb_colourspace.py @@ -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) diff --git a/colour/plotting/__init__.py b/colour/plotting/__init__.py index b85a54df2..7f5c51449 100644 --- a/colour/plotting/__init__.py +++ b/colour/plotting/__init__.py @@ -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 diff --git a/colour/plotting/graph.py b/colour/plotting/graph.py index f9a4f02a9..08a339691 100644 --- a/colour/plotting/graph.py +++ b/colour/plotting/graph.py @@ -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 `__ and diff --git a/colour/plotting/models.py b/colour/plotting/models.py index 290992369..f3bbc1e0e 100644 --- a/colour/plotting/models.py +++ b/colour/plotting/models.py @@ -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) diff --git a/colour/plotting/tests/test_models.py b/colour/plotting/tests/test_models.py index 1e74be3b0..52d1a6c41 100644 --- a/colour/plotting/tests/test_models.py +++ b/colour/plotting/tests/test_models.py @@ -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) diff --git a/colour/quality/cfi2017.py b/colour/quality/cfi2017.py index 2edf94d94..7435a8dd0 100644 --- a/colour/quality/cfi2017.py +++ b/colour/quality/cfi2017.py @@ -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): diff --git a/colour/quality/tests/test_cfi2017.py b/colour/quality/tests/test_cfi2017.py index d44ee3242..187638990 100644 --- a/colour/quality/tests/test_cfi2017.py +++ b/colour/quality/tests/test_cfi2017.py @@ -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, diff --git a/colour/recovery/jakob2019.py b/colour/recovery/jakob2019.py index 2e77a1999..8d85773ee 100644 --- a/colour/recovery/jakob2019.py +++ b/colour/recovery/jakob2019.py @@ -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([]) @@ -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) diff --git a/colour/recovery/tests/test_jakob2019.py b/colour/recovery/tests/test_jakob2019.py index efadf561a..76d67f7d8 100644 --- a/colour/recovery/tests/test_jakob2019.py +++ b/colour/recovery/tests/test_jakob2019.py @@ -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): """ diff --git a/colour/utilities/callback.py b/colour/utilities/callback.py index 25479ca33..96fb99ed7 100644 --- a/colour/utilities/callback.py +++ b/colour/utilities/callback.py @@ -174,7 +174,7 @@ def unregister_callback(self, attribute: str, name: str) -> None: defaultdict(, {}) """ - if self._callbacks.get(attribute) is None: + if self._callbacks.get(attribute) is None: # pragma: no cover return self._callbacks[attribute] = [ diff --git a/colour/utilities/common.py b/colour/utilities/common.py index 232643635..d64cc9b7c 100644 --- a/colour/utilities/common.py +++ b/colour/utilities/common.py @@ -1611,4 +1611,4 @@ def int_digest( return -1 else: - int_digest = hash # pyright: ignore + int_digest = hash # pyright: ignore # pragma: no cover diff --git a/colour/utilities/tests/test_callback.py b/colour/utilities/tests/test_callback.py index 6f9266d3b..67d8d8261 100644 --- a/colour/utilities/tests/test_callback.py +++ b/colour/utilities/tests/test_callback.py @@ -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!' ) diff --git a/colour/utilities/verbose.py b/colour/utilities/verbose.py index 6bb3988fa..666730dbb 100644 --- a/colour/utilities/verbose.py +++ b/colour/utilities/verbose.py @@ -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) @@ -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" @@ -937,7 +937,7 @@ def multiline_str( and not attribute.get("section") ) ) - except ValueError: + except ValueError: # pragma: no cover justify = 0 representation = [] diff --git a/colour/volume/spectrum.py b/colour/volume/spectrum.py index ed3043733..2b30d92bf 100644 --- a/colour/volume/spectrum.py +++ b/colour/volume/spectrum.py @@ -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(