coverage.py Cobertura

Cobertura XML code coverage report as written by coverage.py 7.x (coverage xml).

Read by pyEDAA.Reports.CodeCoverage.Cobertura.CoveragePyCobertura.Document - see coverage.py Cobertura.

The schema was reverse-engineered from coverage.py’s xmlreport.py and accepts nothing else. coverage.py names Cobertura’s DTD coverage-04.dtd in a comment, not in a document type declaration. It writes every attribute the DTD requires, but never a method or a condition, and adds missing-branches to a line: the target lines of the branches never taken, exit for an exit of a function. A line’s hits is 0 or 1, every complexity 0.

Download

CoveragePy-Cobertura.xsd (5.0 kiB)

Validate a report

xmllint --schema CoveragePy-Cobertura.xsd --noout coverage.xml

Source

  1<?xml version="1.0" encoding="UTF-8"?>
  2<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  3	<xs:annotation>
  4		<xs:documentation>
  5			Cobertura XML code coverage report as written by coverage.py 7.x ('coverage xml'): reverse-engineered from
  6			coverage.py's 'xmlreport.py'.
  7
  8			coverage.py names Cobertura's DTD 'coverage-04.dtd' in a comment, not in a document type declaration. It writes
  9			every attribute the DTD requires, but never a method or a condition, and adds 'missing-branches' to a line. A
 10			line's 'hits' is 0 or 1, every 'complexity' is 0. No other element or attribute is allowed.
 11		</xs:documentation>
 12	</xs:annotation>
 13
 14	<xs:simpleType name="Rate">
 15		<xs:annotation>
 16			<xs:documentation>A rate in range 0..1, four significant digits, e.g. '0.8148', '1' or '1e-05'.</xs:documentation>
 17		</xs:annotation>
 18		<xs:restriction base="xs:double">
 19			<xs:minInclusive value="0"/>
 20			<xs:maxInclusive value="1"/>
 21		</xs:restriction>
 22	</xs:simpleType>
 23
 24	<xs:simpleType name="Version">
 25		<xs:annotation>
 26			<xs:documentation>coverage.py's version, e.g. '7.16.1', '7.5.0b2' or '7.5.0a1.dev1'.</xs:documentation>
 27		</xs:annotation>
 28		<xs:restriction base="xs:string">
 29			<xs:pattern value="\d+\.\d+\.\d+((a|b|rc)\d+)?(\.dev\d+)?"/>
 30		</xs:restriction>
 31	</xs:simpleType>
 32
 33	<xs:simpleType name="Hits">
 34		<xs:annotation>
 35			<xs:documentation>Whether the line ran: coverage.py doesn't count.</xs:documentation>
 36		</xs:annotation>
 37		<xs:restriction base="xs:nonNegativeInteger">
 38			<xs:enumeration value="0"/>
 39			<xs:enumeration value="1"/>
 40		</xs:restriction>
 41	</xs:simpleType>
 42
 43	<xs:simpleType name="ConditionCoverage">
 44		<xs:annotation>
 45			<xs:documentation>Percentage, rounded down, and count of taken branches, e.g. '50% (1/2)'.</xs:documentation>
 46		</xs:annotation>
 47		<xs:restriction base="xs:string">
 48			<xs:pattern value="\d+% \(\d+/\d+\)"/>
 49		</xs:restriction>
 50	</xs:simpleType>
 51
 52	<xs:simpleType name="MissingBranches">
 53		<xs:annotation>
 54			<xs:documentation>Target lines of the branches never taken, 'exit' for a function's exit.</xs:documentation>
 55		</xs:annotation>
 56		<xs:restriction base="xs:string">
 57			<xs:pattern value="([1-9]\d*|exit)(,([1-9]\d*|exit))*"/>
 58		</xs:restriction>
 59	</xs:simpleType>
 60
 61	<xs:attributeGroup name="Rates">
 62		<xs:attribute name="line-rate"   type="Rate"       use="required"/>
 63		<xs:attribute name="branch-rate" type="Rate"       use="required"/>
 64		<xs:attribute name="complexity"  type="xs:decimal" use="required" fixed="0"/>
 65	</xs:attributeGroup>
 66
 67	<xs:element name="coverage">
 68		<xs:complexType>
 69			<xs:sequence>
 70				<xs:element name="sources">
 71					<xs:complexType>
 72						<xs:sequence>
 73							<xs:element name="source" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
 74						</xs:sequence>
 75					</xs:complexType>
 76				</xs:element>
 77				<xs:element name="packages">
 78					<xs:complexType>
 79						<xs:sequence>
 80							<xs:element ref="package" minOccurs="0" maxOccurs="unbounded"/>
 81						</xs:sequence>
 82					</xs:complexType>
 83				</xs:element>
 84			</xs:sequence>
 85			<xs:attribute name="version"          type="Version"               use="required"/>
 86			<xs:attribute name="timestamp"        type="xs:nonNegativeInteger" use="required"/>
 87			<xs:attribute name="lines-valid"      type="xs:nonNegativeInteger" use="required"/>
 88			<xs:attribute name="lines-covered"    type="xs:nonNegativeInteger" use="required"/>
 89			<xs:attribute name="branches-valid"   type="xs:nonNegativeInteger" use="required"/>
 90			<xs:attribute name="branches-covered" type="xs:nonNegativeInteger" use="required"/>
 91			<xs:attributeGroup ref="Rates"/>
 92		</xs:complexType>
 93	</xs:element>
 94
 95	<xs:element name="package">
 96		<xs:complexType>
 97			<xs:sequence>
 98				<xs:element name="classes">
 99					<xs:complexType>
100						<xs:sequence>
101							<xs:element ref="class" minOccurs="0" maxOccurs="unbounded"/>
102						</xs:sequence>
103					</xs:complexType>
104				</xs:element>
105			</xs:sequence>
106			<xs:attribute name="name" type="xs:string" use="required"/>
107			<xs:attributeGroup ref="Rates"/>
108		</xs:complexType>
109	</xs:element>
110
111	<xs:element name="class">
112		<xs:complexType>
113			<xs:sequence>
114				<xs:element name="methods">
115					<xs:complexType/>
116				</xs:element>
117				<xs:element name="lines">
118					<xs:complexType>
119						<xs:sequence>
120							<xs:element ref="line" minOccurs="0" maxOccurs="unbounded"/>
121						</xs:sequence>
122					</xs:complexType>
123				</xs:element>
124			</xs:sequence>
125			<xs:attribute name="name"     type="xs:string" use="required"/>
126			<xs:attribute name="filename" type="xs:string" use="required"/>
127			<xs:attributeGroup ref="Rates"/>
128		</xs:complexType>
129	</xs:element>
130
131	<xs:element name="line">
132		<xs:complexType>
133			<xs:attribute name="number"             type="xs:positiveInteger" use="required"/>
134			<xs:attribute name="hits"               type="Hits"               use="required"/>
135			<xs:attribute name="branch"             type="xs:boolean"         fixed="true"/>
136			<xs:attribute name="condition-coverage" type="ConditionCoverage"/>
137			<xs:attribute name="missing-branches"   type="MissingBranches"/>
138		</xs:complexType>
139	</xs:element>
140</xs:schema>