actions

Actions module.

class wmflib.actions.Actions(name: Hashable)[source]

Bases: object

Class to keep track and log a set of actions performed and their result with a nice string representation.

Initialize the instance.

When converted to string returns a nicely formatted representation of the instance and all its actions.

It exposes the following properties:

  • name: the name passed to the instance at instantiation time.

  • has_warnings: a bool that is True when at least one warning action was registered, False otherwise.

  • has_failures: a bool that is True when at least one failed action was registered, False otherwise.

Parameters

name (typing.Hashable) – the name of the set of actions to be registered.

property status: str

Return the current status of the actions based on the worst result recorded.

Returns

the short string representation of the status, one of: PASS, WARN, FAIL.

Return type

str

success(message: str) None[source]

Register a successful action.

Parameters

message (str) – the action description.

failure(message: str) None[source]

Register a failed action.

Parameters

message (str) – the action description.

warning(message: str) None[source]

Register an action that require some attention.

Parameters

message (str) – the action description.

_action(level: int, message: str) None[source]

Register a generic action.

Parameters
  • level (int) – a logging level integer to register the action for.

  • message (str) – the action description.

class wmflib.actions.ActionsDict[source]

Bases: dict

Custom dictionary with defaultdict capabilities for the wmflib.actions.Action class.

Automatically instantiate and returns a new instance of the wmflib.actions.Actions class for every missing key like a collections.defaultdict.

When accessing a missing key, the key itself is passed to the new wmflib.actions.Actions instance as name.

When converted to string returns a nicely formatted representation of the instance and all its items.