Coverage for pyquickhelper/pycode/default_filter_warning.py: 100%

1 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-03 02:21 +0200

1""" 

2@file 

3@brief Function which filters ou warnings after running the unit test 

4""" 

5import warnings 

6 

7 

8def default_filter_warning(w): # pragma: no cover 

9 """ 

10 Filters out warnings. 

11 

12 @param w warning 

13 @return boolean (True to keep it) 

14 

15 Interesting fields: ``w.message``, ``w.category``, ``w.filename``, ``w.lineno``. 

16 """ 

17 if "RemovedInSphinx" in str(w): 

18 return False 

19 

20 class UnusedException(Exception): 

21 pass 

22 

23 with warnings.catch_warnings(): 

24 warnings.simplefilter("ignore", DeprecationWarning) 

25 try: 

26 from matplotlib.cbook import MatplotlibDeprecationWarning 

27 except ImportError: 

28 MatplotlibDeprecationWarning = UnusedException 

29 

30 if "ConvergenceWarning" in str(type(w.message)): 

31 return False 

32 if isinstance(w.message, FutureWarning): 

33 return False 

34 if isinstance(w.message, RuntimeWarning): 

35 if "_bootstrap.py" in w.filename: 

36 if "numpy.dtype size changed" in str(w.message): 

37 return False 

38 if "More than 20 figures have been opened." in str(w.message): 

39 return False 

40 elif isinstance(w.message, UserWarning): 

41 if "matplotlib" in w.filename: 

42 if "findfont: Font family" in str(w.message): 

43 return False 

44 if "pyquickhelper" in w.filename: 

45 if "pymyinstall" in str(w.message): 

46 return False 

47 if "FixedFormatter should only be used together" in str(w): 

48 return False 

49 elif isinstance(w.message, MatplotlibDeprecationWarning): 

50 if "basemap" in w.filename: 

51 if "The ishold function was deprecated in version 2.0." in str(w.message): 

52 return False 

53 elif isinstance(w.message, ResourceWarning): 

54 if "pyquickhelper" in w.filename: 

55 if "Unable to retrieve content from" in str(w): 

56 return False 

57 if "<zmq.asyncio." in str(w): 

58 return False 

59 elif isinstance(w.message, DeprecationWarning): 

60 if w.filename in ('', None): 

61 return False 

62 if "`np.str`" in str(w): 

63 return False 

64 if "`np.bool`" in str(w): 

65 return False 

66 if "RemovedInSphinx" in str(w): 

67 return False 

68 if w.filename.endswith("kernelspec.py"): 

69 return False 

70 if "jupyter_client" in w.filename: 

71 return False 

72 elif "IPython" in w.filename: 

73 if "DisplayFormatter." in str(w.message): 

74 return False 

75 if "ScriptMagics." in str(w.message): 

76 return False 

77 if "HistoryManager." in str(w.message): 

78 return False 

79 if "ProfileDir." in str(w.message): 

80 return False 

81 if "InteractiveShell." in str(w.message): 

82 return False 

83 if "on_trait_change" in str(w.message): 

84 return False 

85 if "PlainTextFormatter." in str(w.message): 

86 return False 

87 if "Metadata should be set using the .tag()" in str(w.message): 

88 return False 

89 elif "nbconvert" in w.filename: 

90 if "SlidesExporter." in str(w.message): 

91 return False 

92 if "TemplateExporter." in str(w.message): 

93 return False 

94 if "HTMLExporter." in str(w.message): 

95 return False 

96 if "SVG2PDFPreprocessor." in str(w.message): 

97 return False 

98 if "on_trait_change" in str(w.message): 

99 return False 

100 if "PresentExporter." in str(w.message): 

101 return False 

102 if "NbConvertApp." in str(w.message): 

103 return False 

104 if "RSTExporter." in str(w.message): 

105 return False 

106 if "PythonExporter." in str(w.message): 

107 return False 

108 if "LatexExporter." in str(w.message): 

109 return False 

110 if "metadata should be set using the .tag()" in str(w.message).lower(): 

111 return False 

112 if 'cgi.escape is deprecated, use html.escape instead' in str(w.message): 

113 return False 

114 elif "jupyter_core" in w.filename: 

115 if "JupyterApp." in str(w.message): 

116 return False 

117 if "metadata should be set using the .tag()" in str(w.message).lower(): 

118 return False 

119 elif "nbextensions.py" in w.filename: 

120 if "metadata should be set using the .tag()" in str(w.message).lower(): 

121 return False 

122 elif "docutils" in w.filename: 

123 if "'U' mode is deprecated" in str(w.message): 

124 return False 

125 if "Metadata should be set using the .tag()" in str(w.message): 

126 return False 

127 elif "sympy" in w.filename: 

128 if "inspect.getargspec() is deprecated" in str(w.message): 

129 return False 

130 elif "_mode_cbc.py" in w.filename: 

131 if "will be forbidden in the future" in str(w.message): 

132 return False 

133 elif "mpl_toolkits" in w.filename: 

134 if "The ishold function was deprecated in version 2.0." in str(w.message): 

135 return False 

136 if "The hold function was deprecated in version 2.0." in str(w.message): 

137 return False 

138 if "axes.hold is deprecated." in str(w.message): 

139 return False 

140 elif "_bootstrap.py" in w.filename: 

141 if "can't resolve package from __spec__" in str(w.message): 

142 return False 

143 elif "basemap" in w.filename: 

144 if "The ishold function was deprecated in version 2.0." in str(w.message): 

145 return False 

146 elif "pandas" in w.filename: 

147 if "ix is deprecated" in str(w.message): 

148 return False 

149 elif "sphinx" in w.filename: 

150 if "sphinx.util.compat.Directive is deprecated and will be removed" in str(w.message): 

151 return False 

152 elif "markdown_mistune.py" in w.filename: 

153 if "cgi.escape is deprecated, use html.escape instead" in str(w.message): 

154 return False 

155 if "There is no current event loop" in str(w): 

156 return False 

157 elif isinstance(w.message, ImportWarning): 

158 if "_bootstrap.py" in w.filename: 

159 if "can't resolve package from __spec__" in str(w.message): 

160 return False 

161 elif w.filename.endswith("_bootstrap_external.py"): 

162 return False 

163 elif "MatplotlibDeprecationWarning" in str(type(w.message)): 

164 if "basemap" in w.filename: 

165 return False 

166 elif "CoverageWarning" in str(w): 

167 return False 

168 return True