openepda.validators module

openepda.validators.py

This file contains validators for the data formats defined by the openEPDA.

Author: Dima Pustakhod Copyright: 2020, TU/e - PITC and authors

openepda.validators.is_cdf_valid(data, version='latest', raise_error=False, full_output=False)[source]

Check if the data is a correct CDF of a given version.

JSON Schema is used for validation. See http://json-schema.org

Parameters
  • data (any) – data structure to be validated

  • version (str) – CDF format version, ‘X.Y’ or ‘latest’

  • raise_error (bool) – If True, a jsonschema.ValidationError is raised in case of wrong format. If False, a boolean result will be returned (with optional message).

  • full_output (bool) – If False, only resulting boolean value is returned. Otherwise, additional string with a validation message is returned.

Returns

  • bool – validation result

  • str – validation message (optional)

Examples

>>> with open('tests/_test_data/cdf_correct_v0.3.cdf') as s:
...     data = safe_load(s)
>>> is_cdf_valid(data, raise_error=False)
True
>>> is_cdf_valid(data, version='0.3', raise_error=False)
True
openepda.validators.is_updk_sbb_valid(data, version='latest', raise_error=False, full_output=False)[source]

Check if the data structure is a correct uPDK SBB.

JSON Schema is used for validation. See http://json-schema.org . Validation runs against a specification with a given version.

Parameters
  • data (Dict) – data structure to be validated

  • version (str) – format version, ‘X.Y’ or ‘latest’

  • raise_error (bool) – If True, a jsonschema.ValidationError is raised in case of wrong format. If False, an boolean result will be returned (with optional message).

  • full_output (bool) – If False, only resulting boolean value is returned. Otherwise, additional string with a validation message is returned.

Returns

  • bool – validation result

  • str – validation message (optional)

Examples

>>> with open('tests/_test_data/sbb_correct_v0.2.yaml') as s:
...     data = safe_load(s)
>>> is_updk_sbb_valid(data, raise_error=True)
True