Coverage for plotting/tests/test_diagrams.py: 100%

1"""Define the unit tests for the :mod:`colour.plotting.diagrams` module."""

2

3 from __future__ import annotations

4

5 import pytest

6 from matplotlib.axes import Axes

7 from matplotlib.figure import Figure

8

9 from colour.colorimetry import MSDS_CMFS, SDS_ILLUMINANTS, SpectralShape, reshape_msds

10 from colour.plotting import (

11 lines_spectral_locus,

12 plot_chromaticity_diagram_CIE1931,

13 plot_chromaticity_diagram_CIE1960UCS,

14 plot_chromaticity_diagram_CIE1976UCS,

15 plot_sds_in_chromaticity_diagram_CIE1931,

16 plot_sds_in_chromaticity_diagram_CIE1960UCS,

17 plot_sds_in_chromaticity_diagram_CIE1976UCS,

18)

19 from colour.plotting.diagrams import (

20 plot_chromaticity_diagram,

21 plot_chromaticity_diagram_colours,

22 plot_sds_in_chromaticity_diagram,

23 plot_spectral_locus,

24)

25

26 __author__ = "Colour Developers"

27 __copyright__ = "Copyright 2013 Colour Developers"

28 __license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"

29 __maintainer__ = "Colour Developers"

30 __email__ = "colour-developers@colour-science.org"

31 __status__ = "Production"

32

33 __all__ = [

34 "TestLinesSpectralLocus",

35 "TestPlotSpectralLocus",

36 "TestPlotChromaticityDiagramColours",

37 "TestPlotChromaticityDiagram",

38 "TestPlotChromaticityDiagramCIE1931",

39 "TestPlotChromaticityDiagramCIE1960UCS",

40 "TestPlotChromaticityDiagramCIE1976UCS",

41 "TestPlotSdsInChromaticityDiagram",

42 "TestPlotSdsInChromaticityDiagramCIE1931",

43 "TestPlotSdsInChromaticityDiagramCIE1960UCS",

44 "TestPlotSdsInChromaticityDiagramCIE1976UCS",

45]

46

47

48 class TestLinesSpectralLocus:

49 """

50 Define :func:`colour.plotting.diagrams.lines_spectral_locus` definition

51 unit tests methods.

52 """

53

54 def test_lines_spectral_locus(self) -> None:

55 """

56 Test :func:`colour.plotting.diagrams.lines_spectral_locus`

57 definition.

58 """

59

60 assert len(lines_spectral_locus()) == 2

61

62

63 class TestPlotSpectralLocus:

64 """

65 Define :func:`colour.plotting.diagrams.plot_spectral_locus` definition

66 unit tests methods.

67 """

68

69 def test_plot_spectral_locus(self) -> None:

70 """

71 Test :func:`colour.plotting.diagrams.plot_spectral_locus` definition.

72 """

73

74 figure, axes = plot_spectral_locus()

75

76 assert isinstance(figure, Figure)

77 assert isinstance(axes, Axes)

78

79 figure, axes = plot_spectral_locus(spectral_locus_colours="RGB")

80

81 assert isinstance(figure, Figure)

82 assert isinstance(axes, Axes)

83

84 figure, axes = plot_spectral_locus(

85 method="CIE 1960 UCS", spectral_locus_colours="RGB"

86 )

87

88 assert isinstance(figure, Figure)

89 assert isinstance(axes, Axes)

90

91 figure, axes = plot_spectral_locus(

92 method="CIE 1976 UCS", spectral_locus_colours="RGB"

93 )

94

95 assert isinstance(figure, Figure)

96 assert isinstance(axes, Axes)

97

98 figure, axes = plot_spectral_locus(

99 reshape_msds(

100 MSDS_CMFS["CIE 1931 2 Degree Standard Observer"],

101 SpectralShape(400, 700, 10),

102 )

103 )

104

105 assert isinstance(figure, Figure)

106 assert isinstance(axes, Axes)

107

108 pytest.raises(ValueError, lambda: plot_spectral_locus(method="Undefined"))

109

110

111 class TestPlotChromaticityDiagramColours:

112 """

113 Define :func:`colour.plotting.diagrams.plot_chromaticity_diagram_colours`

114 definition unit tests methods.

115 """

116

117 def test_plot_chromaticity_diagram_colours(self) -> None:

118 """

119 Test :func:`colour.plotting.diagrams.plot_chromaticity_diagram_colours`

120 definition.

121 """

122

123 figure, axes = plot_chromaticity_diagram_colours()

124

125 assert isinstance(figure, Figure)

126 assert isinstance(axes, Axes)

127

128 pytest.raises(

129 ValueError,

130 lambda: plot_chromaticity_diagram_colours(method="Undefined"),

131 )

132

133 figure, axes = plot_chromaticity_diagram_colours(diagram_colours="RGB")

134

135 assert isinstance(figure, Figure)

136 assert isinstance(axes, Axes)

137

138

139 class TestPlotChromaticityDiagram:

140 """

141 Define :func:`colour.plotting.diagrams.plot_chromaticity_diagram`

142 definition unit tests methods.

143 """

144

145 def test_plot_chromaticity_diagram(self) -> None:

146 """

147 Test :func:`colour.plotting.diagrams.plot_chromaticity_diagram`

148 definition.

149 """

150

151 figure, axes = plot_chromaticity_diagram()

152

153 assert isinstance(figure, Figure)

154 assert isinstance(axes, Axes)

155

156 figure, axes = plot_chromaticity_diagram(method="CIE 1960 UCS")

157

158 assert isinstance(figure, Figure)

159 assert isinstance(axes, Axes)

160

161 figure, axes = plot_chromaticity_diagram(method="CIE 1976 UCS")

162

163 assert isinstance(figure, Figure)

164 assert isinstance(axes, Axes)

165

166 pytest.raises(

167 ValueError,

168 lambda: plot_chromaticity_diagram(

169 method="Undefined",

170 show_diagram_colours=False,

171 show_spectral_locus=False,

172 ),

173 )

174

175

176 class TestPlotChromaticityDiagramCIE1931:

177 """

178 Define :func:`colour.plotting.diagrams.plot_chromaticity_diagram_CIE1931`

179 definition unit tests methods.

180 """

181

182 def test_plot_chromaticity_diagram_CIE1931(self) -> None:

183 """

184 Test :func:`colour.plotting.diagrams.\

185 plot_chromaticity_diagram_CIE1931` definition.

186 """

187

188 figure, axes = plot_chromaticity_diagram_CIE1931()

189

190 assert isinstance(figure, Figure)

191 assert isinstance(axes, Axes)

192

193

194 class TestPlotChromaticityDiagramCIE1960UCS:

195 """

196 Define :func:`colour.plotting.diagrams.\

197 plot_chromaticity_diagram_CIE1960UCS` definition unit tests methods.

198 """

199

200 def test_plot_chromaticity_diagram_CIE1960UCS(self) -> None:

201 """

202 Test :func:`colour.plotting.diagrams.\

203 plot_chromaticity_diagram_CIE1960UCS` definition.

204 """

205

206 figure, axes = plot_chromaticity_diagram_CIE1960UCS()

207

208 assert isinstance(figure, Figure)

209 assert isinstance(axes, Axes)

210

211

212 class TestPlotChromaticityDiagramCIE1976UCS:

213 """

214 Define :func:`colour.plotting.diagrams.\

215 plot_chromaticity_diagram_CIE1976UCS` definition unit tests methods.

216 """

217

218 def test_plot_chromaticity_diagram_CIE1976UCS(self) -> None:

219 """

220 Test :func:`colour.plotting.diagrams.\

221 plot_chromaticity_diagram_CIE1976UCS` definition.

222 """

223

224 figure, axes = plot_chromaticity_diagram_CIE1976UCS()

225

226 assert isinstance(figure, Figure)

227 assert isinstance(axes, Axes)

228

229

230 class TestPlotSdsInChromaticityDiagram:

231 """

232 Define :func:`colour.plotting.diagrams.\

233 plot_sds_in_chromaticity_diagram` definition unit tests methods.

234 """

235

236 def test_plot_sds_in_chromaticity_diagram(self) -> None:

237 """

238 Test :func:`colour.plotting.diagrams.plot_sds_in_chromaticity_diagram`

239 definition.

240 """

241

242 figure, axes = plot_sds_in_chromaticity_diagram(

243 [SDS_ILLUMINANTS["A"], SDS_ILLUMINANTS["D65"]],

244 annotate_kwargs={"arrowprops": {"width": 10}},

245 plot_kwargs={"normalise_sd_colours": True, "use_sd_colours": True},

246 )

247

248 assert isinstance(figure, Figure)

249 assert isinstance(axes, Axes)

250

251 figure, axes = plot_sds_in_chromaticity_diagram(

252 [SDS_ILLUMINANTS["A"], SDS_ILLUMINANTS["D65"]],

253 annotate_kwargs=[{"arrowprops": {"width": 10}}] * 2,

254 plot_kwargs=[{"normalise_sd_colours": True, "use_sd_colours": True}] * 2,

255 )

256

257 assert isinstance(figure, Figure)

258 assert isinstance(axes, Axes)

259

260 pytest.raises(

261 ValueError,

262 lambda: plot_sds_in_chromaticity_diagram(

263 [SDS_ILLUMINANTS["A"], SDS_ILLUMINANTS["D65"]],

264 chromaticity_diagram_callable=lambda **x: x,

265 method="Undefined",

266 ),

267 )

268

269

270 class TestPlotSdsInChromaticityDiagramCIE1931:

271 """

272 Define :func:`colour.plotting.diagrams.\

273 plot_sds_in_chromaticity_diagram_CIE1931` definition unit tests methods.

274 """

275

276 def test_plot_sds_in_chromaticity_diagram_CIE1931(self) -> None:

277 """

278 Test :func:`colour.plotting.diagrams.\

279 plot_sds_in_chromaticity_diagram_CIE1931` definition.

280 """

281

282 figure, axes = plot_sds_in_chromaticity_diagram_CIE1931(

283 [SDS_ILLUMINANTS["A"], SDS_ILLUMINANTS["D65"]]

284 )

285

286 assert isinstance(figure, Figure)

287 assert isinstance(axes, Axes)

288

289

290 class TestPlotSdsInChromaticityDiagramCIE1960UCS:

291 """

292 Define :func:`colour.plotting.diagrams.\

293 plot_sds_in_chromaticity_diagram_CIE1960UCS` definition unit tests methods.

294 """

295

296 def test_plot_sds_in_chromaticity_diagram_CIE1960UCS(self) -> None:

297 """

298 Test :func:`colour.plotting.diagrams.\

299 plot_sds_in_chromaticity_diagram_CIE1960UCS` definition.

300 """

301

302 figure, axes = plot_sds_in_chromaticity_diagram_CIE1960UCS(

303 [SDS_ILLUMINANTS["A"], SDS_ILLUMINANTS["D65"]]

304 )

305

306 assert isinstance(figure, Figure)

307 assert isinstance(axes, Axes)

308

309

310 class TestPlotSdsInChromaticityDiagramCIE1976UCS:

311 """

312 Define :func:`colour.plotting.diagrams.\

313 plot_sds_in_chromaticity_diagram_CIE1976UCS` definition unit tests methods.

314 """

315

316 def test_plot_sds_in_chromaticity_diagram_CIE1976UCS(self) -> None:

317 """

318 Test :func:`colour.plotting.diagrams.\

319 plot_sds_in_chromaticity_diagram_CIE1976UCS` definition.

320 """

321

322 figure, axes = plot_sds_in_chromaticity_diagram_CIE1976UCS(

323 [SDS_ILLUMINANTS["A"], SDS_ILLUMINANTS["D65"]]

324 )

325

326 assert isinstance(figure, Figure)

327 assert isinstance(axes, Axes)