MCPcopy Create free account
hub / github.com/python/mypy / CoberturaPackage

Class CoberturaPackage

mypy/report.py:588–612  ·  view source on GitHub ↗

Container for XML and statistics mapping python modules to Cobertura package.

Source from the content-addressed store, hash-verified

586
587
588class CoberturaPackage:
589 """Container for XML and statistics mapping python modules to Cobertura package."""
590
591 def __init__(self, name: str) -> None:
592 self.name = name
593 self.classes: dict[str, Any] = {}
594 self.packages: dict[str, CoberturaPackage] = {}
595 self.total_lines = 0
596 self.covered_lines = 0
597
598 def as_xml(self) -> Any:
599 package_element = etree.Element("package", complexity="1.0", name=self.name)
600 package_element.attrib["branch-rate"] = "0"
601 package_element.attrib["line-rate"] = get_line_rate(self.covered_lines, self.total_lines)
602 classes_element = etree.SubElement(package_element, "classes")
603 for class_name in sorted(self.classes):
604 classes_element.append(self.classes[class_name])
605 self.add_packages(package_element)
606 return package_element
607
608 def add_packages(self, parent_element: Any) -> None:
609 if self.packages:
610 packages_element = etree.SubElement(parent_element, "packages")
611 for package in sorted(self.packages.values(), key=attrgetter("name")):
612 packages_element.append(package.as_xml())
613
614
615class CoberturaXmlReporter(AbstractReporter):

Callers 3

test_as_xmlMethod · 0.90
__init__Method · 0.85
on_fileMethod · 0.85

Calls

no outgoing calls

Tested by 1

test_as_xmlMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…