pyTooling.Sphinx.Unittest
A directive rendering a unit test report as a table: per testsuite and testcase, the counts and the runtime.
The reports are read by pyEDAA.Reports: a JUnit XML file in any dialect - e.g. the reports of pytest or
OSVVM -, or a test report in pyTooling’s own XML format, recognized by its root element <TestReport>. The report
files are declared in conf.py under pyTooling_Unittest_Testsuites, each with an identifier a directive
names in its :reportid: option. An entry with the key pages gets a page per testsuite and testcase, generated
below that document name (see pyTooling.Sphinx.UnittestPages):
# doc/conf.py
pyTooling_Unittest_Testsuites = {
"src": {
"xml_report": "../report/unit/unittest.xml",
"pages": "unittests/src",
}
}
The reports are read once, when the builder is initialized, and shared by every directive and page using them.
The table’s columns after the first are Column and ColumnGroup instances. A directive of another kind
of test report - e.g. a simulation framework’s build summary - derives from UnittestSummaryBase, which renders
the rows, and declares its own columns.
See also
- report:unittest-summary
→ The directive’s options and configuration, with examples.
Variables
Classes
TestsuiteConfiguration: An entry ofpyTooling_Unittest_Testsuites, afterUnittestSummary.CheckConfiguration()read it.ShowTestcases: Which testcases a unit test summary lists, by their status.Column: A column of a unit test summary table: its title, its width, and the cells it adds to the rows.ColumnGroup: A group of columns of a unit test summary table, under a common title: the table’s header gets a second row.UnittestSummaryBase: Base-class of a directive rendering a testsuite summary - unit test results - as a table, per testsuite and testcase.UnittestSummary: Thereport:unittest-summarydirective: a table of a unit test report, per testsuite and testcase.
Variables
- pyTooling.Sphinx.Unittest.CONFIG_PREFIX
Prefix every configuration value of the unit test directive carries in
conf.py.'pyTooling_Unittest'
- pyTooling.Sphinx.Unittest.REPORT_FORMATS
The report formats, by the root element of a report file.
{'TestReport': 'pyTooling', 'testsuite': 'JUnit', 'testsuites': 'JUnit'}
Classes
- class pyTooling.Sphinx.Unittest.TestsuiteConfiguration[source]
An entry of
pyTooling_Unittest_Testsuites, afterUnittestSummary.CheckConfiguration()read it.Inheritance
- __contains__(key, /)
True if the dictionary has the specified key, else False.
- __delitem__(key, /)
Delete self[key].
- __eq__(value, /)
Return self==value.
- __ge__(value, /)
Return self>=value.
- __getitem__(key, /)
Return self[key].
- __gt__(value, /)
Return self>value.
- __init__(*args, **kwargs)
- __ior__(value, /)
Return self|=value.
- __iter__()
Implement iter(self).
- __le__(value, /)
Return self<=value.
- __len__()
Return len(self).
- __lt__(value, /)
Return self<value.
- __ne__(value, /)
Return self!=value.
- classmethod __new__(*args, **kwargs)
- __or__(value, /)
Return self|value.
- __repr__()
Return repr(self).
- __reversed__()
Return a reverse iterator over the dict keys.
- __ror__(value, /)
Return value|self.
- __setitem__(key, value, /)
Set self[key] to value.
- __sizeof__()
Return the size of the dict in memory, in bytes.
- clear()
Remove all items from the dict.
- copy()
Return a shallow copy of the dict.
- classmethod fromkeys(iterable, value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items()
Return a set-like object providing a view on the dict’s items.
- keys()
Return a set-like object providing a view on the dict’s keys.
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from mapping/iterable E and F.
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values()
Return an object providing a view on the dict’s values.
- class pyTooling.Sphinx.Unittest.ShowTestcases(*values)[source]
Which testcases a unit test summary lists, by their status.
A member compares equal to a
TestcaseStatusit includes.Inheritance
- passed = 1
Passed testcases, and testcases failing as expected.
- failed = 2
Failed testcases, and testcases passing unexpectedly.
- skipped = 4
Skipped testcases.
- excluded = 8
Excluded testcases.
- errors = 16
Errored testcases, and testcases whose setup failed.
- aborted = 32
Aborted testcases.
- all = 63
Every testcase.
- not_passed = 62
Every testcase but the passed ones.
- class pyTooling.Sphinx.Unittest.Column(title, width=None, *, testsuite=None, testcase=None)[source]
A column of a unit test summary table: its title, its width, and the cells it adds to the rows.
A row shows a testsuite summary, a testsuite or a testcase. A column names a function per kind of row, which returns the cell’s content: a text, a node, or the cell itself - an
entry, e.g. to give it a CSS class. A column without a function for a kind of row leaves the cell of such a row empty.Inheritance
- Parameters:
- __init__(title, width=None, *, testsuite=None, testcase=None)[source]
Initializes a column of a unit test summary table.
- Parameters:
title (
str) – Title of the column.width (
int|None) – Optional, relative width of the column;Noneleaves it to the writer. Default:None.testsuite (
Callable[[TestsuiteBase[Any]],str|Node] |None) – Optional, function returning the content of the cell of a testsuite’s row and of a testsuite summary’s rows. Default:None.testcase (
Callable[[Testcase],str|Node] |None) – Optional, function returning the content of the cell of a testcase’s row. Default:None.
- Raises:
- Return type:
None
- _testsuite: Callable[[TestsuiteBase[Any]], str | Node] | None
Content of a testsuite(‘s summary) row.
- property Width: int | None
Read-only property to access the column’s relative width (
_width).- Returns:
The width, or
Noneif the writer chooses it.
- TestsuiteCell(testsuite)[source]
Create the column’s cell of a testsuite’s row, or of a testsuite summary’s row.
- Parameters:
testsuite (
TestsuiteBase[Any]) – The testsuite or testsuite summary.- Return type:
entry- Returns:
The cell.
- TestcaseCell(testcase)[source]
Create the column’s cell of a testcase’s row.
- Parameters:
testcase (
Testcase) – The testcase.- Return type:
entry- Returns:
The cell.
- static _Cell(function, entity)[source]
Create a cell from the content a function returns for a row’s testsuite or testcase.
- classmethod GetMethodsWithAttributes(predicate=None)
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (
type[TAttr] |Iterable[type[TAttr]] |None) – Optional, an attribute class, an iterable of attribute classes, orNoneto accept every attribute.- Return type:
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- __getstate__()
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- __setstate__(state)
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- class pyTooling.Sphinx.Unittest.ColumnGroup(title, columns)[source]
A group of columns of a unit test summary table, under a common title: the table’s header gets a second row.
Inheritance
- __init__(title, columns)[source]
Initializes a group of columns.
- Parameters:
- Raises:
ValueError – If parameter ‘title’ is None.
ValueError – If parameter ‘columns’ is None.
TypeError – If parameter ‘columns’ is not iterable.
TypeError – If parameter ‘columns’ contains an element not of type
Column.ValueError – If parameter ‘columns’ is empty.
- Return type:
None
- property Columns: tuple[Column, ...]
Read-only property to access the grouped columns (
_columns).- Returns:
The columns, in their order in the table.
- classmethod GetMethodsWithAttributes(predicate=None)
Return the class’ methods that carry at least one matching attribute.
- Parameters:
predicate (
type[TAttr] |Iterable[type[TAttr]] |None) – Optional, an attribute class, an iterable of attribute classes, orNoneto accept every attribute.- Return type:
- Returns:
Dictionary of methods and the matching attributes attached to them.
- Raises:
ValueError – If an element of parameter ‘predicate’ is not a sub-class of
Attribute.ValueError – If parameter ‘predicate’ is neither an attribute class nor an iterable of those.
- __getstate__()
Return the object’s state for pickling, collecting every slot of the class hierarchy.
- __setstate__(state)
Restore the object’s state from unpickling, requiring exactly the slots of the class hierarchy.
- class pyTooling.Sphinx.Unittest.UnittestSummaryBase(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]
Base-class of a directive rendering a testsuite summary - unit test results - as a table, per testsuite and testcase.
The table has a row per testsuite and listed testcase, indented by its depth, optionally a row of the testsuite summary above them, and a row of the overall status below them. Its first column names the row - linked to the row’s page, if the report has pages -, the other columns are the
ColumnandColumnGroupinstances_Columns()returns.The report files are declared in a configuration value of
conf.py(_CONFIG_VALUE), each with an identifier, the report file (key_REPORT_KEY) and optionally the keypages. A derived class names them, declares its own class variables_testSummaries,_reportsand_readErrors, reads a report file by_ReadReport(), reads its options in_CheckOptions(), and returns its pages by_Pages().A legend of the status symbols (
_LEGEND) is drawn below the table, or above it or not at all, as option:legend:chooses; a derived class accepts the option by adding"legend": LegendPosition.Parseto itsoption_spec.Inheritance
- _NAME_COLUMN: ClassVar[Column] = <pyTooling.Sphinx.Unittest.Column object>
The first column, naming the rows.
- _reports: ClassVar[dict[str, TestsuiteSummary]]
Reports read by
ReadReports(), by ID.
- _LEGEND: ClassVar[tuple[tuple[str, str], ...]] = (('✅', 'passed'), ('❌', 'failed'), ('⚠️', 'skipped'), ('➖', 'excluded'), ('❗', 'errored'), ('⛔', 'setup error'), ('🚫', 'aborted'), ('❓', 'unknown'))
The status symbols of testsuites and testcases with the word explaining each, in the order of the legend.
- _showTestcases: ShowTestcases
Which testcases are listed.
- _legend: LegendPosition
Where the legend of the status symbols is drawn, by option
:legend:.
- _testsuite: TestsuiteSummary
The report’s testsuite summary.
- _CheckOptions()[source]
Parse all directive options or use default values.
A derived class sets
_cssClasses,_reportID,_reportFile,_hideTestsuiteSummary,_testsuiteSummaryNameand_showTestcases.- Return type:
- classmethod CheckConfiguration(sphinxApplication, sphinxConfiguration)[source]
Check the configuration value and load the report configurations.
- classmethod ReadReports(sphinxApplication)[source]
Read every configured report, once per build.
A report that can’t be read keeps the exception, which a directive or a report’s pages show when they need it.
- classmethod GetReport(reportID)[source]
Return a report read by
ReadReports().- Parameters:
reportID (
str) – Identifier of the report.- Return type:
TestsuiteSummary- Returns:
The report’s testsuite summary.
- Raises:
ReportExtensionError – If the report wasn’t read, chained to the exception reading it raised.
- classmethod _ReadReport(reportFile)[source]
Read a report file.
- Parameters:
reportFile (
Path) – The report file.- Return type:
TestsuiteSummary- Returns:
The report’s testsuite summary, aggregated.
- classmethod _CheckConfiguration(sphinxConfiguration)[source]
Check and load the report configurations from the configuration value
_CONFIG_VALUE.- Parameters:
sphinxConfiguration (
Config) – Sphinx configuration instance.- Raises:
ReportExtensionError – If the configuration value isn’t registered.
ReportExtensionError – If a report configuration has no report file (key
_REPORT_KEY).ReportExtensionError – If the report file doesn’t exist.
ReportExtensionError – If
pagesisn’t a string.ReportExtensionError – If
pagesisn’t a relative document name.
Use a name like ‘unittests/src’, separated by ‘/’, without ‘.’ or ‘..’.
- Return type:
- _Columns()[source]
Return the table’s columns after the first one, which names the rows.
- Return type:
- Returns:
The columns and groups of columns, in their order in the table.
- _Pages()[source]
Return the pages of the report, which the first column links to.
- Return type:
ReportPages[Any] |None- Returns:
The report’s pages, or
Noneif it has none.
- _TableClasses()[source]
Return the CSS classes of the table:
report-unittest-table,report-unittest-<report ID>and the classes of option:class:.
- static _ConvertTestcaseStatusToSymbol(status)[source]
Return the symbol shown for a testcase’s status.
- Parameters:
status (
TestcaseStatus) – The testcase’s status.- Return type:
- Returns:
An emoji, e.g. ✅ for a passed testcase.
- static _ConvertTestsuiteStatusToSymbol(status)[source]
Return the symbol shown for a testsuite’s status.
- Parameters:
status (
TestsuiteStatus) – The testsuite’s status.- Return type:
- Returns:
An emoji, e.g. ✅ for a passed testsuite.
- _GenerateTestSummaryTable()[source]
Build the table: a header of the columns, a row per testsuite and listed testcase, and a summary row.
A header has a second row, if a column is a
ColumnGroup.- Return type:
table- Returns:
The table.
- _CreateLegend()[source]
Build the legend of the status symbols: a paragraph naming each symbol of
_LEGENDwith its word.The paragraph gets the CSS classes
report-unittest-legendandreport-unittest-legend-<position>.- Return type:
paragraph- Returns:
The legend.
- _RenderRoot(tableBody, columns, testsuiteSummary, includeRoot=True, testsuiteSummaryName=None)[source]
Add the rows of a testsuite summary: optionally its own row, its testsuites’ rows, and the summary row.
- Parameters:
tableBody (
tbody) – The table body the rows are added to.testsuiteSummary (
TestsuiteSummary) – The testsuite summary.includeRoot (
bool) – Optional, whether the testsuite summary gets a row of its own. Default:True.testsuiteSummaryName (
str|None) – Optional, name replacing the testsuite summary’s name;""keeps it. Default:None.
- Return type:
- _RenderTestsuite(tableBody, columns, testsuite, level)[source]
Add a row for a testsuite, then - recursively - rows for its testsuites and its listed testcases.
- _NameEntry(level, state, entity, roleName)[source]
Create the cell naming a testsuite or testcase, indented, and linked to its page if the report has pages.
- Parameters:
- Return type:
entry- Returns:
The table cell.
- _RenderSummary(tableBody, columns, testsuiteSummary)[source]
Add the summary row: the overall status and counts.
- run()[source]
Read the configured report and return it as a table, on landscape pages in LaTeX.
The legend of the status symbols is drawn below the table, or above it, as option
:legend:chooses.:legend: nonedraws no legend.A report with pages adds a hidden table of contents of its top-level testsuites, so the pages are below this document in the navigation.
- _CreateDoubleRowTableHeader(columns, identifier, classes)
Create a table whose header spans two rows, so a column can group sub-columns.
A column’s
subColumnsisNonewhen it spans both header rows, and otherwise holds the(title, width)pairs below it.- Parameters:
- Return type:
tgroup- Returns:
The table’s column group, with both header rows already in it.
- _CreateRotatedTableHeader(columns, identifier, classes)
Create a table whose header titles are rotated, for many narrow columns.
- Parameters:
- Return type:
tgroup- Returns:
The table’s column group, with the header row already in it.
- _CreateSingleRowTableHeader(columns, identifier, classes)
Create a table with a single header row.
- Parameters:
- Return type:
tgroup- Returns:
The table’s column group, with the header row already in it.
- _ParseBooleanOption(optionName, default=None)
Read an option written as
yes/trueorno/false.- Parameters:
- Return type:
- Returns:
The option’s value.
- Raises:
SphinxExtensionError – If the option wasn’t given and has no default.
SphinxExtensionError – If the option’s value is neither of the two accepted spellings.
- _ParseStringOption(optionName, default=None, regexp='\\w+')
Read an option that has to match a regular expression.
The pattern defaults to one or more word characters.
- Parameters:
- Return type:
- Returns:
The option’s value.
- Raises:
SphinxExtensionError – If the option wasn’t given and has no default.
SphinxExtensionError – If the option’s value doesn’t match the pattern.
- __init__(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)
- Return type:
None
- _internalError(container, location, message, exception)
Report an exception a directive couldn’t recover from, in the log and on the page.
A directive that fails silently leaves a hole in the documentation that nobody notices. This puts the message where a reader sees it and the traceback where a maintainer does. The exception’s notes - e.g. how to install a missing package - are logged below it.
- Parameters:
- Return type:
list[Node]- Returns:
The container, as the list a directive’s
runreturns.
- _object_hierarchy_parts(sig_node)
Returns a tuple of strings, one entry for each part of the object’s hierarchy (e.g.
('module', 'submodule', 'Class', 'method')). The returned tuple is used to properly nest children within parents in the table of contents, and can also be used within the_toc_entry_name()method.This method must not be used outwith table of contents generation.
- _toc_entry_name(sig_node)
Returns the text of the table of contents entry for the object.
This function is called once, in
run(), to set the name for the table of contents entry (a special attribute_toc_nameis set on the object node, later used inenvironment.collectors.toctree.TocTreeCollector.process_doc().build_toc()when the table of contents entries are collected).To support table of contents entries for their objects, domains must override this method, also respecting the configuration setting
toc_object_entries_show_parents. Domains must also override_object_hierarchy_parts(), with one (string) entry for each part of the object’s hierarchy. The result of this method is set on the signature node, and can be accessed assig_node['_toc_parts']for use within this method. The resulting tuple is also used to properly nest children within parents in the table of contents.An example implementations of this method is within the python domain (
PyObject._toc_entry_name()). The python domain sets the_toc_partsattribute within thehandle_signature()method.- Return type:
- Parameters:
sig_node (desc_signature)
- add_name(node)
Append self.options[‘name’] to node[‘names’] if it exists.
Also normalize the name string and register it as explicit target.
- Return type:
- add_target_and_index(name, sig, signode)
Add cross-reference IDs and entries to self.indexnode, if applicable.
name is whatever
handle_signature()returned.
- after_content()
Called after parsing content.
Used to reset information about the current directive context on the build environment.
- Return type:
- assert_has_content()
Throw an ERROR-level DirectiveError if the directive doesn’t have contents.
- before_content()
Called before parsing content.
Used to set information about the current directive context on the build environment.
- Return type:
- directive_error(level, message)
Return a DirectiveError suitable for being thrown as an exception.
Call “raise self.directive_error(level, message)” from within a directive implementation to return one single system message at level level, which automatically gets the directive block and the line number added.
Preferably use the debug, info, warning, error, or severe wrapper methods, e.g.
self.error(message)to generate an ERROR-level directive error.
- property env: BuildEnvironment
Reference to the
BuildEnvironmentobject.Added in version 1.8.
- final_argument_whitespace = False
A boolean;
Trueif the last argument may contain spaces.
- get_signatures()
Retrieve the signatures to document from the directive arguments.
By default, signatures are given as arguments, one per line.
- get_source_info()
Get source and line number.
Added in version 3.0.
- handle_signature(sig, signode)
Parse the signature sig.
The individual nodes are then appended to signode. If ValueError is raised, parsing is aborted and the whole sig is put into a single desc_name node.
The return value should be a value that identifies the object. It is passed to
add_target_and_index()unchanged, and otherwise only used to skip duplicates.
- has_content = False
A boolean;
Trueif content is allowed.
- optional_arguments = 0
Number of optional arguments after the required ones.
- parse_content_to_nodes(allow_section_headings=False)
Parse the directive’s content into nodes.
- Parameters:
allow_section_headings (
bool) – Are titles (sections) allowed in the directive’s content? Note that this option bypasses Docutils’ usual checks on doctree structure, and misuse of this option can lead to an incoherent doctree. In Docutils, section nodes should only be children ofStructuralnodes, which includesdocument,section, andsidebarnodes.- Return type:
list[Node]
Added in version 7.4.
- parse_inline(text, *, lineno=-1)
Parse text as inline elements.
- Parameters:
- Return type:
- Returns:
A list of nodes (text and inline elements) and a list of system_messages.
Added in version 7.4.
- parse_text_to_nodes(text='', /, *, offset=-1, allow_section_headings=False)
Parse text into nodes.
- Parameters:
text (
str) – Text, in string form.StringListis also accepted.allow_section_headings (
bool) – Are titles (sections) allowed in text? Note that this option bypasses Docutils’ usual checks on doctree structure, and misuse of this option can lead to an incoherent doctree. In Docutils, section nodes should only be children ofStructuralnodes, which includesdocument,section, andsidebarnodes.offset (
int) – The offset of the content.
- Return type:
list[Node]
Added in version 7.4.
- required_arguments = 0
Number of required directive arguments.
- set_source_info(node)
Set source and line number to the node.
Added in version 2.1.
- Return type:
- Parameters:
node (Node)
- transform_content(content_node)
Can be used to manipulate the content.
Called after creating the content through nested parsing, but before the
object-description-transformevent is emitted, and before the info-fields are transformed.- Return type:
- Parameters:
content_node (desc_content)
- class pyTooling.Sphinx.Unittest.UnittestSummary(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]
The
report:unittest-summarydirective: a table of a unit test report, per testsuite and testcase.Inheritance
- has_content = False
A boolean;
Trueif content is allowed.
- required_arguments = 0
Number of required directive arguments.
- optional_arguments = 6
Number of optional arguments.
- option_spec: dict[str, Any] = {'class': <function strip>, 'hide-testsuite-summary': <function flag>, 'legend': <bound method StringEnum.Parse of <enum 'LegendPosition'>>, 'no-assertions': <function flag>, 'reportid': <function stripAndNormalize>, 'show-testcases': <function stripAndNormalize>, 'testsuite-summary-name': <function strip>}
Mapping of option names to validator functions.
- configValues: ClassVar[dict[str, tuple[Any, str, Any]]] = {'Testsuites': ({}, 'env', <class 'dict'>)}
Values added to
conf.py, asname: (default, rebuild, types), prefixed byCONFIG_PREFIX.
- _CONFIG_VALUE: ClassVar[str] = 'pyTooling_Unittest_Testsuites'
Configuration value declaring the reports.
- classmethod CheckConfiguration(sphinxApplication, sphinxConfiguration)
Check the configuration value and load the report configurations.
- classmethod GetReport(reportID)
Return a report read by
ReadReports().- Parameters:
reportID (
str) – Identifier of the report.- Return type:
TestsuiteSummary- Returns:
The report’s testsuite summary.
- Raises:
ReportExtensionError – If the report wasn’t read, chained to the exception reading it raised.
- classmethod ReadReports(sphinxApplication)
Read every configured report, once per build.
A report that can’t be read keeps the exception, which a directive or a report’s pages show when they need it.
- classmethod _CheckConfiguration(sphinxConfiguration)
Check and load the report configurations from the configuration value
_CONFIG_VALUE.- Parameters:
sphinxConfiguration (
Config) – Sphinx configuration instance.- Raises:
ReportExtensionError – If the configuration value isn’t registered.
ReportExtensionError – If a report configuration has no report file (key
_REPORT_KEY).ReportExtensionError – If the report file doesn’t exist.
ReportExtensionError – If
pagesisn’t a string.ReportExtensionError – If
pagesisn’t a relative document name.
Use a name like ‘unittests/src’, separated by ‘/’, without ‘.’ or ‘..’.
- Return type:
- static _ConvertTestcaseStatusToSymbol(status)
Return the symbol shown for a testcase’s status.
- Parameters:
status (
TestcaseStatus) – The testcase’s status.- Return type:
- Returns:
An emoji, e.g. ✅ for a passed testcase.
- static _ConvertTestsuiteStatusToSymbol(status)
Return the symbol shown for a testsuite’s status.
- Parameters:
status (
TestsuiteStatus) – The testsuite’s status.- Return type:
- Returns:
An emoji, e.g. ✅ for a passed testsuite.
- _CreateDoubleRowTableHeader(columns, identifier, classes)
Create a table whose header spans two rows, so a column can group sub-columns.
A column’s
subColumnsisNonewhen it spans both header rows, and otherwise holds the(title, width)pairs below it.- Parameters:
- Return type:
tgroup- Returns:
The table’s column group, with both header rows already in it.
- _CreateLegend()
Build the legend of the status symbols: a paragraph naming each symbol of
_LEGENDwith its word.The paragraph gets the CSS classes
report-unittest-legendandreport-unittest-legend-<position>.- Return type:
paragraph- Returns:
The legend.
- _CreateRotatedTableHeader(columns, identifier, classes)
Create a table whose header titles are rotated, for many narrow columns.
- Parameters:
- Return type:
tgroup- Returns:
The table’s column group, with the header row already in it.
- _CreateSingleRowTableHeader(columns, identifier, classes)
Create a table with a single header row.
- Parameters:
- Return type:
tgroup- Returns:
The table’s column group, with the header row already in it.
- static _FormatTimedelta(delta)
Format a duration as
HH:MM:SS.sss, rounded to milliseconds.
- _GenerateTestSummaryTable()
Build the table: a header of the columns, a row per testsuite and listed testcase, and a summary row.
A header has a second row, if a column is a
ColumnGroup.- Return type:
table- Returns:
The table.
- _LEGEND: ClassVar[tuple[tuple[str, str], ...]] = (('✅', 'passed'), ('❌', 'failed'), ('⚠️', 'skipped'), ('➖', 'excluded'), ('❗', 'errored'), ('⛔', 'setup error'), ('🚫', 'aborted'), ('❓', 'unknown'))
The status symbols of testsuites and testcases with the word explaining each, in the order of the legend.
- _NAME_COLUMN: ClassVar[Column] = <pyTooling.Sphinx.Unittest.Column object>
The first column, naming the rows.
- _NameEntry(level, state, entity, roleName)
Create the cell naming a testsuite or testcase, indented, and linked to its page if the report has pages.
- Parameters:
- Return type:
entry- Returns:
The table cell.
- _ParseBooleanOption(optionName, default=None)
Read an option written as
yes/trueorno/false.- Parameters:
- Return type:
- Returns:
The option’s value.
- Raises:
SphinxExtensionError – If the option wasn’t given and has no default.
SphinxExtensionError – If the option’s value is neither of the two accepted spellings.
- _ParseStringOption(optionName, default=None, regexp='\\w+')
Read an option that has to match a regular expression.
The pattern defaults to one or more word characters.
- Parameters:
- Return type:
- Returns:
The option’s value.
- Raises:
SphinxExtensionError – If the option wasn’t given and has no default.
SphinxExtensionError – If the option’s value doesn’t match the pattern.
- _RenderRoot(tableBody, columns, testsuiteSummary, includeRoot=True, testsuiteSummaryName=None)
Add the rows of a testsuite summary: optionally its own row, its testsuites’ rows, and the summary row.
- Parameters:
tableBody (
tbody) – The table body the rows are added to.testsuiteSummary (
TestsuiteSummary) – The testsuite summary.includeRoot (
bool) – Optional, whether the testsuite summary gets a row of its own. Default:True.testsuiteSummaryName (
str|None) – Optional, name replacing the testsuite summary’s name;""keeps it. Default:None.
- Return type:
- _RenderSummary(tableBody, columns, testsuiteSummary)
Add the summary row: the overall status and counts.
- _RenderTestcase(tableBody, columns, testcase, level)
Add a row for a testcase.
- _RenderTestsuite(tableBody, columns, testsuite, level)
Add a row for a testsuite, then - recursively - rows for its testsuites and its listed testcases.
- _SortedValues(d)
Yield the values of a mapping, sorted by key.
- _TableClasses()
Return the CSS classes of the table:
report-unittest-table,report-unittest-<report ID>and the classes of option:class:.
- __init__(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)
- Return type:
None
- _internalError(container, location, message, exception)
Report an exception a directive couldn’t recover from, in the log and on the page.
A directive that fails silently leaves a hole in the documentation that nobody notices. This puts the message where a reader sees it and the traceback where a maintainer does. The exception’s notes - e.g. how to install a missing package - are logged below it.
- Parameters:
- Return type:
list[Node]- Returns:
The container, as the list a directive’s
runreturns.
- _object_hierarchy_parts(sig_node)
Returns a tuple of strings, one entry for each part of the object’s hierarchy (e.g.
('module', 'submodule', 'Class', 'method')). The returned tuple is used to properly nest children within parents in the table of contents, and can also be used within the_toc_entry_name()method.This method must not be used outwith table of contents generation.
- _testSummaries: ClassVar[dict[str, TestsuiteConfiguration]] = {'example': {'pages': 'unittests/example', 'xml_report': PosixPath('../tests/data/Report/unittest.xml')}, 'pytooling': {'pages': 'unittests/pytooling', 'xml_report': PosixPath('../tests/data/Report/TestReport.xml')}, 'src': {'pages': 'unittests/src', 'xml_report': PosixPath('../report/unit/unittest.xml')}}
Report configurations, by report ID.
- _toc_entry_name(sig_node)
Returns the text of the table of contents entry for the object.
This function is called once, in
run(), to set the name for the table of contents entry (a special attribute_toc_nameis set on the object node, later used inenvironment.collectors.toctree.TocTreeCollector.process_doc().build_toc()when the table of contents entries are collected).To support table of contents entries for their objects, domains must override this method, also respecting the configuration setting
toc_object_entries_show_parents. Domains must also override_object_hierarchy_parts(), with one (string) entry for each part of the object’s hierarchy. The result of this method is set on the signature node, and can be accessed assig_node['_toc_parts']for use within this method. The resulting tuple is also used to properly nest children within parents in the table of contents.An example implementations of this method is within the python domain (
PyObject._toc_entry_name()). The python domain sets the_toc_partsattribute within thehandle_signature()method.- Return type:
- Parameters:
sig_node (desc_signature)
- add_name(node)
Append self.options[‘name’] to node[‘names’] if it exists.
Also normalize the name string and register it as explicit target.
- Return type:
- add_target_and_index(name, sig, signode)
Add cross-reference IDs and entries to self.indexnode, if applicable.
name is whatever
handle_signature()returned.
- after_content()
Called after parsing content.
Used to reset information about the current directive context on the build environment.
- Return type:
- assert_has_content()
Throw an ERROR-level DirectiveError if the directive doesn’t have contents.
- before_content()
Called before parsing content.
Used to set information about the current directive context on the build environment.
- Return type:
- directive_error(level, message)
Return a DirectiveError suitable for being thrown as an exception.
Call “raise self.directive_error(level, message)” from within a directive implementation to return one single system message at level level, which automatically gets the directive block and the line number added.
Preferably use the debug, info, warning, error, or severe wrapper methods, e.g.
self.error(message)to generate an ERROR-level directive error.
- property env: BuildEnvironment
Reference to the
BuildEnvironmentobject.Added in version 1.8.
- final_argument_whitespace = False
A boolean;
Trueif the last argument may contain spaces.
- get_signatures()
Retrieve the signatures to document from the directive arguments.
By default, signatures are given as arguments, one per line.
- get_source_info()
Get source and line number.
Added in version 3.0.
- handle_signature(sig, signode)
Parse the signature sig.
The individual nodes are then appended to signode. If ValueError is raised, parsing is aborted and the whole sig is put into a single desc_name node.
The return value should be a value that identifies the object. It is passed to
add_target_and_index()unchanged, and otherwise only used to skip duplicates.
- parse_content_to_nodes(allow_section_headings=False)
Parse the directive’s content into nodes.
- Parameters:
allow_section_headings (
bool) – Are titles (sections) allowed in the directive’s content? Note that this option bypasses Docutils’ usual checks on doctree structure, and misuse of this option can lead to an incoherent doctree. In Docutils, section nodes should only be children ofStructuralnodes, which includesdocument,section, andsidebarnodes.- Return type:
list[Node]
Added in version 7.4.
- parse_inline(text, *, lineno=-1)
Parse text as inline elements.
- Parameters:
- Return type:
- Returns:
A list of nodes (text and inline elements) and a list of system_messages.
Added in version 7.4.
- parse_text_to_nodes(text='', /, *, offset=-1, allow_section_headings=False)
Parse text into nodes.
- Parameters:
text (
str) – Text, in string form.StringListis also accepted.allow_section_headings (
bool) – Are titles (sections) allowed in text? Note that this option bypasses Docutils’ usual checks on doctree structure, and misuse of this option can lead to an incoherent doctree. In Docutils, section nodes should only be children ofStructuralnodes, which includesdocument,section, andsidebarnodes.offset (
int) – The offset of the content.
- Return type:
list[Node]
Added in version 7.4.
- run()
Read the configured report and return it as a table, on landscape pages in LaTeX.
The legend of the status symbols is drawn below the table, or above it, as option
:legend:chooses.:legend: nonedraws no legend.A report with pages adds a hidden table of contents of its top-level testsuites, so the pages are below this document in the navigation.
- set_source_info(node)
Set source and line number to the node.
Added in version 2.1.
- Return type:
- Parameters:
node (Node)
- transform_content(content_node)
Can be used to manipulate the content.
Called after creating the content through nested parsing, but before the
object-description-transformevent is emitted, and before the info-fields are transformed.- Return type:
- Parameters:
content_node (desc_content)
- _showTestcases: ShowTestcases
Which testcases are listed.
- _legend: LegendPosition
Where the legend of the status symbols is drawn, by option
:legend:.
- _testsuite: TestsuiteSummary
The report’s testsuite summary.
- _reports: ClassVar[dict[str, TestsuiteSummary]] = {'example': <pyEDAA.Reports.Unittesting.TestsuiteSummary object>, 'pytooling': <pyEDAA.Reports.Unittesting.pyTooling.Document object>, 'src': <pyEDAA.Reports.Unittesting.TestsuiteSummary object>}
Reports read by
ReadReports(), by ID.
- _CheckOptions()[source]
Parse all directive options or use default values.
- Raises:
SphinxExtensionError – If option
:class:isn’t a list of CSS class names.SphinxExtensionError – If option
:show-testcases:is neitherallnornot-passed.SphinxExtensionError – If option
:reportid:is missing.ReportExtensionError – If
pyTooling_Unittest_Testsuiteshas no entry for the report ID.
- Return type:
- _Columns()[source]
Return the columns after the first one: the counts of testcases, skipped, errored, failed and passed ones, the assertions - unless option
:no-assertions:is given -, and the runtime.- Return type:
- Returns:
The columns.
- _Pages()[source]
Return the pages of the report, if it was declared with the key
pages.- Return type:
ReportPages[Any] |None- Returns:
The report’s pages, or
Noneif it has none.
- classmethod _ReadReport(xmlReport)[source]
Read a report file, choosing the reader by the file’s root element.
- Parameters:
xmlReport (
Path) – The report file.- Return type:
TestsuiteSummary- Returns:
The report’s testsuite summary, aggregated.
- Raises:
ReportExtensionError – If the file’s root element is no known report format.
ReportsPackageMissingError – If pyEDAA.Reports, or its reader for the report’s format, isn’t installed.