Test module docstring formatting.
()
| 163 | |
| 164 | @pytest.mark.slowtest |
| 165 | def test_docstring_parameters(): |
| 166 | """Test module docstring formatting.""" |
| 167 | npd = pytest.importorskip("numpydoc") |
| 168 | incorrect = [] |
| 169 | for name in public_modules: |
| 170 | # Assert that by default we import all public names with `import mne` |
| 171 | if name not in ("mne", "mne.gui"): |
| 172 | extra = name.split(".")[1] |
| 173 | assert hasattr(mne, extra) |
| 174 | with _record_warnings(): # traits warnings |
| 175 | module = __import__(name, globals()) |
| 176 | for submod in name.split(".")[1:]: |
| 177 | module = getattr(module, submod) |
| 178 | try: |
| 179 | classes = inspect.getmembers(module, inspect.isclass) |
| 180 | except ModuleNotFoundError as exc: # e.g., mne.decoding but no sklearn |
| 181 | if "'sklearn'" in str(exc): |
| 182 | continue |
| 183 | raise |
| 184 | for cname, cls in classes: |
| 185 | if cname.startswith("_"): |
| 186 | continue |
| 187 | incorrect += check_parameters_match(cls, where=name) |
| 188 | cdoc = npd.docscrape.ClassDoc(cls) |
| 189 | for method_name in cdoc.methods: |
| 190 | method = getattr(cls, method_name) |
| 191 | incorrect += check_parameters_match(method, cls=cls, where=name) |
| 192 | if ( |
| 193 | hasattr(cls, "__call__") |
| 194 | and "of type object" not in str(cls.__call__) |
| 195 | and "of ABCMeta object" not in str(cls.__call__) |
| 196 | ): |
| 197 | incorrect += check_parameters_match( |
| 198 | cls.__call__, |
| 199 | cls=cls, |
| 200 | where=name, |
| 201 | ) |
| 202 | functions = inspect.getmembers(module, inspect.isfunction) |
| 203 | for fname, func in functions: |
| 204 | if fname.startswith("_"): |
| 205 | continue |
| 206 | incorrect += check_parameters_match(func, where=name) |
| 207 | incorrect = sorted(list(set(incorrect))) |
| 208 | if len(incorrect) > 0: |
| 209 | raise AssertionError( |
| 210 | f"{len(incorrect)} error{_pl(incorrect)} found:\n" + "\n".join(incorrect) |
| 211 | ) |
| 212 | |
| 213 | |
| 214 | def test_tabs(): |
nothing calls this directly
no test coverage detected