Checklet results

class mtrchk.org.momotor.base.checklet.result.CheckletResult(outcome, *, properties=None, files=None)

One of the possible return types of Checklet.run().

Instead of returning a ResultsBundle directly, this class provides an easier and more flexible way to return results.

Has methods to merge multiple CheckletResult objects into one.

Parameters:
as_checklet_result()
Return type:

Self

classmethod error(**properties)

Convenience method to create a result with outcome ERROR, with optional properties and no files

Return type:

Self

errored()

Shortcut for result.outcome == Outcome.ERROR

Return type:

bool

classmethod fail(**properties)

Convenience method to create a result with outcome FAIL, with optional properties and no files

Return type:

Self

failed()

Shortcut for result.outcome == Outcome.FAIL

Return type:

bool

classmethod merge(*results, merged_prop_types=None)

Merge multiple CheckletResult objects into one. By default, properties will be merged using operator.add() which will work for strings and numeric values.

The merged_prop_types argument can be used to specify a different merge method for individual properties.

Parameters:
  • results (TypeVar(TC)) – The results to merge.

  • merged_prop_types (dict[str, tuple[type, Union[str, Callable]]] | None) –

    A mapping of property names to a tuple of the expected type and a merge method.

    The merge method can be either a callable that takes two arguments (the current value and the new value), or a string that is the name of an attribute of the current value that takes one argument (the new value).

    LTIMergeProps contains the common merge properties for results created for Momotor LTI.

Return type:

Self

Returns:

The merged result.

classmethod pass_(**properties)

Convenience method to create a result with outcome PASS, with optional properties and no files

Return type:

Self

passed()

Shortcut for result.outcome == Outcome.PASS

Return type:

bool

classmethod skip(**properties)

Convenience method to create a result with outcome SKIP, with optional properties and no files

Return type:

Self

skipped()

Shortcut for result.outcome == Outcome.SKIP

Return type:

bool

LTIMergeProps: ClassVar[dict[str, tuple[type, Union[str, Callable]]]] = {'reason': (<class 'str'>, <function CheckletResult.<lambda>>), 'report': (<class 'collections.deque'>, 'extend'), 'reportCss': (<class 'set'>, 'update'), 'reportJs': (<class 'set'>, 'update'), 'secret': (<class 'bool'>, <built-in function or_>)}

Common merge properties for Momotor LTI

files: dict[Union[str, PurePath, NameClass], Union[File, ResultFile, Path, bytes]]

Files of the result.

property outcome: Outcome

The outcome of the run

properties: dict[str, Union[str, bool, None, NewType(NoContentType, object), bytes, int, float, Decimal, Sequence[str], set[str]]]

Properties of the result.

class mtrchk.org.momotor.base.checklet.result.NameClass(name, class_)
class_: str
name: str | PurePath
class mtrchk.org.momotor.base.checklet.result.Outcome(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

An enum for the Result.outcome. Mirrors OutcomeSimpleType

classmethod condition(state)

Get outcome based on a condition

Return type:

Self

Returns:

returns Outcome.PASS if state is truthy, otherwise returns Outcome.FAIL

classmethod from_simpletype(st)

Create an Outcome from an OutcomeSimpleType

Return type:

Self

to_simpletype()

Convert into an OutcomeSimpleType

Return type:

OutcomeSimpleType

ERROR = 'error'
FAIL = 'fail'
PASS = 'pass'
SKIP = 'skip'
class mtrchk.org.momotor.base.checklet.result.ResultFile(*, src=None, content=None, **attrs)

A file in a CheckletResult.

VALID_ATTRS: ClassVar[frozenset[str]] = frozenset({'attrs', 'class_', 'executable', 'name', 'type_'})
attrs: dict | None = None

The attributes of the file

content: bytes | memoryview | None = None

The content of the file

src: Path | None = None

The source path of the file