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

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

2

3 from __future__ import annotations

4

5 from matplotlib.axes import Axes

6 from matplotlib.figure import Figure

7

8 from colour.geometry import primitive_cube

9 from colour.models import RGB_COLOURSPACE_sRGB, RGB_to_XYZ

10 from colour.plotting import plot_RGB_colourspace_section, plot_visible_spectrum_section

11 from colour.plotting.section import plot_hull_section_colours, plot_hull_section_contour

12 from colour.utilities import is_scipy_installed, is_trimesh_installed

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

23 "TestPlotHullSectionContour",

24 "TestPlotVisibleSpectrumSection",

25 "TestPlotRGBColourspaceSection",

26]

27

28

29 class TestPlotHullSectionColours:

30 """

31 Define :func:`colour.plotting.section.plot_hull_section_colours`

32 definition unit tests methods.

33 """

34

35 def test_plot_hull_section_colours(self) -> None:

36 """

37 Test :func:`colour.plotting.section.plot_hull_section_colours`

38 definition.

39 """

40

41 if not is_trimesh_installed(): # pragma: no cover

42 return

43

44 import trimesh # noqa: PLC0415

45

46 vertices, faces, _outline = primitive_cube(1, 1, 1, 64, 64, 64)

47 XYZ_vertices = RGB_to_XYZ(vertices["position"] + 0.5, RGB_COLOURSPACE_sRGB)

48 hull = trimesh.Trimesh(XYZ_vertices, faces, process=False)

49

50 figure, axes = plot_hull_section_colours(hull)

51

52 assert isinstance(figure, Figure)

53 assert isinstance(axes, Axes)

54

55 figure, axes = plot_hull_section_colours(hull, axis="+x")

56

57 assert isinstance(figure, Figure)

58 assert isinstance(axes, Axes)

59

60 figure, axes = plot_hull_section_colours(hull, axis="+y")

61

62 assert isinstance(figure, Figure)

63 assert isinstance(axes, Axes)

64

65

66 class TestPlotHullSectionContour:

67 """

68 Define :func:`colour.plotting.section.plot_hull_section_contour`

69 definition unit tests methods.

70 """

71

72 def test_plot_hull_section_contour(self) -> None:

73 """

74 Test :func:`colour.plotting.section.plot_hull_section_contour`

75 definition.

76 """

77

78 if not is_trimesh_installed(): # pragma: no cover

79 return

80

81 import trimesh # noqa: PLC0415

82

83 vertices, faces, _outline = primitive_cube(1, 1, 1, 64, 64, 64)

84 XYZ_vertices = RGB_to_XYZ(vertices["position"] + 0.5, RGB_COLOURSPACE_sRGB)

85 hull = trimesh.Trimesh(XYZ_vertices, faces, process=False)

86

87 figure, axes = plot_hull_section_contour(hull)

88

89 assert isinstance(figure, Figure)

90 assert isinstance(axes, Axes)

91

92

93 class TestPlotVisibleSpectrumSection:

94 """

95 Define :func:`colour.plotting.section.plot_visible_spectrum_section`

96 definition unit tests methods.

97 """

98

99 def test_plot_visible_spectrum_section(self) -> None:

100 """

101 Test :func:`colour.plotting.section.plot_visible_spectrum_section`

102 definition.

103 """

104

105 if not is_scipy_installed(): # pragma: no cover

106 return

107

108 if not is_trimesh_installed(): # pragma: no cover

109 return

110

111 figure, axes = plot_visible_spectrum_section()

112

113 assert isinstance(figure, Figure)

114 assert isinstance(axes, Axes)

115

116

117 class TestPlotRGBColourspaceSection:

118 """

119 Define :func:`colour.plotting.section.plot_RGB_colourspace_section`

120 definition unit tests methods.

121 """

122

123 def test_plot_RGB_colourspace_section(self) -> None:

124 """

125 Test :func:`colour.plotting.section.plot_RGB_colourspace_section`

126 definition.

127 """

128

129 if not is_trimesh_installed(): # pragma: no cover

130 return

131

132 figure, axes = plot_RGB_colourspace_section("sRGB")

133

134 assert isinstance(figure, Figure)

135 assert isinstance(axes, Axes)