Coverage for src/km3pipe/tests/test_style.py: 100%

115 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-20 03:14 +0000

1# Filename: test_style.py 

2# pylint: disable=C0111,E1003,R0904,C0103,R0201,C0102 

3 

4from km3pipe.testing import TestCase, patch 

5from km3pipe.style import get_style_path, ColourCycler, use 

6 

7__author__ = "Tamas Gal" 

8__copyright__ = "Copyright 2016, Tamas Gal and the KM3NeT collaboration." 

9__credits__ = [] 

10__license__ = "MIT" 

11__maintainer__ = "Tamas Gal" 

12__email__ = "tgal@km3net.de" 

13__status__ = "Development" 

14 

15 

16class TestStyle(TestCase): 

17 def test_get_style_path(self): 

18 gsp = get_style_path 

19 self.assertTrue(gsp("km3pipe").endswith("stylelib/km3pipe.mplstyle")) 

20 self.assertTrue(gsp("foo").endswith("/stylelib/foo.mplstyle")) 

21 self.assertTrue(gsp("bar").endswith("/stylelib/bar.mplstyle")) 

22 

23 

24class TestColourCycler(TestCase): 

25 def test_available(self): 

26 cc = ColourCycler() 

27 self.assertTrue("km3pipe" in cc.available) 

28 self.assertTrue("classic" in cc.available) 

29 

30 def test_next(self): 

31 cc = ColourCycler() 

32 first = next(cc) 

33 second = next(cc) 

34 self.assertTrue(first != second) 

35 

36 def test_next_a_few_times(self): 

37 cc = ColourCycler() 

38 last_colour = "" 

39 for i in range(100): 

40 current_colour = next(cc) 

41 self.assertTrue(last_colour != current_colour) 

42 last_colour = current_colour 

43 

44 def test_raise_keyerror_if_style_not_available(self): 

45 with self.assertRaises(KeyError): 

46 cc = ColourCycler("foo") # noqa 

47 

48 

49class TestStyles(TestCase): 

50 @patch("matplotlib.pyplot") 

51 def test_non_existent_style(self, plt_mock): 

52 use("non-existent") 

53 assert not plt_mock.style.use.called 

54 

55 @patch("matplotlib.pyplot") 

56 def test_km3pipe(self, plt_mock): 

57 use("km3pipe") 

58 self._assert_plt_imported(plt_mock, "km3pipe.mplstyle") 

59 

60 @patch("matplotlib.pyplot") 

61 def test_noargs_load_km3pipe_style(self, plt_mock): 

62 use() 

63 self._assert_plt_imported(plt_mock, "km3pipe.mplstyle") 

64 

65 @patch("matplotlib.pyplot") 

66 def test_poster_style(self, plt_mock): 

67 use("poster") 

68 self._assert_plt_imported(plt_mock, "km3pipe-poster.mplstyle") 

69 

70 @patch("matplotlib.pyplot") 

71 def test_notebook_style(self, plt_mock): 

72 use("notebook") 

73 self._assert_plt_imported(plt_mock, "km3pipe-notebook.mplstyle") 

74 

75 @patch("matplotlib.pyplot") 

76 def test_talk_style(self, plt_mock): 

77 use("talk") 

78 self._assert_plt_imported(plt_mock, "km3pipe-talk.mplstyle") 

79 

80 @patch("matplotlib.pyplot") 

81 def test_alba_style(self, plt_mock): 

82 use("alba") 

83 self._assert_plt_imported(plt_mock, "alba.mplstyle") 

84 

85 @patch("matplotlib.pyplot") 

86 def test_jonas_style(self, plt_mock): 

87 use("jonas-phd") 

88 self._assert_plt_imported(plt_mock, "jonas-phd.mplstyle") 

89 

90 @patch("matplotlib.pyplot") 

91 def test_jvs_style(self, plt_mock): 

92 use("jvs") 

93 self._assert_plt_imported(plt_mock, "jvs.mplstyle") 

94 

95 @patch("matplotlib.pyplot") 

96 def test_moritz_style(self, plt_mock): 

97 use("moritz") 

98 self._assert_plt_imported(plt_mock, "moritz.mplstyle") 

99 

100 @patch("matplotlib.pyplot") 

101 def test_serifs_style(self, plt_mock): 

102 use("serifs") 

103 self._assert_plt_imported(plt_mock, "serifs.mplstyle") 

104 

105 @patch("matplotlib.pyplot") 

106 def test_import_alba(self, plt_mock): 

107 import km3pipe.style.alba 

108 

109 self._assert_plt_imported(plt_mock, "alba.mplstyle") 

110 

111 @patch("matplotlib.pyplot") 

112 def test_import_moritz(self, plt_mock): 

113 import km3pipe.style.moritz 

114 

115 self._assert_plt_imported(plt_mock, "moritz.mplstyle") 

116 

117 @patch("matplotlib.pyplot") 

118 def test_import_default(self, plt_mock): 

119 import km3pipe.style.default 

120 

121 self._assert_plt_imported(plt_mock, "km3pipe.mplstyle") 

122 

123 @patch("matplotlib.pyplot") 

124 def test_import_jonas_phd(self, plt_mock): 

125 import km3pipe.style.jonas_phd 

126 

127 self._assert_plt_imported(plt_mock, "jonas-phd.mplstyle") 

128 

129 @patch("matplotlib.pyplot") 

130 def test_import_km3pipe(self, plt_mock): 

131 import km3pipe.style.km3pipe 

132 

133 self._assert_plt_imported(plt_mock, "km3pipe.mplstyle") 

134 

135 @patch("matplotlib.pyplot") 

136 def test_import_km3pipe_notebook(self, plt_mock): 

137 import km3pipe.style.km3pipe_notebook 

138 

139 self._assert_plt_imported(plt_mock, "km3pipe-notebook.mplstyle") 

140 

141 @patch("matplotlib.pyplot") 

142 def test_import_km3pipe_poster(self, plt_mock): 

143 import km3pipe.style.km3pipe_poster 

144 

145 self._assert_plt_imported(plt_mock, "km3pipe-poster.mplstyle") 

146 

147 @patch("matplotlib.pyplot") 

148 def test_import_km3pipe_talk(self, plt_mock): 

149 import km3pipe.style.km3pipe_talk 

150 

151 self._assert_plt_imported(plt_mock, "km3pipe-talk.mplstyle") 

152 

153 def _assert_plt_imported(self, plt_mock, style_filename): 

154 args, kwargs = plt_mock.style.use.call_args_list[0] 

155 assert args[0].endswith(style_filename)