ValidationTools

Module containing all the tools for validation.

Functions and Classes

validateDate(date_string, date_name, n_type)

Function that determines if date_string is a valid date or not

Parameters:
  • date_string (str) – value to be validated
  • date_name (str) – name of the parameter for messaging purposes
  • n_type (int) – header name id. Used for messaging purposes
Returns:

correct value as a date or None if it’s empty

validateDatetime(datetime_val, datetime_name=None, n_type=None)

Function that determines if datetime_val is a valid datetime or empty

Parameters:
  • datetime_val (str) – value to be validated
  • datetime_name (str) – name of the parameter for messaging purposes
  • n_type (int) – header name id. Used for messaging.
Returns:

Correct value as a datetime or None if it’s empty

validateFencatString(fencat_string)

Function for validating that a given string is a valid FENCAT string.

Parameters:fencat_string (str) – FENCAT string to be validates
Returns:Input (without a possible newline in the end) if valid -or- empty string if not valid.
validateFloat(val, value_name, low, high, n_type)

Function that determines and returns string as float if the given value is valid float, falls between given parameters and is not nAn or inf.

Parameters:
  • val (str) – value to be validated
  • value_name (str) – name of the parameter for messaging purposes
  • low (float) – lower limit of the val
  • high (float) – upper limit of the val
  • n_type (int) – header name id. Used for messaging purposes
Returns:

correct value as a float or None if it’s empty

validateInteger(val, value_name, low, high, n_type)

Function that determines and returns a string as integer or None if the given value is valid integer and falls between given parameters or is empty.

Parameters:
  • val (str) – value to be validated
  • value_name (str) – name of the parameter for messaging purposes
  • low (int) – lower limit of the val
  • high (int) – upper limit of the val
  • n_type (int) – header name id. Used for messaging purposes
Returns:

correct value as a integer or None if it’s empty

validateNordicString(nordic_seq)

Function for validating a string is of Nordic Format. Currently done by checking it begins following the formatting of Nordic Main Header.

Parameters:nordic_seq (str) – String that is to be validated
Returns:Returns the input string if it’s valid, returns empty string otherwise
validatePID(pid, allow_empty=False)

Function for validating Persistent IDs.

Parameters:
  • pid – PID to validate, can be string or Pid object
  • allow_empty (bool) – If true giving empty string as argument does not raise exceptions
Returns:

PID as a string if argument is valid

validateString(string, string_name, minlen, maxlen, list_of_allowed, n_type)

Function that determines if val is empty, falls between given parameters or can be found from a given list.

Parameters:
  • string (str) – value to be validated
  • string_name (str) – name of the parameter for messaging purposes
  • minlen (int) – lower limit of the string length
  • maxlen (int) – upper limit of the string length
  • list_of_allowed (array) – list of valid string from where the string needs to be found
  • n_type (int) – header name id. Used for messaging purposes
Returns:

the same string or None if it’s empty

validateTime(time_string, time_name, n_type)

Function that determines if a time_string is a valid time or not

Parameters:
  • time_string (str) – value to be validated
  • time_name (str) – name of the parameter for messaging purposes
  • n_type (int) – header name id. Used for messaging purposes
Returns:

correct value as a time or None if it’s empty

validateWfdiscTimestamp(timestamp)

Function for validating that a given timestamp string is of format YYYYDDDHHMMSS

Parameters:timestamp (str) – Timestamp to be validated
Returns:Returns the input string if it’s valid, returns empty string otherwise