Utility methods

mtrchk.org.momotor.base.checklet.legacy.convert_legacy_selector(selector, *, option_name=None)

Convert a possible legacy selector (used by the base package prior to version 2.0.0) into a modern momotor-engine-options selector. If the selector is already in modern syntax, it is returned unchanged, otherwise a deprecation warning is logged and the selector is converted to modern syntax.

Parameters:
  • selector (str) – The selector to convert.

  • option_name (str | None) – The name of the option that contains the selector, used for logging.

Return type:

str

Returns:

A modern selector.

Note

The syntax described here is deprecated. Use the modern syntax as documented here.

The selector syntax was [ <condition> ][ : <result_id> ].

Legacy selectors used the following syntax:

pass

True if outcome == pass

fail

True if outcome == fail

error

True if outcome == error

prop[x]

Property x is True

prop[x]?

Property x exists

prop[x]==0

Property x equals 0

prop[x]>0

Property x is greater than 0

prop[x]>=0

Property x is greater than or equals 0

prop[x]<0

Property x is less than 0

prop[x]<=0

Property x is less than or equals 0

To invert the check, prefix with not-:

not-pass

True if outcome != pass

not-prop[x]==0

True if property x does not equal 0

If no <result_id> is provided or it equals %all, all steps must match the condition. If <result_id> equals %any, any step can match the condition, otherwise all steps with given id must match the condition.

<result id> can contain wildcards and $ task references, see result_query() for details.

>>> convert_legacy_selector('pass')
'pass'
>>> convert_legacy_selector('pass:#all')
'%all pass'
>>> convert_legacy_selector('pass#%all')
'%all pass'
>>> convert_legacy_selector('pass:#any')
'%any pass'
>>> convert_legacy_selector('pass#%any')
'%any pass'
>>> convert_legacy_selector('pass:step-id')
'pass[#step-id]'
>>> convert_legacy_selector('pass#step-id')
'pass[#step-id]'
>>> convert_legacy_selector('prop[name]')
'prop[:name]'
>>> convert_legacy_selector('prop[name]:#any')
'%any prop[:name]'
>>> convert_legacy_selector('prop[name]#%any')
'%any prop[:name]'
>>> convert_legacy_selector('prop[name]:step-id')
'prop[#step-id:name]'
>>> convert_legacy_selector('prop[name]#step-id')
'prop[#step-id:name]'
>>> convert_legacy_selector('prop[name]?')
'prop[:name]?'
>>> convert_legacy_selector('prop[name]==0')
'prop[:name]==0'
>>> convert_legacy_selector('prop[name]?#step-id')
'prop[#step-id:name]?'
>>> convert_legacy_selector('prop[name]==0#step-id')
'prop[#step-id:name]==0'
>>> convert_legacy_selector('prop[name]==1.0#step-id')
'prop[#step-id:name]==1.0'
>>> convert_legacy_selector('prop[name]==1e10#step-id')
'prop[#step-id:name]==1e10'
>>> convert_legacy_selector('prop[name]==test#step-id')
"prop[#step-id:name]=='test'"
>>> convert_legacy_selector('not-pass#step-id')
'not-pass[#step-id]'
>>> convert_legacy_selector('not-prop[name]#step-id')
'%not prop[#step-id:name]'
>>> convert_legacy_selector('not-prop[name]#%any')
'%notany prop[:name]'
mtrchk.org.momotor.base.checklet.legacy.split_legacy_selector(selector)

Split a legacy selector into a condition and an id_query.

Parameters:

selector (str) – The legacy selector to split.

Return type:

tuple[str, str]

Returns:

A tuple of condition and id_query.

mtrchk.org.momotor.base.checklet.log_helper.safe_repr_iterable(i)

Return a safe representation of an iterable suitable for logging

Parameters:

i (TypeVar(TI, bound= Iterable)) – the iterable to be represented

Return type:

TypeVar(TI, bound= Iterable)

Returns:

a safe representation of the iterable

mtrchk.org.momotor.base.checklet.log_helper.safe_repr_mapping(m)

Return a safe representation of a mapping suitable for logging

Parameters:

m (TypeVar(TM, bound= Mapping)) – the mapping to be represented

Return type:

TypeVar(TM, bound= Mapping)

Returns:

a safe representation of the mapping

mtrchk.org.momotor.base.checklet.log_helper.safe_repr_value(v)

Return a safe representation of a value suitable for logging

Parameters:

v (Any) – the value to be represented

Return type:

Any

Returns:

a safe representation of the value

class mtrchk.org.momotor.base.checklet.meta.CheckletBaseMeta(name, bases, attrs, **kwargs)

Metaclass for all option containers

class mtrchk.org.momotor.base.checklet.meta.CheckletOptions(options, options_by_name, options_source, description=None, domain=None, location=None)
description: str | None = None

Description of the checklet (deprecated, use docstring on the Checklet class instead)

domain: str | None = None

The default domain for all options

location: str | Sequence[str] | None = None

The default location for all options

options: tuple[OptionDefinition, ...]

All options

options_by_name: dict[OptionNameDomain, OptionDefinition]

The options, indexed by name and domain

options_source: dict[OptionNameDomain, str]

Source checklet of each option. Used for linking options to their canonical location in documentation.

class mtrchk.org.momotor.base.checklet.meta.OptionDefinition

A re-export of momotor.options.OptionDefinition.

This is provided for convenience as it is often one of the few classes from the options module that are needed by checklets.

class mtrchk.org.momotor.base.checklet.meta.OptionNameDomain

A re-export of momotor.options.OptionDomainName.

This is provided for convenience as it is often one of the few classes from the options module that are needed by checklets.