mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-08-31 12:46:38 +00:00
test: eliminate docutils warning flood
This commit is contained in:
+27
-21
@@ -9,7 +9,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
from docutils.core import publish_parts
|
from docutils.core import publish_parts
|
||||||
from docutils.frontend import OptionParser
|
from docutils.frontend import get_default_settings
|
||||||
from docutils.parsers.rst import Directive, Parser, directives
|
from docutils.parsers.rst import Directive, Parser, directives
|
||||||
from docutils.utils import Reporter, new_document
|
from docutils.utils import Reporter, new_document
|
||||||
from sphinx.ext.napoleon import Config as NapoleonConfig
|
from sphinx.ext.napoleon import Config as NapoleonConfig
|
||||||
@@ -230,6 +230,7 @@ def prepare_docutils_for_sphinx():
|
|||||||
required_arguments = 0
|
required_arguments = 0
|
||||||
optional_arguments = 100
|
optional_arguments = 100
|
||||||
final_argument_whitespace = True
|
final_argument_whitespace = True
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -249,13 +250,14 @@ def validate_rst(text: str) -> list[tuple[int, str]]:
|
|||||||
|
|
||||||
class RecordingReporter(Reporter):
|
class RecordingReporter(Reporter):
|
||||||
"""Capture warnings/errors instead of halting."""
|
"""Capture warnings/errors instead of halting."""
|
||||||
|
|
||||||
def system_message(self, level, message, *children, **kwargs):
|
def system_message(self, level, message, *children, **kwargs):
|
||||||
line = kwargs.get("line", None)
|
line = kwargs.get("line", None)
|
||||||
warnings.append((line or 0, message))
|
warnings.append((line or 0, message))
|
||||||
return nodes.system_message(message, level=level, type=self.levels[level], *children, **kwargs)
|
return nodes.system_message(message, level=level, type=self.levels[level], *children, **kwargs)
|
||||||
|
|
||||||
# Create default settings
|
# Create default parser settings without the deprecated Docutils OptionParser.
|
||||||
settings = OptionParser(components=(Parser,)).get_default_values()
|
settings = get_default_settings(Parser)
|
||||||
|
|
||||||
document = new_document("<docstring>", settings=settings)
|
document = new_document("<docstring>", settings=settings)
|
||||||
|
|
||||||
@@ -265,7 +267,7 @@ def validate_rst(text: str) -> list[tuple[int, str]]:
|
|||||||
report_level=1, # capture warnings and above
|
report_level=1, # capture warnings and above
|
||||||
halt_level=100, # never halt
|
halt_level=100, # never halt
|
||||||
stream=None,
|
stream=None,
|
||||||
debug=False
|
debug=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
parser = Parser()
|
parser = Parser()
|
||||||
@@ -275,7 +277,7 @@ def validate_rst(text: str) -> list[tuple[int, str]]:
|
|||||||
|
|
||||||
|
|
||||||
def iter_docstrings(package_name: str):
|
def iter_docstrings(package_name: str):
|
||||||
"""Yield docstrings of modules, classes, functions in the given package."""
|
"""Yield project-owned docstrings of modules, classes, and functions in a package."""
|
||||||
|
|
||||||
package = importlib.import_module(package_name)
|
package = importlib.import_module(package_name)
|
||||||
|
|
||||||
@@ -286,22 +288,26 @@ def iter_docstrings(package_name: str):
|
|||||||
if module.__doc__:
|
if module.__doc__:
|
||||||
yield f"Module {module.__name__}", inspect.getdoc(module)
|
yield f"Module {module.__name__}", inspect.getdoc(module)
|
||||||
|
|
||||||
# Classes + methods
|
# Classes + functions defined by this module. Imported objects and inherited
|
||||||
|
# methods are validated where they are defined, not repeatedly under every alias.
|
||||||
for _, obj in inspect.getmembers(module):
|
for _, obj in inspect.getmembers(module):
|
||||||
if inspect.isclass(obj) or inspect.isfunction(obj):
|
if not (inspect.isclass(obj) or inspect.isfunction(obj)):
|
||||||
if obj.__doc__:
|
continue
|
||||||
yield f"{module.__name__}.{obj.__name__}", inspect.getdoc(obj)
|
if getattr(obj, "__module__", None) != module.__name__:
|
||||||
|
continue
|
||||||
|
|
||||||
# Methods of classes
|
if obj.__doc__:
|
||||||
if inspect.isclass(obj):
|
yield f"{module.__name__}.{obj.__name__}", inspect.getdoc(obj)
|
||||||
for _, meth in inspect.getmembers(obj, inspect.isfunction):
|
|
||||||
if not getattr(meth, "__module__", "").startswith(package_name + "."):
|
if inspect.isclass(obj):
|
||||||
continue
|
for _, meth in inspect.getmembers(obj, inspect.isfunction):
|
||||||
if meth.__doc__:
|
if meth.__name__ not in obj.__dict__:
|
||||||
yield f"{module.__name__}.{obj.__name__}.{meth.__name__}", inspect.getdoc(meth)
|
continue
|
||||||
|
if meth.__doc__:
|
||||||
|
yield f"{module.__name__}.{obj.__name__}.{meth.__name__}", inspect.getdoc(meth)
|
||||||
|
|
||||||
|
|
||||||
def map_converted_to_original(orig: str, conv: str) -> dict[int,int]:
|
def map_converted_to_original(orig: str, conv: str) -> dict[int, int]:
|
||||||
"""Map original docstring line to converted docstring line.
|
"""Map original docstring line to converted docstring line.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
@@ -353,10 +359,10 @@ def test_all_docstrings_rst_compliant():
|
|||||||
ignore_msg_patterns.extend(patterns)
|
ignore_msg_patterns.extend(patterns)
|
||||||
|
|
||||||
for conv_line, msg_text in messages:
|
for conv_line, msg_text in messages:
|
||||||
orig_line = line_map.get(conv_line - 1, conv_line - 1) + 1
|
orig_line = line_map.get(conv_line - 1, conv_line - 1) + 1
|
||||||
if any(re.search(pat, msg_text) for pat in ignore_msg_patterns):
|
if any(re.search(pat, msg_text) for pat in ignore_msg_patterns):
|
||||||
continue
|
continue
|
||||||
filtered_messages.append((orig_line, msg_text))
|
filtered_messages.append((orig_line, msg_text))
|
||||||
|
|
||||||
if filtered_messages:
|
if filtered_messages:
|
||||||
failures.append((location, filtered_messages, doc, doc_converted))
|
failures.append((location, filtered_messages, doc, doc_converted))
|
||||||
|
|||||||
Reference in New Issue
Block a user