Python documentation for the leapp package

Subpackages

Submodules

leapp.compat module

leapp.compat.raise_with_traceback(exc, tb)

This is a helper function to raise exceptions with a traceback.

This is function is required to workaround the syntax changes between Python 2 and 3 Python 3.4 introduced a with_traceback method to Exception classes and Python 3 removed the syntax which used to be used in Python 2.

Parameters:
  • exc – Exception to raise

  • tb – Traceback to use

Returns:

Nothing

leapp.compat.unicode_type

alias of str

leapp.config module

class leapp.config.BetterConfigParser(defaults=None, dict_type=<class 'dict'>, allow_no_value=False, *, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True, default_section='DEFAULT', interpolation=<object object>, converters=<object object>)

Bases: ConfigParser

get(section, *args, **kwargs)

Get an option value for a given section.

If vars is provided, it must be a dictionary. The option is looked up in vars (if provided), section, and in DEFAULTSECT in that order. If the key is not found and fallback is provided, it is used as a fallback value. None can be provided as a fallback value.

If interpolation is enabled and the optional argument raw is False, all interpolations are expanded in the return values.

Arguments raw, vars, and fallback are keyword only.

The section DEFAULT is special.

leapp.config.get_config()

leapp.exceptions module

exception leapp.exceptions.ActorDiscoveryExecutionError(message)

Bases: LeappError

exception leapp.exceptions.ActorInspectionFailedError(message)

Bases: LeappError

exception leapp.exceptions.CannotConsumeErrorMessages

Bases: LeappError

exception leapp.exceptions.CommandDefinitionError(message)

Bases: LeappError

exception leapp.exceptions.CommandError(message)

Bases: LeappError

exception leapp.exceptions.CyclingDependenciesError(message)

Bases: LeappError

exception leapp.exceptions.FrameworkInitializationError(message)

Bases: LeappError

exception leapp.exceptions.InvalidTagDefinitionError(message)

Bases: LeappError

exception leapp.exceptions.InvalidTopicDefinitionError(message)

Bases: LeappError

exception leapp.exceptions.InvalidTopicItemError(message)

Bases: LeappError

exception leapp.exceptions.LeappError(message)

Bases: Exception

exception leapp.exceptions.LeappRuntimeError(message, exception_info=None)

Bases: LeappError

exception leapp.exceptions.MissingActorAttributeError(message)

Bases: LeappError

exception leapp.exceptions.ModelDefinitionError(message)

Bases: LeappError

exception leapp.exceptions.ModuleNameAlreadyExistsError(message)

Bases: LeappError

exception leapp.exceptions.MultipleActorsError(path)

Bases: LeappError

exception leapp.exceptions.MultipleConfigActorsError(config_actors)

Bases: LeappError

exception leapp.exceptions.ProcessLockError(message)

Bases: LeappError

This exception is used to represent an error within the process locking mechanism.

exception leapp.exceptions.RepoItemPathDoesNotExistError(kind, rel_path, full_path)

Bases: LeappError

exception leapp.exceptions.RepositoryConfigurationError(message)

Bases: LeappError

exception leapp.exceptions.RequestStopAfterPhase

Bases: LeappError

This exception is used to gracefully stop the current actor and request the stop of the workflow execution after the current phase.

exception leapp.exceptions.StopActorExecution

Bases: Exception

This exception is used to gracefully stop execution of actor, but allows the workflow to continue.

exception leapp.exceptions.StopActorExecutionError(message, severity='error', details=None)

Bases: LeappError

This exception is used to gracefully stop execution of actor and it will call leapp.actors.Actor.report_error().

Parameters:
  • message (str) – A message to print the possible error

  • severity (str with defined values from leapp.messaging.errors.ErrorSeverity.ERROR) – Severity of the error default leapp.messaging.errors.ErrorSeverity.ERROR

  • details (dict) – A dictionary where additional context information is passed along with the error

class ErrorSeverity

Bases: object

ALLOWED_VALUES = ('fatal', 'error', 'warning')
ERROR = 'error'
FATAL = 'fatal'
WARNING = 'warning'
classmethod validate(value)
exception leapp.exceptions.TagFilterUsageError(message)

Bases: LeappError

exception leapp.exceptions.UnknownCommandError(command)

Bases: LeappError

exception leapp.exceptions.UnsupportedDefinitionKindError(message)

Bases: LeappError

exception leapp.exceptions.UsageError(message)

Bases: LeappError

exception leapp.exceptions.WorkflowConfigNotAvailable(actor)

Bases: LeappError

exception leapp.exceptions.WrongAttributeTypeError(message)

Bases: LeappError

leapp.snactor.fixture module

class leapp.snactor.fixture.ActorContext(actor=None)

Bases: object

ActorContext is a helper class for testing actors. It helps to eliminate the boilerplate for executing actors. It provides a set of methods that allow specifying input messages for the actor, executing the actor and to retrieve messages sent by the actor.

apis = ()
consume(*models)

Retrieve messages produced by the actor execution and specified in the actors produces attribute, and filter message types by models.

Parameters:

models (Variable number of the derived classes from leapp.models.Model) – Models to use as a filter for the messages to return

Returns:

feed(*models)

Feed the messaging model with messages to be available to consume.

Parameters:

models (Variable number of instances of classes derived from leapp.models.Model) – Data in form of model instances to be available for the actor to consume.

Returns:

None

messages()

Returns raw messages produced by the actor.

Returns:

list of raw message data dictionaries.

run(config_model=None)

Execute the current actor.

Parameters:

config_model (Config model instance derived from leapp.models.Model) – Config model for the actor to consume.

Returns:

None

set_actor(actor)

Internally used method to set the current actor specification object to setup the current actor for the test function.

Parameters:

actor – ActorSpecification instance to use.

Returns:

None

leapp.snactor.fixture.current_actor_context(loaded_leapp_repository)

This fixture will prepare an environment for the actor the test belongs to, to be safely executable.

current_actor_context Is an instance of leapp.snactor.fixture.ActorContext and gives access to its methods for feeding an actor with input data, running the actor, and retrieving messages produced by the actor during its execution.

Example:

from leapp.snactor.fixture import current_actor_context
from leapp.models import ConsumedExampleModel, ProducedExampleModel

def test_actor_lib_some_function(current_actor_context):
    # Feed with messages to be consumable by the actor that is going to be executed.
    current_actor_context.feed(ConsumedExampleModel(value='Some random data'))

    # Execute the actor
    current_actor_context.run()

    # Ensure that at least one message is produced
    assert current_actor_context.consume(ProducedExampleModel)

    # Ensure the value is what we expect
    assert current_actor_context.consume(ProducedExampleModel)[0].value == 42
leapp.snactor.fixture.current_actor_libraries(request, loaded_leapp_repository)

This fixture will make libraries that are private to the actor only available only for the scope of the test function that uses this fixture.

Example:

from leapp.snactor.fixture import current_actor_libraries

def test_actor_lib_some_function(current_actor_libraries):
    from leapp.libraries.actor import private
    assert private.some_function(1) == 42
leapp.snactor.fixture.leapp_forked()
leapp.snactor.fixture.loaded_leapp_repository(request)

This fixture will ensure that the repository for the current test run is loaded with all its links etc.

This enables running actors and using models, tags, topics, workflows etc.

Additionally loaded_leapp_repository gives you access to a leapp.repository.manager.RepositoryManager instance.

Example:

from leapp.snactor.fixture import loaded_leapp_repository
from leapp.models import ExampleModel, ProcessedExampleModel

def my_repository_library_test(loaded_leapp_repository):
    from leapp.libraries.common import global
    e = ExampleModel(value='Some string')
    result = global.process_function(e)
    assert type(result) is ProcessedExampleModel
leapp.snactor.fixture.pytest_pyfunc_call(pyfuncitem)

This function is a hook for pytest implementing the ability to run the actors in tests safely.

It will call leapp.snactor.fixture._execute_test() in a child process if the current test uses the current_actor_context() fixture. If it doesn’t use the current_actor_context() fixture, it will default to the default pytest_pyfunc_call implementation.

Module contents