labgrid package

Subpackages

Submodules

labgrid.binding module

exception labgrid.binding.StateError(msg) → None[source]

Bases: Exception

__attrs_attrs__ = (Attribute(name='msg', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False),)
__init__(msg) → None
__module__ = 'labgrid.binding'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

exception labgrid.binding.BindingError(msg) → None[source]

Bases: Exception

__attrs_attrs__ = (Attribute(name='msg', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False),)
__init__(msg) → None
__module__ = 'labgrid.binding'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

class labgrid.binding.BindingState[source]

Bases: enum.Enum

An enumeration.

error = -1
idle = 0
bound = 1
active = 2
__module__ = 'labgrid.binding'
__new__(value)
class labgrid.binding.BindingMixin(target, name) → None[source]

Bases: object

Handles the binding and activation of drivers and their supplying resources and drivers.

One client can be bound to many suppliers, and one supplier can be bound by many clients.

Conflicting access to one supplier can be avoided by deactivating conflicting clients before activation (using the resolve_conflicts callback).

bindings = {}
__attrs_post_init__()[source]
display_name
on_supplier_bound(supplier)[source]

Called by the Target after a new supplier has been bound

on_client_bound(client)[source]

Called by the Target after a new client has been bound

on_activate()[source]

Called by the Target when this object has been activated

on_deactivate()[source]

Called by the Target when this object has been deactivated

resolve_conflicts(client)[source]

Called by the Target to allow this object to deactivate conflicting clients.

classmethod check_active(func)[source]
class NamedBinding(value)[source]

Bases: object

Marks a binding (or binding set) as requiring an explicit name.

__init__(value)[source]
__repr__()[source]
__dict__ = mappingproxy({'__init__': <function BindingMixin.NamedBinding.__init__>, '__dict__': <attribute '__dict__' of 'NamedBinding' objects>, '__doc__': '\n Marks a binding (or binding set) as requiring an explicit name.\n ', '__repr__': <function BindingMixin.NamedBinding.__repr__>, '__module__': 'labgrid.binding', '__weakref__': <attribute '__weakref__' of 'NamedBinding' objects>})
__module__ = 'labgrid.binding'
__weakref__

list of weak references to the object (if defined)

__attrs_attrs__ = (Attribute(name='target', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='name', default=NOTHING, validator=<optional validator for <instance_of validator for type <class 'str'>> or None>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='state', default=<BindingState.idle: 0>, validator=None, repr=True, cmp=True, hash=None, init=False, metadata=mappingproxy({}), type=None, converter=None, kw_only=False))
__dict__ = mappingproxy({'on_activate': <function BindingMixin.on_activate>, '__init__': <function BindingMixin.__init__>, '__doc__': '\n Handles the binding and activation of drivers and their supplying resources\n and drivers.\n\n One client can be bound to many suppliers, and one supplier can be bound by\n many clients.\n\n Conflicting access to one supplier can be avoided by deactivating\n conflicting clients before activation (using the resolve_conflicts\n callback).\n ', 'NamedBinding': <class 'labgrid.binding.BindingMixin.NamedBinding'>, 'check_active': <classmethod object>, 'on_deactivate': <function BindingMixin.on_deactivate>, '__attrs_post_init__': <function BindingMixin.__attrs_post_init__>, '__weakref__': <attribute '__weakref__' of 'BindingMixin' objects>, 'on_supplier_bound': <function BindingMixin.on_supplier_bound>, 'resolve_conflicts': <function BindingMixin.resolve_conflicts>, '__attrs_attrs__': (Attribute(name='target', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='name', default=NOTHING, validator=<optional validator for <instance_of validator for type <class 'str'>> or None>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='state', default=<BindingState.idle: 0>, validator=None, repr=True, cmp=True, hash=None, init=False, metadata=mappingproxy({}), type=None, converter=None, kw_only=False)), '__dict__': <attribute '__dict__' of 'BindingMixin' objects>, '__repr__': <function BindingMixin.__repr__>, '__module__': 'labgrid.binding', 'bindings': {}, 'on_client_bound': <function BindingMixin.on_client_bound>, 'display_name': <property object>})
__init__(target, name) → None
__module__ = 'labgrid.binding'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

labgrid.config module

Config convenience class

This class encapsulates access functions to the environment configuration

class labgrid.config.Config(filename) → None[source]

Bases: object

__attrs_post_init__()[source]
resolve_path(path)[source]

Resolve an absolute path

Parameters:path (str) – path to resolve
Returns:the absolute path
Return type:str
get_tool(tool)[source]

Retrieve an entry from the tools subkey

Parameters:tool (str) – the tool to retrieve the path for
Returns:path to the requested tools
Return type:str
get_image_path(kind)[source]

Retrieve an entry from the images subkey

Parameters:kind (str) – the kind of the image to retrieve the path for
Returns:path to the image
Return type:str
Raises:KeyError – if the requested image can not be found in the configuration
get_path(kind)[source]

Retrieve an entry from the paths subkey

Parameters:kind (str) – the type of path to retrieve the path for
Returns:path to the path
Return type:str
Raises:KeyError – if the requested image can not be found in the configuration
get_option(name, default=None)[source]

Retrieve an entry from the options subkey

Parameters:
  • name (str) – name of the option
  • default (str) – A default parameter in case the option can not be found
Returns:

value of the option or default parameter

Return type:

str

Raises:

KeyError – if the requested image can not be found in the configuration

set_option(name, value)[source]

Set an entry in the options subkey

Parameters:
  • name (str) – name of the option
  • value (str) – the new value
get_targets()[source]
get_imports()[source]

Helper function that returns the list of all imports

Returns:List of files which should be imported
Return type:List
get_paths()[source]

Helper function that returns the subdict of all paths

Returns:Dictionary containing all path definitions
Return type:Dict
get_images()[source]

Helper function that returns the subdict of all images

Returns:Dictionary containing all image definitions
Return type:Dict
get_features()[source]
__attrs_attrs__ = (Attribute(name='filename', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False),)
__dict__ = mappingproxy({'get_image_path': <function Config.get_image_path>, 'set_option': <function Config.set_option>, 'get_path': <function Config.get_path>, '__dict__': <attribute '__dict__' of 'Config' objects>, 'get_targets': <function Config.get_targets>, 'get_features': <function Config.get_features>, '__repr__': <function Config.__repr__>, 'get_option': <function Config.get_option>, '__module__': 'labgrid.config', '__init__': <function Config.__init__>, '__attrs_attrs__': (Attribute(name='filename', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False),), 'get_images': <function Config.get_images>, 'get_tool': <function Config.get_tool>, 'get_imports': <function Config.get_imports>, '__attrs_post_init__': <function Config.__attrs_post_init__>, '__weakref__': <attribute '__weakref__' of 'Config' objects>, '__doc__': None, 'get_paths': <function Config.get_paths>, 'resolve_path': <function Config.resolve_path>})
__init__(filename) → None
__module__ = 'labgrid.config'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

labgrid.consoleloggingreporter module

class labgrid.consoleloggingreporter.ConsoleLoggingReporter(logpath)[source]

Bases: object

ConsoleLoggingReporter - Reporter that writes console log files

Parameters:logpath (str) – path to store the logfiles in
instance = None
classmethod start(path)[source]

starts the ConsoleLoggingReporter

classmethod stop()[source]

stops the ConsoleLoggingReporter

__init__(logpath)[source]
get_logfile(event)[source]

Returns the correct file handle from cache or creates a new file handle

notify(event)[source]

This is the callback function for steps

__dict__ = mappingproxy({'__init__': <function ConsoleLoggingReporter.__init__>, '__dict__': <attribute '__dict__' of 'ConsoleLoggingReporter' objects>, 'notify': <function ConsoleLoggingReporter.notify>, '__doc__': 'ConsoleLoggingReporter - Reporter that writes console log files\n\n Args:\n logpath (str): path to store the logfiles in\n ', '__module__': 'labgrid.consoleloggingreporter', 'start': <classmethod object>, 'get_logfile': <function ConsoleLoggingReporter.get_logfile>, '_stop': <function ConsoleLoggingReporter._stop>, '__weakref__': <attribute '__weakref__' of 'ConsoleLoggingReporter' objects>, 'instance': None, 'stop': <classmethod object>})
__module__ = 'labgrid.consoleloggingreporter'
__weakref__

list of weak references to the object (if defined)

labgrid.environment module

class labgrid.environment.Environment(config_file='config.yaml', interact=<built-in function input>) → None[source]

Bases: object

An environment encapsulates targets.

__attrs_post_init__()[source]
get_target(role: str = 'main') → labgrid.target.Target[source]

Returns the specified target or None if not found.

Each target is initialized as needed.

get_features()[source]
get_target_features()[source]
cleanup()[source]
__attrs_attrs__ = (Attribute(name='config_file', default='config.yaml', validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='interact', default=<built-in function input>, validator=None, repr=False, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False))
__dict__ = mappingproxy({'__attrs_attrs__': (Attribute(name='config_file', default='config.yaml', validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='interact', default=<built-in function input>, validator=None, repr=False, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False)), '__init__': <function Environment.__init__>, '__dict__': <attribute '__dict__' of 'Environment' objects>, 'get_features': <function Environment.get_features>, '__repr__': <function Environment.__repr__>, 'cleanup': <function Environment.cleanup>, '__module__': 'labgrid.environment', '__doc__': 'An environment encapsulates targets.', 'get_target': <function Environment.get_target>, '__attrs_post_init__': <function Environment.__attrs_post_init__>, '__weakref__': <attribute '__weakref__' of 'Environment' objects>, 'get_target_features': <function Environment.get_target_features>})
__init__(config_file='config.yaml', interact=<built-in function input>) → None
__module__ = 'labgrid.environment'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

labgrid.exceptions module

exception labgrid.exceptions.NoConfigFoundError(msg) → None[source]

Bases: Exception

__attrs_attrs__ = (Attribute(name='msg', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False),)
__init__(msg) → None
__module__ = 'labgrid.exceptions'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

exception labgrid.exceptions.NoSupplierFoundError(msg, filter=None) → None[source]

Bases: Exception

__attrs_attrs__ = (Attribute(name='msg', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='filter', default=None, validator=<optional validator for <instance_of validator for type <class 'set'>> or None>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False))
__init__(msg, filter=None) → None
__module__ = 'labgrid.exceptions'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

exception labgrid.exceptions.InvalidConfigError(msg) → None[source]

Bases: Exception

__attrs_attrs__ = (Attribute(name='msg', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False),)
__init__(msg) → None
__module__ = 'labgrid.exceptions'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)

exception labgrid.exceptions.NoDriverFoundError(msg, filter=None) → None[source]

Bases: labgrid.exceptions.NoSupplierFoundError

__attrs_attrs__ = (Attribute(name='msg', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='filter', default=None, validator=<optional validator for <instance_of validator for type <class 'set'>> or None>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False))
__init__(msg, filter=None) → None
__module__ = 'labgrid.exceptions'
__repr__()

Automatically created by attrs.

exception labgrid.exceptions.NoResourceFoundError(msg, filter=None) → None[source]

Bases: labgrid.exceptions.NoSupplierFoundError

__attrs_attrs__ = (Attribute(name='msg', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='filter', default=None, validator=<optional validator for <instance_of validator for type <class 'set'>> or None>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False))
__init__(msg, filter=None) → None
__module__ = 'labgrid.exceptions'
__repr__()

Automatically created by attrs.

labgrid.factory module

class labgrid.factory.TargetFactory[source]

Bases: object

__init__()[source]
reg_resource(cls)[source]

Register a resource with the factory.

Returns the class to allow using it as a decorator.

reg_driver(cls)[source]

Register a driver with the factory.

Returns the class to allow using it as a decorator.

static normalize_config(config)[source]
make_resource(target, resource, name, args)[source]
make_driver(target, driver, name, args)[source]
make_target(name, config, *, env=None)[source]
__dict__ = mappingproxy({'normalize_config': <staticmethod object>, '__init__': <function TargetFactory.__init__>, '__dict__': <attribute '__dict__' of 'TargetFactory' objects>, 'reg_resource': <function TargetFactory.reg_resource>, '__doc__': None, 'make_target': <function TargetFactory.make_target>, 'make_driver': <function TargetFactory.make_driver>, 'reg_driver': <function TargetFactory.reg_driver>, '__weakref__': <attribute '__weakref__' of 'TargetFactory' objects>, '_convert_to_named_list': <staticmethod object>, '__module__': 'labgrid.factory', 'make_resource': <function TargetFactory.make_resource>})
__module__ = 'labgrid.factory'
__weakref__

list of weak references to the object (if defined)

labgrid.factory.target_factory = <labgrid.factory.TargetFactory object>

Global TargetFactory instance

This instance is used to register Resource and Driver classes so that Targets can be created automatically from YAML files.

labgrid.step module

class labgrid.step.Steps[source]

Bases: object

__init__()[source]
get_current()[source]
get_new(title, tag, source)[source]
push(step)[source]
pop(step)[source]
subscribe(callback)[source]
unsubscribe(callback)[source]
notify(event)[source]
__dict__ = mappingproxy({'subscribe': <function Steps.subscribe>, '__init__': <function Steps.__init__>, '__dict__': <attribute '__dict__' of 'Steps' objects>, 'notify': <function Steps.notify>, '__doc__': None, 'pop': <function Steps.pop>, '__module__': 'labgrid.step', 'get_current': <function Steps.get_current>, 'push': <function Steps.push>, 'get_new': <function Steps.get_new>, '__weakref__': <attribute '__weakref__' of 'Steps' objects>, 'unsubscribe': <function Steps.unsubscribe>})
__module__ = 'labgrid.step'
__weakref__

list of weak references to the object (if defined)

class labgrid.step.StepEvent(step, data, *, resource=None, stream=False)[source]

Bases: object

__init__(step, data, *, resource=None, stream=False)[source]
__str__()[source]
merge(other)[source]
age
__dict__ = mappingproxy({'age': <property object>, '_invalidate': <function StepEvent._invalidate>, '__init__': <function StepEvent.__init__>, '__dict__': <attribute '__dict__' of 'StepEvent' objects>, 'merge': <function StepEvent.merge>, '__str__': <function StepEvent.__str__>, '__module__': 'labgrid.step', '__doc__': None, '__weakref__': <attribute '__weakref__' of 'StepEvent' objects>})
__module__ = 'labgrid.step'
__weakref__

list of weak references to the object (if defined)

class labgrid.step.Step(title, level, tag, source)[source]

Bases: object

__init__(title, level, tag, source)[source]
__repr__()[source]
__str__()[source]
duration
status
is_active
is_done
start()[source]
skip(reason)[source]
stop()[source]
__del__()[source]
__dict__ = mappingproxy({'is_active': <property object>, '__init__': <function Step.__init__>, '_notify': <function Step._notify>, '__dict__': <attribute '__dict__' of 'Step' objects>, '__doc__': None, '__repr__': <function Step.__repr__>, '__str__': <function Step.__str__>, '__module__': 'labgrid.step', 'start': <function Step.start>, 'skip': <function Step.skip>, 'status': <property object>, 'duration': <property object>, '__weakref__': <attribute '__weakref__' of 'Step' objects>, 'is_done': <property object>, '__del__': <function Step.__del__>, 'stop': <function Step.stop>})
__module__ = 'labgrid.step'
__weakref__

list of weak references to the object (if defined)

labgrid.step.step(*, title=None, args=[], result=False, tag=None)[source]

labgrid.stepreporter module

class labgrid.stepreporter.StepReporter[source]

Bases: object

instance = None
classmethod start()[source]

starts the StepReporter

classmethod stop()[source]

stops the StepReporter

__init__()[source]
static notify(event)[source]
__dict__ = mappingproxy({'__weakref__': <attribute '__weakref__' of 'StepReporter' objects>, '__init__': <function StepReporter.__init__>, '__dict__': <attribute '__dict__' of 'StepReporter' objects>, 'notify': <staticmethod object>, '__doc__': None, '__module__': 'labgrid.stepreporter', 'start': <classmethod object>, 'instance': None, 'stop': <classmethod object>})
__module__ = 'labgrid.stepreporter'
__weakref__

list of weak references to the object (if defined)

labgrid.target module

class labgrid.target.Target(name, env=None) → None[source]

Bases: object

__attrs_post_init__()[source]
interact(msg)[source]
update_resources()[source]

Iterate over all relevant managers and deactivate any active but unavailable resources.

await_resources(resources, timeout=None, avail=True)[source]

Poll the given resources and wait until they are (un-)available.

Parameters:
  • resources (List) – the resources to poll
  • timeout (float) – optional timeout
  • avail (bool) – optionally wait until the resources are unavailable with avail=False
get_resource(cls, *, name=None, wait_avail=True)[source]

Helper function to get a resource of the target. Returns the first valid resource found, otherwise a NoResourceFoundError is raised.

Arguments: cls – resource-class to return as a resource name – optional name to use as a filter wait_avail – wait for the resource to become available (default True)

get_active_driver(cls, *, name=None)[source]

Helper function to get the active driver of the target. Returns the active driver found, otherwise None.

Arguments: cls – driver-class to return as a resource name – optional name to use as a filter

get_driver(cls, *, name=None, activate=True)[source]

Helper function to get a driver of the target. Returns the first valid driver found, otherwise None.

Arguments: cls – driver-class to return as a resource name – optional name to use as a filter activate – activate the driver (default True)

__getitem__(key)[source]

Syntactic sugar to access drivers by class (optionally filtered by name).

>>> target = Target('main')
>>> console = FakeConsoleDriver(target, 'console')
>>> target.activate(console)
>>> target[FakeConsoleDriver]
FakeConsoleDriver(target=Target(name='main', …), name='console', …)
>>> target[FakeConsoleDriver, 'console']
FakeConsoleDriver(target=Target(name='main', …), name='console', …)
set_binding_map(mapping)[source]

Configure the binding name mapping for the next driver only.

bind_resource(resource)[source]

Bind the resource to this target.

bind_driver(client)[source]

Bind the driver to all suppliers (resources and other drivers).

Currently, we only support binding all suppliers at once.

bind(bindable)[source]
activate(client)[source]

Activate the client by activating all bound suppliers. This may require deactivating other clients.

deactivate(client)[source]

Recursively deactivate the client’s clients and itself.

This is needed to ensure that no client has an inactive supplier.

deactivate_all_drivers()[source]

Deactivates all drivers in reversed order they were activated

cleanup()[source]

Clean up conntected drivers and resources in reversed order

__attrs_attrs__ = (Attribute(name='name', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='env', default=None, validator=None, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False))
__dict__ = mappingproxy({'await_resources': <function Target.await_resources>, '_class_from_string': <function Target._class_from_string>, '__doc__': None, '__getitem__': <function Target.__getitem__>, '__attrs_attrs__': (Attribute(name='name', default=NOTHING, validator=<instance_of validator for type <class 'str'>>, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False), Attribute(name='env', default=None, validator=None, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None, kw_only=False)), 'activate': <function Target.activate>, 'update_resources': <function Target.update_resources>, 'bind_driver': <function Target.bind_driver>, '__init__': <function Target.__init__>, 'interact': <function Target.interact>, '__attrs_post_init__': <function Target.__attrs_post_init__>, 'deactivate_all_drivers': <function Target.deactivate_all_drivers>, 'bind_resource': <function Target.bind_resource>, '__weakref__': <attribute '__weakref__' of 'Target' objects>, '_get_driver': <function Target._get_driver>, 'cleanup': <function Target.cleanup>, '__dict__': <attribute '__dict__' of 'Target' objects>, '__repr__': <function Target.__repr__>, '__module__': 'labgrid.target', 'set_binding_map': <function Target.set_binding_map>, 'get_active_driver': <function Target.get_active_driver>, 'get_resource': <function Target.get_resource>, 'get_driver': <function Target.get_driver>, 'deactivate': <function Target.deactivate>, 'bind': <function Target.bind>})
__init__(name, env=None) → None
__module__ = 'labgrid.target'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)