metron_shared.param_validators module#

The module provides parameter validation functions common across Metron’s components. The scope of validation is all parameters, except validation of YAML config parameters.

metron_shared.param_validators.check_file_existence(file_path: str) None#

Validates if file path exists and is a file.

Parameters:

file_path (str) – File path.

Returns (None):

Exceptions:

OSError: If file does not exist or path is not a file.

metron_shared.param_validators.check_folder_existence(folder_path: str) None#

Validates if file path exists and is a folder.

Parameters:

folder_path (str) – Folder path.

Returns (None):

Exceptions:

OSError: If file does not exist or path is not a folder.

metron_shared.param_validators.check_length_of_list(list_instance: List[Any], expected_list_len: int) None#

Checks if a given list has expected number of items.

Parameters:
  • list (List[Any]) – List to be checked.

  • expected_list_len (int) – Number of items the list has to contain.

Returns: None

Exceptions:

ValueError: If the list has mismatched number of items.

metron_shared.param_validators.check_parameter_value_in_range(param_value: Union[int, float], lower_bound: Union[int, float], upper_bound: Union[int, float]) None#

Checks if parameter value is in range <<lower_bound>, <upper_bound>>.

Parameters:
  • param_value (Union[int, float]) – Parameter value.

  • lower_bound (Union[int, float]) – Lower bound of allowed parameter values.

  • upper_bound (Union[int, float]) – Upper bound of allowed parameter values.

Returns (None):

Exceptions:

ValueError: If value is not in the range.

metron_shared.param_validators.check_type(variable: Any, expected_type: Any) None#

Validates if given <variable> is type of <expected_type>.

Parameters:
  • variable (Any) – Variable.

  • expected_type (Any) – Type.

Returns (None):

Exceptions:

TypeError: Raised if <variable> is not type of <expected_type>.