dcc_json_toolkit.content_validation

Functions to validate the contents of a DCC.

These functions ignore any schema rules. They all work based on the content no matter if the schema is correct or not.

extract_dcc_elements

extract_dcc_elements(
    data: dict | list, element_name: str, path: str = "", case_sensitive: bool = True
) -> list[tuple[str, dict]]

Extracting all elements (recursively) partially containing the name.

Parameters:
  • data (dict | list) –

    Content of the DCC. It does not matter if this content actually follows all the schema rules.

  • element_name (str) –

    Partial name of the element to search, without the need of defining the import. E.G.: 'list' for 'dcc:list' or 'real' for both 'si:real' and 'si:realListXMLList'. See the example below for more information.

  • path (str, default: '' ) –

    Complete path to the element. This argument should be provided only if any element is obtained in a recursive way.

  • case_sensitive (bool, default: True ) –

    Flag defining whether the target element_name should be searched with a case-sensitive pattern.

Returns:
  • elements( list[tuple[str, dict]] ) –

    Iterable where each element is composed as a tuple of two items: the XPath to that element and the content of the element (in that order).

Examples:

Assuming a DCC data with multiple quantities, these quantities can have units under one of the following names (ignoring the namespace import): - 'unit' - 'unitXMLList' - 'unitPhase' - 'unitPhaseXMLList' - etc. Invoking extract_dcc_elements(data, element_name="unit") returns a list with the units declared under all previous listed names.

validate_dcc_content

validate_dcc_content(dcc_source: DccSourceContent) -> list[str]

Checks over the contents of a DCC.

Currently only some content items are checked, as each check requires some rules identifying what is correct. The current checks are:

  • Valid ISO dates in any 'date' field.
  • Correctness over D-SI units.
  • Check over dimension tables and their index quantities.
Returns:
  • content_errors

    A list of messages for each single element that has not passed the check. Each message has the following structure: [Element {ELEMENT_XPATH}] -> {REASON}