Coverage for colour/io/luts/tests/test_sony_spi1d.py: 100%
42 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
1"""Define the unit tests for the :mod:`colour.io.luts.sony_spi1d` module."""
3from __future__ import annotations
5import os
6import shutil
7import tempfile
9import numpy as np
11from colour.constants import TOLERANCE_ABSOLUTE_TESTS
12from colour.io import read_LUT_SonySPI1D, write_LUT_SonySPI1D
14__author__ = "Colour Developers"
15__copyright__ = "Copyright 2013 Colour Developers"
16__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
17__maintainer__ = "Colour Developers"
18__email__ = "colour-developers@colour-science.org"
19__status__ = "Production"
21__all__ = [
22 "ROOT_LUTS",
23 "TestReadLUTSonySPI1D",
24 "TestWriteLUTSonySPI1D",
25]
27ROOT_LUTS: str = os.path.join(os.path.dirname(__file__), "resources", "sony_spi1d")
30class TestReadLUTSonySPI1D:
31 """
32 Define :func:`colour.io.luts.sony_spi1d.read_LUT_SonySPI1D` definition
33 unit tests methods.
34 """
36 def test_read_LUT_SonySPI1D(self) -> None:
37 """Test :func:`colour.io.luts.sony_spi1d.read_LUT_SonySPI1D` definition."""
39 LUT_1 = read_LUT_SonySPI1D(os.path.join(ROOT_LUTS, "eotf_sRGB_1D.spi1d"))
41 np.testing.assert_allclose(
42 LUT_1.table,
43 np.array(
44 [
45 -7.73990000e-03,
46 5.16000000e-04,
47 1.22181000e-02,
48 3.96819000e-02,
49 8.71438000e-02,
50 1.57439400e-01,
51 2.52950100e-01,
52 3.75757900e-01,
53 5.27729400e-01,
54 7.10566500e-01,
55 9.25840600e-01,
56 1.17501630e00,
57 1.45946870e00,
58 1.78049680e00,
59 2.13933380e00,
60 2.53715520e00,
61 ]
62 ),
63 atol=TOLERANCE_ABSOLUTE_TESTS,
64 )
65 assert LUT_1.name == "eotf sRGB 1D"
66 assert LUT_1.dimensions == 1
67 np.testing.assert_array_equal(LUT_1.domain, np.array([-0.1, 1.5]))
68 assert LUT_1.size == 16
69 assert LUT_1.comments == [
70 'Generated by "Colour 0.3.11".',
71 '"colour.models.eotf_sRGB".',
72 ]
74 LUT_2 = read_LUT_SonySPI1D(os.path.join(ROOT_LUTS, "eotf_sRGB_3x1D.spi1d"))
75 assert LUT_2.comments == [
76 'Generated by "Colour 0.3.11".',
77 '"colour.models.eotf_sRGB".',
78 ]
79 np.testing.assert_array_equal(
80 LUT_2.domain, np.array([[-0.1, -0.1, -0.1], [1.5, 1.5, 1.5]])
81 )
84class TestWriteLUTSonySPI1D:
85 """
86 Define :func:`colour.io.luts.sony_spi1d.write_LUT_SonySPI1D` definition
87 unit tests methods.
88 """
90 def setup_method(self) -> None:
91 """Initialise the common tests attributes."""
93 self._temporary_directory = tempfile.mkdtemp()
95 def teardown_method(self) -> None:
96 """After tests actions."""
98 shutil.rmtree(self._temporary_directory)
100 def test_write_LUT_SonySPI1D(self) -> None:
101 """Test :func:`colour.io.luts.sony_spi1d.write_LUT_SonySPI1D` definition."""
103 LUT_1_r = read_LUT_SonySPI1D(os.path.join(ROOT_LUTS, "eotf_sRGB_1D.spi1d"))
104 write_LUT_SonySPI1D(
105 LUT_1_r,
106 os.path.join(self._temporary_directory, "eotf_sRGB_1D.spi1d"),
107 )
108 LUT_1_t = read_LUT_SonySPI1D(
109 os.path.join(self._temporary_directory, "eotf_sRGB_1D.spi1d")
110 )
111 assert LUT_1_r == LUT_1_t
113 LUT_2_r = read_LUT_SonySPI1D(os.path.join(ROOT_LUTS, "eotf_sRGB_3x1D.spi1d"))
114 write_LUT_SonySPI1D(
115 LUT_2_r,
116 os.path.join(self._temporary_directory, "eotf_sRGB_3x1D.spi1d"),
117 )
118 LUT_2_t = read_LUT_SonySPI1D(
119 os.path.join(self._temporary_directory, "eotf_sRGB_3x1D.spi1d")
120 )
121 assert LUT_2_r == LUT_2_t
122 assert LUT_2_r.comments == LUT_2_t.comments