cape.gruvoc.errors: Error classes for gruvoc package

This module provides a collection of error types relevant to the gruvoc package. They are essentially the same as standard error types such as KeyError, TypeError, etc. but with an extra parent of GruvocError to enable catching all errors specifically raised by this package

exception cape.gruvoc.errors.GruvocAttributeError

Bases: AttributeError, GruvocError

Error related to accessing attributes

Inherits from AttributeError and GruvocError.

exception cape.gruvoc.errors.GruvocError

Bases: Exception

Parent error class for gruvoc errors

Inherits from Exception

exception cape.gruvoc.errors.GruvocFileNotFoundError

Bases: FileNotFoundError, GruvocError

Exception for missing but required file

Inherits from FileNotFoundError and :class;`GruvocError`

exception cape.gruvoc.errors.GruvocJSONError

Bases: ValueError, GruvocError

Exception class for errors while parsing JSON files

Inherits from ValueError and GruvocError

exception cape.gruvoc.errors.GruvocKeyError

Bases: KeyError, GruvocError

Exception for missing key in gruvoc

Inherits from KeyError and GruvocError

exception cape.gruvoc.errors.GruvocNameError

Bases: NameError, GruvocError

Error for badly named options in gruvoc

Inherits from NameError and GruvocError

exception cape.gruvoc.errors.GruvocNotImplementedError

Bases: NotImplementedError, GruvocError

Error for features not currently implemented

exception cape.gruvoc.errors.GruvocSystemError

Bases: SystemError, GruvocError

Exception for system errors raised by gruvoc

exception cape.gruvoc.errors.GruvocTypeError

Bases: TypeError, GruvocError

Exception for unexpected type of parameter in gruvoc

exception cape.gruvoc.errors.GruvocValueError

Bases: ValueError, GruvocError

Exception for unexpected value of parameter in gruvoc

cape.gruvoc.errors.assert_isfile(fname: str)

Ensure that a file exists

Call:
>>> assert_isfile(fname)
Inputs:
fname: str

Name of a file

Raises:

GruvocFileNotFoundError if fname does not exist

Versions:
  • 2023-10-25 @ddalle: v1.0

cape.gruvoc.errors.assert_isinstance(obj, cls_or_tuple, desc=None)

Conveniently check types

Applies isinstance(obj, cls_or_tuple) but also constructs a :class;`TypeError` and appropriate message if test fails

Call:
>>> assert_isinstance(obj, cls, desc=None)
>>> assert_isinstance(obj, cls_tuple, desc=None)
Inputs:
obj: object

Object whose type is checked

cls: type

Single permitted class

cls_tuple: tuple[type]

Tuple of allowed classes

Raises:

GruvocTypeError

cape.gruvoc.errors.assert_nd(v: ndarray, nd: int, name: str | None = None)
cape.gruvoc.errors.assert_ndmin(v: ndarray, nd: int, name: str | None = None)
cape.gruvoc.errors.assert_shape(v: ndarray, size: int, axis: int = 1, nd: int | None = None, name: str | None = None)
cape.gruvoc.errors.assert_size(v: ndarray, size: int, name: str | None = None)
cape.gruvoc.errors.assert_value(v: Any, vtarg: Any, name: str | None = None)
cape.gruvoc.errors.trunc8_fname(fname: str, n: int) → str

Truncate string so it fits in current terminal with n to spare

Call:
>>> fshort = trunc8_fname(fname, n)
Inputs:
fname: str

File name or other string to truncate

n: int

Number of chars to reserve for other text

Outputs:
fshort: str

fname or truncated version if fname won’t fit in current terminal width