lmp.util.validate#

Checking types and values.

lmp.util.validate.raise_if_empty_str(*, val: str, val_name: str) None[source]#

Raise if val is an empty str.

Parameters
  • val (str) – Test target.

  • val_name (str) – Test target name. Mainly used to create error message.

Raises

ValueError – When val is an empty str.

lmp.util.validate.raise_if_is_directory(*, path: str) None[source]#

Raise if path exists and is a directory.

Parameters

path (str) – Test path.

Raises

FileExistsError – When path exists and is a directory.

lmp.util.validate.raise_if_is_file(*, path: str) None[source]#

Raise if path exists and is a file.

Parameters

path (str) – Test path.

Raises

FileExistsError – When path exists and is a file.

lmp.util.validate.raise_if_not_in(*, val: Any, val_name: str, val_range: List) None[source]#

Raise if val is not in val_range.

Parameters
  • val (Any) – Test target.

  • val_name (str) – Test target name. Mainly used to create error message.

  • val_range (list) – Expected value range.

Raises

ValueError – When val is not in val_range.

lmp.util.validate.raise_if_not_instance(*, val: Any, val_name: str, val_type: Type) None[source]#

Raise if val is not an instance of val_type.

Parameters
  • val (Any) – Test target.

  • val_name (str) – Test target name. Mainly used to create error message.

  • val_type (Type) – Expected target type.

Raises

TypeError – When val is not an instance of val_type.

lmp.util.validate.raise_if_wrong_ordered(*, vals: List[Union[float, int]], val_names: List[str]) None[source]#

Raise if there exist some i < j such that vals[i] > vals[j].

Parameters
  • vals (list[Union[float, int]]) – Test targets.

  • val_names (list[str]) – Test targets’ names. Mainly used to create error message.

Raises

ValueError – When there exist some i < j such that vals[i] > vals[j].