dynsimf.models.helpers package

Submodules

dynsimf.models.helpers.ConfigValidator module

class dynsimf.models.helpers.ConfigValidator.ConfigValidator

Bases: object

A class that can be used to validate variable types and values

Mostly used to validate user specified values in a config

A value error will be thrown if a variable does not match with the expected type or value

static check_optionality(name, variable, optional)

Check whether a variable may be None, otherwise throw a value error

Parameters:
  • name (str) – Name of the variable

  • variable – The variable to check the optionality for

  • optional (bool) – Boolean indicating whether the variable can be optional

Raises:

ValueError – if the variable is None while optional is False

static check_range(name, variable, variable_range)

Check whether a variable lies within an expected range, otherwise throw a value error

Parameters:
  • name (str) – Name of the variable

  • variable – The variable to check whether the value lies in the expected range

  • variable_range (tuple(from(comparable), to(comparable(optional)))) – The expected variable range

Raises:

ValueError – if the variable does not lie in the expected range

static check_type(name, variable, variable_type)

Check whether a variable type matches with an expected type, otherwise throw a value error

Parameters:
  • name (str) – Name of the variable

  • variable – The variable to check the type for

  • variable_type – The expected variable type

Raises:

ValueError – if the variable type does not match the expected type

static check_types(name, variable, variable_types)

Check whether a variable type matches with any of the expected types, otherwise throw a value error

Parameters:
  • name (str) – Name of the variable

  • variable – The variable to check the type for

  • variable_types (list[any]) – The expected variable types

Raises:

ValueError – if the variable type does not match with any of the expected types

classmethod validate(name, variable, variable_type, variable_range=None, optional=False)

Validate a variable type, optionality and range if set

Parameters:
  • name (str) – Name of the variable

  • variable – The variable to validate

  • variable_range (tuple(start, end), optional) – The range a variable value should lie in

  • optional (bool, optional) – Boolean indicating whether the variable can be optional

Raises:

ValueError – if any of the expected variable type or values does not match

Module contents