Python documentation for the leapp package¶
Subpackages¶
Submodules¶
leapp.compat module¶
-
leapp.compat.
unicode_type
¶ alias of
unicode
-
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.config module¶
-
class
leapp.config.
BetterConfigParser
(defaults=None, dict_type=<class 'collections.OrderedDict'>, allow_no_value=False)¶ Bases:
ConfigParser.ConfigParser
-
OPTCRE
= <_sre.SRE_Pattern object>¶
-
OPTCRE_NV
= <_sre.SRE_Pattern object>¶
-
SECTCRE
= <_sre.SRE_Pattern object>¶
-
add_section
(section)¶ Create a new section in the configuration.
Raise DuplicateSectionError if a section by the specified name already exists. Raise ValueError if name is DEFAULT or any of it’s case-insensitive variants.
-
defaults
()¶
-
get
(section, *args, **kwargs)¶
-
getboolean
(section, option)¶
-
getfloat
(section, option)¶
-
getint
(section, option)¶
-
has_option
(section, option)¶ Check for the existence of a given option in a given section.
-
has_section
(section)¶ Indicate whether the named section is present in the configuration.
The DEFAULT section is not acknowledged.
-
items
(section, raw=False, vars=None)¶ Return a list of tuples with (name, value) for each option in the section.
All % interpolations are expanded in the return values, based on the defaults passed into the constructor, unless the optional argument `raw’ is true. Additional substitutions may be provided using the `vars’ argument, which must be a dictionary whose contents overrides any pre-existing defaults.
The section DEFAULT is special.
-
options
(section)¶ Return a list of option names for the given section name.
-
optionxform
(optionstr)¶
-
read
(filenames)¶ Read and parse a filename or a list of filenames.
Files that cannot be opened are silently ignored; this is designed so that you can specify a list of potential configuration file locations (e.g. current directory, user’s home directory, systemwide directory), and all existing configuration files in the list will be read. A single filename may also be given.
Return list of successfully read files.
-
readfp
(fp, filename=None)¶ Like read() but the argument must be a file-like object.
The `fp’ argument must have a `readline’ method. Optional second argument is the `filename’, which if not given, is taken from fp.name. If fp has no `name’ attribute, `<???>’ is used.
-
remove_option
(section, option)¶ Remove an option.
-
remove_section
(section)¶ Remove a file section.
-
sections
()¶ Return a list of section names, excluding [DEFAULT]
-
set
(section, option, value=None)¶ Set an option.
-
write
(fp)¶ Write an .ini-format representation of the configuration state.
-
-
leapp.config.
get_config
()¶
leapp.exceptions module¶
-
exception
leapp.exceptions.
ActorDiscoveryExecutionError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
ActorInspectionFailedError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
CannotConsumeErrorMessages
¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
CommandDefinitionError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
CommandError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
CyclingDependenciesError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
InvalidTagDefinitionError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
InvalidTopicDefinitionError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
InvalidTopicItemError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
LeappRuntimeError
(message, exception_info=None)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
MissingActorAttributeError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
ModelDefinitionError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
ModuleNameAlreadyExistsError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
MultipleActorsError
(path)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
MultipleConfigActorsError
(config_actors)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
RepoItemPathDoesNotExistError
(kind, rel_path, full_path)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
RepositoryConfigurationError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
RequestStopAfterPhase
¶ Bases:
leapp.exceptions.LeappError
This exception is used to gracefully stop the current actor and request the stop of the workflow execution after the current phase.
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
StopActorExecution
¶ Bases:
exceptions.Exception
This exception is used to gracefully stop execution of actor, but allows the workflow to continue.
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
StopActorExecutionError
(message, severity='error', details=None)¶ Bases:
leapp.exceptions.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 defaultleapp.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)¶
-
-
args
¶
-
message
¶
-
exception
leapp.exceptions.
TagFilterUsageError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
UnknownCommandError
(command)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
UnsupportedDefinitionKindError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
UsageError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
WorkflowConfigNotAvailable
(actor)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
-
exception
leapp.exceptions.
WrongAttributeTypeError
(message)¶ Bases:
leapp.exceptions.LeappError
-
args
¶
-
message
¶
-
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 returnReturns:
-
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
(*args, **kwargs)¶ 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
(*args, **kwargs)¶ 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
(*args, **kwargs)¶
-
leapp.snactor.fixture.
loaded_leapp_repository
(*args, **kwargs)¶ 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 thecurrent_actor_context()
fixture. If it doesn’t use thecurrent_actor_context()
fixture, it will default to the default pytest_pyfunc_call implementation.