mt_metadata.utils.validators
Convenience Classes and Functions to deal with the base metadata standards described by the csv file.
The hope is that only the csv files will need to be changed as the standards are modified. The attribute dictionaries are stored in ATTRICT
Created on Wed Apr 29 11:11:31 2020
@author: jpeacock
Functions
|
Validate a DOI string. |
|
validate header to make sure it includes the required keys: |
|
validate the name to conform to the standards |
|
validate station name to conform to general standards |
|
validate the name to conform to the standards |
|
Validate required, must be True or False |
|
Validate required type. Must be: |
|
Validate units |
|
Validate string style |
|
make sure the description is a string |
|
turn options into a list of strings |
|
validate alias names |
|
Validate example values |
|
validate default value |
|
validate type from standards |
|
Validate an input value dictionary |
Module Contents
- mt_metadata.utils.validators.validate_doi(value)
Validate a DOI string.
- Parameters:
value (str) – The DOI string to validate.
- Returns:
The validated DOI string.
- Return type:
str
- Raises:
ValueError – If the DOI string is not valid.
- mt_metadata.utils.validators.validate_header(header, attribute=False)
- validate header to make sure it includes the required keys:
‘attribute’
‘type’
‘required’
‘style’
‘units’
- Parameters:
header (list) – list of header names
attribute (bool, optional) – include attribute in test or not, by default False
- Returns:
validated header
- Return type:
list
- mt_metadata.utils.validators.validate_name(name)
validate the name to conform to the standards name must be:
all lower case {a-z; 1-9}
must start with a letter
categories are separated by ‘.’
words separated by ‘_’
{object}.{name_name}
‘/’ will be replaced with ‘.’ converted to all lower case
- Parameters:
name (str) – name name
- Returns:
valid name name
- Return type:
str
- mt_metadata.utils.validators.validate_station_name(name)
validate station name to conform to general standards
must be a string
must only contain letters, numbers, and underscores
- Parameters:
name (str | int | float) – The station name to validate
- Returns:
The validated station name
- Return type:
str
- Raises:
MTValidatorError – If name is not a string or contains invalid characters
- mt_metadata.utils.validators.validate_attribute(name)
validate the name to conform to the standards name must be:
all lower case {a-z; 1-9}
must start with a letter
categories are separated by ‘.’
words separated by ‘_’
{object}.{name_name}
‘/’ will be replaced with ‘.’ converted to all lower case
- Parameters:
name (str) – name name
- Returns:
valid name name
- Return type:
str
- mt_metadata.utils.validators.validate_required(value)
Validate required, must be True or False
- Parameters:
value (str or bool) – required value
- Returns:
validated required value
- Return type:
bool
- mt_metadata.utils.validators.validate_type(value)
- Validate required type. Must be:
str
float
int
bool
list
dict
object
- Parameters:
value (type or str) – required type
- Returns:
validated type
- Return type:
str
- mt_metadata.utils.validators.validate_units(value)
Validate units
..todo:: make a list of acceptable unit names
- Parameters:
value (str) – unit value to be validated
- Returns:
validated units
- Return type:
str
- mt_metadata.utils.validators.validate_style(value)
Validate string style
..todo:: make list of accepted style formats
- Parameters:
value (str) – style to be validated
- Returns:
validated style
- Return type:
str
- mt_metadata.utils.validators.validate_description(description)
make sure the description is a string
- Parameters:
description (str) – detailed description of an attribute
- Returns:
validated string of description
- Return type:
str
- mt_metadata.utils.validators.validate_options(options)
turn options into a list of strings
- Parameters:
options (TYPE) – DESCRIPTION
- Returns:
DESCRIPTION
- Return type:
TYPE
- mt_metadata.utils.validators.validate_alias(alias)
validate alias names
- Parameters:
alias (TYPE) – DESCRIPTION
- Returns:
DESCRIPTION
- Return type:
TYPE
- mt_metadata.utils.validators.validate_example(example)
Validate example values
- Parameters:
example (TYPE) – DESCRIPTION
- Returns:
DESCRIPTION
- Return type:
TYPE
- mt_metadata.utils.validators.validate_default(value_dict)
validate default value
- Parameters:
value_dict (TYPE) – DESCRIPTION
- Returns:
DESCRIPTION
- Return type:
TYPE
- mt_metadata.utils.validators.validate_value_type(value, v_type, style=None)
validate type from standards
- Parameters:
value (TYPE) – DESCRIPTION
v_type (TYPE) – DESCRIPTION
style (TYPE, optional) – DESCRIPTION, by default None
- Returns:
DESCRIPTION
- Return type:
TYPE
- mt_metadata.utils.validators.validate_value_dict(value_dict)
Validate an input value dictionary
- Must be of the form:
{‘type’: str, ‘required’: True, ‘style’: ‘name’, ‘units’: units}
- Parameters:
value_dict (TYPE) – DESCRIPTION
- Returns:
DESCRIPTION
- Return type:
TYPE