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

1"""Define the unit tests for the :mod:`colour.io.luts.sony_spimtx` 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_SonySPImtx, write_LUT_SonySPImtx

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 "TestReadLUTSonySPImtx",

24 "TestWriteLUTSonySPImtx",

25]

26

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

28

29

30 class TestReadLUTSonySPImtx:

31 """

32 Define :func:`colour.io.luts.sony_spimtx.read_LUT_SonySPImtx` definition

33 unit tests methods.

34 """

35

36 def test_read_LUT_SonySPImtx(self) -> None:

37 """

38 Test :func:`colour.io.luts.sony_spimtx.read_LUT_SonySPImtx`

39 definition.

40 """

41

42 LUT_1 = read_LUT_SonySPImtx(os.path.join(ROOT_LUTS, "dt.spimtx"))

43

44 np.testing.assert_allclose(

45 LUT_1.matrix,

46 np.array(

47 [

48 [0.864274, 0.000000, 0.000000, 0.000000],

49 [0.000000, 0.864274, 0.000000, 0.000000],

50 [0.000000, 0.000000, 0.864274, 0.000000],

51 [0.000000, 0.000000, 0.000000, 1.000000],

52 ]

53 ),

54 atol=TOLERANCE_ABSOLUTE_TESTS,

55 )

56 np.testing.assert_allclose(

57 LUT_1.offset,

58 np.array([0.000000, 0.000000, 0.000000, 0.000000]),

59 atol=TOLERANCE_ABSOLUTE_TESTS,

60 )

61 assert LUT_1.name == "dt"

62

63 LUT_2 = read_LUT_SonySPImtx(os.path.join(ROOT_LUTS, "p3_to_xyz16.spimtx"))

64 np.testing.assert_allclose(

65 LUT_2.matrix,

66 np.array(

67 [

68 [0.44488, 0.27717, 0.17237, 0.00000],

69 [0.20936, 0.72170, 0.06895, 0.00000],

70 [0.00000, 0.04707, 0.90780, 0.00000],

71 [0.00000, 0.00000, 0.00000, 1.00000],

72 ]

73 ),

74 atol=TOLERANCE_ABSOLUTE_TESTS,

75 )

76 np.testing.assert_allclose(

77 LUT_2.offset,

78 np.array([0.000000, 0.000000, 0.000000, 0.000000]),

79 atol=TOLERANCE_ABSOLUTE_TESTS,

80 )

81 assert LUT_2.name == "p3 to xyz16"

82

83 LUT_3 = read_LUT_SonySPImtx(os.path.join(ROOT_LUTS, "Matrix_Offset.spimtx"))

84 np.testing.assert_allclose(

85 LUT_3.matrix,

86 np.array(

87 [

88 [1.0, 0.0, 0.0, 0.0],

89 [0.0, 1.0, 0.0, 0.0],

90 [0.0, 0.0, 1.0, 0.0],

91 [0.0, 0.0, 0.0, 1.0],

92 ]

93 ),

94 atol=TOLERANCE_ABSOLUTE_TESTS,

95 )

96 np.testing.assert_allclose(

97 LUT_3.offset,

98 np.array([0.0, 0.0, 1.0, 0.0]),

99 atol=TOLERANCE_ABSOLUTE_TESTS,

100 )

101 assert LUT_3.name == "Matrix Offset"

102

103

104 class TestWriteLUTSonySPImtx:

105 """

106 Define :func:`colour.io.luts.sony_spimtx.write_LUT_SonySPImtx` definition

107 unit tests methods.

108 """

109

110 def setup_method(self) -> None:

111 """Initialise the common tests attributes."""

112

113 self._temporary_directory = tempfile.mkdtemp()

114

115 def teardown_method(self) -> None:

116 """After tests actions."""

117

118 shutil.rmtree(self._temporary_directory)

119

120 def test_write_LUT_SonySPImtx(self) -> None:

121 """

122 Test :func:`colour.io.luts.sony_spimtx.write_LUT_SonySPImtx`

123 definition.

124 """

125

126 LUT_1_r = read_LUT_SonySPImtx(os.path.join(ROOT_LUTS, "dt.spimtx"))

127 write_LUT_SonySPImtx(

128 LUT_1_r, os.path.join(self._temporary_directory, "dt.spimtx")

129 )

130 LUT_1_t = read_LUT_SonySPImtx(

131 os.path.join(self._temporary_directory, "dt.spimtx")

132 )

133 assert LUT_1_r == LUT_1_t

134

135 LUT_2_r = read_LUT_SonySPImtx(os.path.join(ROOT_LUTS, "p3_to_xyz16.spimtx"))

136 write_LUT_SonySPImtx(

137 LUT_2_r,

138 os.path.join(self._temporary_directory, "p3_to_xyz16.spimtx"),

139 )

140 LUT_2_t = read_LUT_SonySPImtx(

141 os.path.join(self._temporary_directory, "p3_to_xyz16.spimtx")

142 )

143 assert LUT_2_r == LUT_2_t

144 assert LUT_2_r.comments == LUT_2_t.comments