augur.validate

Validate files related to augur consumption or export.

exception augur.validate.ValidateError

Bases: Exception

augur.validate.auspice_config_v2(config_json, **kwargs)
augur.validate.elide_path(path)

Elide recursive .children[N] selectors from path after formatting with format_path().

Our tree JSONs are highly nested and the exact path to a node in the tree is often more noisy than useful in error messages.

>>> format_path(("tree", "children", 1, "children", 0, "children", 1, "children", 0, "node_attrs", "x"))
'.tree.children[1].children[0].children[1].children[0].node_attrs.x'
:rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
>>> elide_path(("tree", "children", 1, "children", 0, "children", 1, "children", 0, "node_attrs", "x"))
'.tree.children[…].node_attrs.x'

Elision is only used with more than a single level of .children[N].

>>> elide_path(("tree", "children", 1, "node_attrs", "x"))
'.tree.children[1].node_attrs.x'
augur.validate.export_v1(meta_json, tree_json, **kwargs)
augur.validate.export_v2(main_json, **kwargs)
augur.validate.fatal(message)
augur.validate.format_path(path)

Format an iterable of path segments, which index into a JSON document, into a more human-readable string.

Intended for folks who aren’t necessarily programmers, so this doesn’t try to construct a valid JS property accessor chain or valid JSON Path selector.

>>> format_path(("a", "b", "c"))
'.a.b.c'
>>> format_path(("l", "m-n-o", "p"))
".l.'m-n-o'.p"
:rtype: :sphinx_autodoc_typehints_type:`\:py\:class\:\`str\``
>>> format_path(("x", "y", 42, "z"))
'.x.y[42].z'
augur.validate.get_unique_keys(list_of_dicts)

Returns a set of unique keys from a list of dicts

Examples

>>> list_of_dicts = [{"key1": "val1", "key2": "val2"}, {"key1": "val1", "key3": "val3"}]
>>> sorted(get_unique_keys(list_of_dicts))
['key1', 'key2', 'key3']
augur.validate.grouped(iterable, key)

Version of itertools.groupby() which doesn’t require the caller to remember to sort first.

augur.validate.load_json(path)
augur.validate.load_json_schema(path, refs=None)

Load a JSON schema from the augur included set of schemas (located in augur/data)

augur.validate.measurements(measurements_json, **kwargs)
augur.validate.measurements_collection_config(collection_config_json, **kwargs)
augur.validate.register_parser(parent_subparsers)
augur.validate.run(args)
augur.validate.validate(jsonToValidate, schema, filename)
augur.validate.validate_collection_config_fields(collection, index=None)

Validates a single collection’s config field keys provided in fields, groupings, and filters are valid fields that exist in measurements’ fields.

Prints any validation errors to stderr.

Parameters:
  • collection (dict) – A single collection to validate. Assumes that the collection has already passed the schema validation.

  • index (int, optional) – the index of the collection within a list of collections in a measurements JSON. Used to print more detailed error messages.

Returns:

True if collection’s config is valid

Return type:

bool

augur.validate.validate_collection_display_defaults(collection, index=None)

Validates a single collection’s display defaults. If a default group-by field is provided, the field must be included in groupings.

Prints validation errors to stderr.

Parameters:
  • collection (dict) – A single collection to validate. Assumest htat the collection has already passed the schema validation.

  • index (int, optional) – The index of the collection within a list of collections in a measurements JSON. Used to print more detailed error messages.

Returns:

True if collection’s display defaults are valid

Return type:

bool

augur.validate.validate_json(jsonToValidate, schema, filename)
augur.validate.validate_measurements_config(measurements)

Validate measurements’ config values meet expectations described in the measurements JSON schema descriptions that cannot be verified via validate_json: 1. Individual collections have valid config values 2. All collections have unique keys 3. If a default collection is provided, it matches one of the collections

Prints any validation errors to stderr.

Parameters:

measurements (dict) – Loaded measurements JSON to validate. Assumes the measurements JSON has already passed the schema validation.

Returns:

True if measurements’ config is valid

Return type:

bool