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
ResultsBundledirectly, this class provides an easier and more flexible way to return results.Has methods to merge multiple
CheckletResultobjects into one.- Parameters:
outcome (
Union[Outcome,Literal['pass','fail','skip','error']]) – The outcome of the checklet run.properties (
dict[str,Union[str,bool,None,NewType(NoContentType,object),bytes,int,float,Decimal,Sequence[str],set[str]]] |None) –Properties of the result. A mapping of property names to values.
Property names are strings.
Property values can be a basic python value (
str,bytes,int,float,Decimal,bool,None) or a sequence or set of strings.files (
dict[Union[str,PurePath,NameClass],Union[File,ResultFile,Path,bytes]] |None) –Files of the result. A mapping of file names to files.
File names can be a
str,PurePathor aNameClassobject. Using NameClass allows to specify a class name for the file.File values can be a
Fileobject, aResultFileobject, aPathobject or abytesobject.
- 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
- classmethod fail(**properties)¶
Convenience method to create a result with outcome
FAIL, with optional properties and no files- Return type:
Self
- classmethod merge(*results, merged_prop_types=None)¶
Merge multiple
CheckletResultobjects into one. By default, properties will be merged usingoperator.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).
LTIMergePropscontains 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
- classmethod skip(**properties)¶
Convenience method to create a result with outcome
SKIP, with optional properties and no files- Return type:
Self
-
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
- class mtrchk.org.momotor.base.checklet.result.NameClass(name, class_)¶
- 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. MirrorsOutcomeSimpleType- classmethod condition(state)¶
Get outcome based on a condition
- Return type:
Self- Returns:
returns
Outcome.PASSif state is truthy, otherwise returnsOutcome.FAIL
- classmethod from_simpletype(st)¶
Create an
Outcomefrom anOutcomeSimpleType- Return type:
Self
- to_simpletype()¶
Convert into an
OutcomeSimpleType- Return type:
- 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_'})¶
-
content:
bytes|memoryview|None= None¶ The content of the file
-
VALID_ATTRS: