Skip to content

Commit 12e8985

Browse files
committed
Documentation improvements for validation and XmlCheck
1 parent 57131a4 commit 12e8985

6 files changed

Lines changed: 65 additions & 7 deletions

File tree

docs/source/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@
5151
autosummary_generate = True
5252
todo_include_todos = True
5353

54+
autodoc_default_options = {
55+
# 'no-index-entry': ['src'],
56+
}
57+
5458
language = 'en'
5559
# master_doc = 'docs/index'
5660
pygments_style = 'sphinx'
5761
source_suffix = '.rst'
5862

63+
napoleon_google_docstring = True
64+
5965
# -- Options for HTML output ----------------------------------------------
6066
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
6167

docs/source/validationLogging.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,12 @@ appropriate check codes, for example the
2525
:py:class:`XmlPassChecker<src.validationLogging.validationSummariser.XmlPassChecker>` has a ``_check_codes``
2626
list that contains all the appropriate ``ValidationCode`` values
2727
for which check failures would indicate that the input is not
28-
valid XML.
28+
valid XML, whereas the
29+
:py:class:`TtmlPassChecker<src.validationLogging.validationSummariser.TtmlPassChecker>` has TTML-specific check failures.
30+
31+
Typically a :py:class:`ConstraintSet<src.constraintSets.constraintSet.ConstraintSet>`
32+
would check each appropriate ``ValidationPassChecker`` that is
33+
relevant for its purpose, in its static
34+
:py:meth:`summarise<src.constraintSets.constraintSet.ConstraintSet.summarise>` method, so that the results can be used to establish
35+
where the error lies, for example the input document might be valid
36+
XML but contain TTML errors.

docs/source/xmlChecks.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
11
XML (post-parsing) Checks
22
=========================
33

4+
Assuming that parsing is successful, the validator creates an ``ElementTree``
5+
object that represents the parsed XML document. It then iterates through the
6+
list of :py:class:`XMLChecks<src.xmlChecks.xmlCheck.XmlCheck>`
7+
supplied by the selected
8+
:py:class:`ConstraintSet<src.constraintSets.constraintSet.ConstraintSet>`.
9+
10+
Each of these ``XMLCheck`` objects must be a derived class that implements
11+
the :py:meth:`run<src.xmlChecks.xmlCheck.XmlCheck.run>` method,
12+
stores any validation results and returns a boolean,
13+
``True`` if the check passes, ``False`` otherwise.
14+
15+
``XMLCheck`` objects are _not_ supposed to modify the ``input``.
16+
It may be that information can be derived during a check that is needed
17+
for a later check. This can be stored in the ``context`` dictionary.
18+
There is currently no dependency modelling to deal with checks that are
19+
dependent on other checks having already run; in that scenario the check
20+
should be written to proceed in some safe way, for example exiting
21+
without completing the check and logging a :py:obj:`SKIP<src.validationLogging.validationResult.SKIP>`
22+
:py:class:`ValidationResult<src.validationLogging.validationResult.ValidationResult>`.
23+
24+
There are a large number of checks, some of which traverse the element tree,
25+
others that just check for a simple individual thing. Each derived
26+
class should document itself. They live in the
27+
:py:mod:`xmlChecks<src.xmlChecks>` module.

src/validationLogging/validationResult.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
from .validationCodes import ValidationCode
33

44
GOOD = 0
5+
"""Validation status code for a passed check, content is valid"""
56
INFO = 1
7+
"""Validation status code for information generated by a check"""
68
WARN = 2
9+
"""Validation status code for a warning generated by a check"""
710
ERROR = 3
11+
"""Validation status code for a failed check, content is invalid"""
812
SKIP = 4
13+
"""Validation status code for skipped check"""
914

1015
StatusStrings = {
1116
GOOD: 'Success',
@@ -14,6 +19,9 @@
1419
ERROR: 'Error',
1520
SKIP: 'Skip',
1621
}
22+
"""
23+
Map of Validation status codes to human readable strings
24+
"""
1725

1826

1927
@dataclass

src/validationLogging/validationSummariser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class ValidationPassChecker():
7-
_check_codes = []
7+
_check_codes: list[ValidationCode] = []
88

99
@classmethod
1010
def failuresAndWarningsAndSkips(
@@ -29,7 +29,7 @@ def failuresAndWarningsAndSkips(
2929

3030

3131
class XmlPassChecker(ValidationPassChecker):
32-
_check_codes = [
32+
_check_codes: list[ValidationCode] = [
3333
ValidationCode.preParse_nullBytes,
3434
ValidationCode.preParse_encoding,
3535
ValidationCode.preParse_byteOrderMark,
@@ -41,7 +41,7 @@ class XmlPassChecker(ValidationPassChecker):
4141

4242

4343
class TtmlPassChecker(ValidationPassChecker):
44-
_check_codes = [
44+
_check_codes: list[ValidationCode] = [
4545
ValidationCode.xml_root_element,
4646
ValidationCode.xml_tt_namespace,
4747
ValidationCode.ttml_idref_element_applicability,
@@ -67,7 +67,7 @@ class TtmlPassChecker(ValidationPassChecker):
6767

6868

6969
class DaptPassChecker(ValidationPassChecker):
70-
_check_codes = [
70+
_check_codes: list[ValidationCode] = [
7171
ValidationCode.xml_xsd,
7272
ValidationCode.xml_encoding_decl,
7373
ValidationCode.xml_entity_decl,
@@ -97,7 +97,7 @@ class DaptPassChecker(ValidationPassChecker):
9797

9898

9999
class EbuttdPassChecker(ValidationPassChecker):
100-
_check_codes = [
100+
_check_codes: list[ValidationCode] = [
101101
ValidationCode.xml_xsd,
102102
ValidationCode.ttml_attribute_styling_attribute,
103103
ValidationCode.ebuttd_parameter_timeBase,
@@ -123,7 +123,7 @@ class EbuttdPassChecker(ValidationPassChecker):
123123

124124

125125
class BbcPassChecker(ValidationPassChecker):
126-
_check_codes = [
126+
_check_codes: list[ValidationCode] = [
127127
ValidationCode.bbc_block_backgroundColor_constraint,
128128
ValidationCode.bbc_region_attributes_constraint,
129129
ValidationCode.bbc_region_backgroundColor_constraint,

src/xmlChecks/xmlCheck.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,16 @@ def run(
99
input: Element,
1010
context: dict,
1111
validation_results: ValidationLogger) -> bool:
12+
"""Runs the check.
13+
14+
Must be implemented in a derived class.
15+
16+
Args:
17+
input: The parsed XML element to check
18+
context: A context dictionary used across validation
19+
validation_results: Object in which to store any validation results
20+
21+
Returns:
22+
True if the input element passes the check, False otherwise
23+
"""
1224
raise NotImplementedError()

0 commit comments

Comments
 (0)