Coverage for io/luts/tests/test_sony_spi1d.py: 100%

1"""Define the unit tests for the :mod:`colour.io.luts.sony_spi1d` module."""

2

3 from __future__ import annotations

4

5 import os

6 import shutil

7 import tempfile

8

9 import numpy as np

10

11 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

12 from colour.io import read_LUT_SonySPI1D, write_LUT_SonySPI1D

13

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"

20

21 __all__ = [

22 "ROOT_LUTS",

23 "TestReadLUTSonySPI1D",

24 "TestWriteLUTSonySPI1D",

25]

26

27 ROOT_LUTS: str = os.path.join(os.path.dirname(__file__), "resources", "sony_spi1d")

28

29

30 class TestReadLUTSonySPI1D:

31 """

32 Define :func:`colour.io.luts.sony_spi1d.read_LUT_SonySPI1D` definition

33 unit tests methods.

34 """

35

36 def test_read_LUT_SonySPI1D(self) -> None:

37 """Test :func:`colour.io.luts.sony_spi1d.read_LUT_SonySPI1D` definition."""

38

39 LUT_1 = read_LUT_SonySPI1D(os.path.join(ROOT_LUTS, "eotf_sRGB_1D.spi1d"))

40

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 ]

73

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 )

82

83

84 class TestWriteLUTSonySPI1D:

85 """

86 Define :func:`colour.io.luts.sony_spi1d.write_LUT_SonySPI1D` definition

87 unit tests methods.

88 """

89

90 def setup_method(self) -> None:

91 """Initialise the common tests attributes."""

92

93 self._temporary_directory = tempfile.mkdtemp()

94

95 def teardown_method(self) -> None:

96 """After tests actions."""

97

98 shutil.rmtree(self._temporary_directory)

99

100 def test_write_LUT_SonySPI1D(self) -> None:

101 """Test :func:`colour.io.luts.sony_spi1d.write_LUT_SonySPI1D` definition."""

102

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

112

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