Skip to content

Commit

Permalink
Support tables with primary and secondary header rows.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels committed Jan 22, 2024
1 parent d3b69ca commit 170670f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 41 deletions.
38 changes: 23 additions & 15 deletions sphinx_reports/CodeCoverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
**Report code coverage as Sphinx documentation page(s).**
"""
from pathlib import Path
from typing import Dict, Tuple, Any, List, Iterable, Mapping, Generator, TypedDict, Union
from typing import Dict, Tuple, Any, List, Iterable, Mapping, Generator, TypedDict, Union, Optional as Nullable

from docutils import nodes
from pyTooling.Decorators import export
Expand Down Expand Up @@ -167,22 +167,30 @@ def _ConvertToColor(self, currentLevel: float, configKey: str) -> str:
return self._levels[100][configKey]

def _GenerateCoverageTable(self) -> nodes.table:
# Create a table and table header with 5 columns
# Create a table and table header with 10 columns
table, tableGroup = self._PrepareTable(
identifier=self._packageID,
columns={
"Module": 500,
"Total Statements": 100,
"Excluded Statements": 100,
"Covered Statements": 100,
"Missing Statements": 100,
"Total Branches": 100,
"Covered Branches": 100,
"Partial Branches": 100,
"Missing Branches": 100,
"Coverage in %": 100
},
classes=["report-doccov-table"]
columns=[
("Package", [
(" Module", 500)
], None),
("Statments", [
("Total", 100),
("Excluded", 100),
("Covered", 100),
("Missing", 100)
], None),
("Branches", [
("Total", 100),
("Covered", 100),
("Partial", 100),
("Missing", 100)
], None),
("Coverage", [
("in %", 100)
], None)
],
classes=["report-codecov-table"]
)
tableBody = nodes.tbody()
tableGroup += tableBody
Expand Down
14 changes: 7 additions & 7 deletions sphinx_reports/DocCoverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ def _GenerateCoverageTable(self) -> nodes.table:
# Create a table and table header with 5 columns
table, tableGroup = self._PrepareTable(
identifier=self._packageID,
columns={
"Filename": 500,
"Total": 100,
"Covered": 100,
"Missing": 100,
"Coverage in %": 100
},
columns=[
("Filename", None, 500),
("Total", None, 100),
("Covered", None, 100),
("Missing", None, 100),
("Coverage in %", None, 100)
],
classes=["report-doccov-table"]
)
tableBody = nodes.tbody()
Expand Down
52 changes: 44 additions & 8 deletions sphinx_reports/Sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,53 @@ def _ParseLegendOption(self, optionName: str, default: Nullable[LegendPosition]
except KeyError as ex:
raise ReportExtensionError(f"{self.directiveName}::{optionName}: Value '{option}' is not a valid member of 'LegendPosition'.") from ex

def _PrepareTable(self, columns: Dict[str, int], identifier: str, classes: List[str]) -> Tuple[nodes.table, nodes.tgroup]:
def _PrepareTable(self, columns: List[Tuple[str, Nullable[List[Tuple[str, int]]], Nullable[int]]], identifier: str, classes: List[str]) -> Tuple[nodes.table, nodes.tgroup]:
table = nodes.table("", identifier=identifier, classes=classes)

tableGroup = nodes.tgroup(cols=(len(columns)))
table += tableGroup
hasSecondHeaderRow = False
columnCount = 0
for groupColumn in columns:
if groupColumn[1] is not None:
columnCount += len(groupColumn[1])
hasSecondHeaderRow = True
else:
columnCount += 1

tableRow = nodes.row()
for columnTitle, width in columns.items():
tableGroup += nodes.colspec(colwidth=width)
tableRow += nodes.entry("", nodes.paragraph(text=columnTitle))
tableGroup = nodes.tgroup(cols=columnCount)
table += tableGroup

tableGroup += nodes.thead("", tableRow)
# Setup column specifications
for _, more, width in columns:
if more is None:
tableGroup += nodes.colspec(colwidth=width)
else:
for _, width in more:
tableGroup += nodes.colspec(colwidth=width)

# Setup primary header row
headerRow = nodes.row()
for columnTitle, more, _ in columns:
if more is None:
headerRow += nodes.entry("", nodes.paragraph(text=columnTitle), morerows=1)
else:
morecols = len(more) - 1
headerRow += nodes.entry("", nodes.paragraph(text=columnTitle), morecols=morecols)
for i in range(morecols):
headerRow += None

tableHeader = nodes.thead("", headerRow)
tableGroup += tableHeader

# If present, setup secondary header row
if hasSecondHeaderRow:
tableRow = nodes.row()
for columnTitle, more, _ in columns:
if more is None:
tableRow += None
else:
for columnTitle, _ in more:
tableRow += nodes.entry("", nodes.paragraph(text=columnTitle))

tableHeader += tableRow

return table, tableGroup
22 changes: 11 additions & 11 deletions sphinx_reports/Unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ def _CheckConfiguration(self) -> None:
raise ReportExtensionError(f"conf.py: {ReportDomain.name}_{self.configPrefix}_testsuites:{self._reportID}.xml_report: Unittest report file '{self._xmlReport}' doesn't exist.") from FileNotFoundError(self._xmlReport)

def _GenerateTestSummaryTable(self) -> nodes.table:
# Create a table and table header with 5 columns
# Create a table and table header with 8 columns
table, tableGroup = self._PrepareTable(
identifier=self._reportID,
columns={
"Testsuite / Testcase": 500,
"Testcases": 100,
"Skipped": 100,
"Errored": 100,
"Failed": 100,
"Passed": 100,
"Assertions": 100,
"Runtime (H:MM:SS.sss)": 100
},
columns=[
("Testsuite / Testcase", None, 500),
("Testcases", None, 100),
("Skipped", None, 100),
("Errored", None, 100),
("Failed", None, 100),
("Passed", None, 100),
("Assertions", None, 100),
("Runtime (H:MM:SS.sss)", None, 100),
],
classes=["report-unittest-table"]
)
tableBody = nodes.tbody()
Expand Down

0 comments on commit 170670f

Please sign in to comment.