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),)
__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),)
__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({'__weakref__': <attribute '__weakref__' of 'NamedBinding' objects>, '__repr__': <function BindingMixin.NamedBinding.__repr__>, '__init__': <function BindingMixin.NamedBinding.__init__>, '__module__': 'labgrid.binding', '__dict__': <attribute '__dict__' of 'NamedBinding' objects>, '__doc__': '\n Marks a binding (or binding set) as requiring an explicit name.\n '})
__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), 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), Attribute(name='state', default=<BindingState.idle: 0>, validator=None, repr=True, cmp=True, hash=None, init=False, metadata=mappingproxy({}), type=None, converter=None))
__dict__ = mappingproxy({'__init__': <function BindingMixin.__init__>, '__module__': 'labgrid.binding', '__attrs_attrs__': (Attribute(name='target', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None), 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), Attribute(name='state', default=<BindingState.idle: 0>, validator=None, repr=True, cmp=True, hash=None, init=False, metadata=mappingproxy({}), type=None, converter=None)), 'bindings': {}, 'on_client_bound': <function BindingMixin.on_client_bound>, '__attrs_post_init__': <function BindingMixin.__attrs_post_init__>, 'display_name': <property object>, 'on_activate': <function BindingMixin.on_activate>, 'on_supplier_bound': <function BindingMixin.on_supplier_bound>, 'check_active': <classmethod object>, '__weakref__': <attribute '__weakref__' of 'BindingMixin' objects>, '__repr__': <function BindingMixin.__repr__>, 'NamedBinding': <class 'labgrid.binding.BindingMixin.NamedBinding'>, 'on_deactivate': <function BindingMixin.on_deactivate>, '__dict__': <attribute '__dict__' of 'BindingMixin' objects>, '__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 ', 'resolve_conflicts': <function BindingMixin.resolve_conflicts>})
__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
__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),)
__dict__ = mappingproxy({'__weakref__': <attribute '__weakref__' of 'Config' objects>, '__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),), 'get_images': <function Config.get_images>, '__module__': 'labgrid.config', '__repr__': <function Config.__repr__>, 'get_targets': <function Config.get_targets>, 'set_option': <function Config.set_option>, 'get_tool': <function Config.get_tool>, 'get_paths': <function Config.get_paths>, 'resolve_path': <function Config.resolve_path>, '__init__': <function Config.__init__>, '__doc__': None, '__attrs_post_init__': <function Config.__attrs_post_init__>, 'get_imports': <function Config.get_imports>, 'get_option': <function Config.get_option>, 'get_image_path': <function Config.get_image_path>, 'get_path': <function Config.get_path>, '__dict__': <attribute '__dict__' of 'Config' objects>})
__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({'__weakref__': <attribute '__weakref__' of 'ConsoleLoggingReporter' objects>, 'instance': None, '__init__': <function ConsoleLoggingReporter.__init__>, '__module__': 'labgrid.consoleloggingreporter', '__dict__': <attribute '__dict__' of 'ConsoleLoggingReporter' objects>, 'notify': <function ConsoleLoggingReporter.notify>, 'start': <classmethod object>, 'get_logfile': <function ConsoleLoggingReporter.get_logfile>, 'stop': <classmethod object>, '__doc__': 'ConsoleLoggingReporter - Reporter that writes console log files\n\n Args:\n logpath (str): path to store the logfiles in\n ', '_stop': <function ConsoleLoggingReporter._stop>})
__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.

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), Attribute(name='interact', default=<built-in function input>, validator=None, repr=False, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None))
__dict__ = mappingproxy({'__weakref__': <attribute '__weakref__' of 'Environment' objects>, '__init__': <function Environment.__init__>, '__module__': 'labgrid.environment', '__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), Attribute(name='interact', default=<built-in function input>, validator=None, repr=False, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None)), '__dict__': <attribute '__dict__' of 'Environment' objects>, 'get_target': <function Environment.get_target>, '__repr__': <function Environment.__repr__>, 'cleanup': <function Environment.cleanup>, '__attrs_post_init__': <function Environment.__attrs_post_init__>, '__doc__': 'An environment encapsulates targets.'})
__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),)
__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), 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))
__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),)
__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), 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))
__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), 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))
__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({'__weakref__': <attribute '__weakref__' of 'TargetFactory' objects>, '__init__': <function TargetFactory.__init__>, '__module__': 'labgrid.factory', '__dict__': <attribute '__dict__' of 'TargetFactory' objects>, 'reg_resource': <function TargetFactory.reg_resource>, 'make_target': <function TargetFactory.make_target>, 'make_resource': <function TargetFactory.make_resource>, 'normalize_config': <staticmethod object>, '_convert_to_named_list': <staticmethod object>, 'reg_driver': <function TargetFactory.reg_driver>, 'make_driver': <function TargetFactory.make_driver>, '__doc__': None})
__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({'get_new': <function Steps.get_new>, '__weakref__': <attribute '__weakref__' of 'Steps' objects>, 'subscribe': <function Steps.subscribe>, '__init__': <function Steps.__init__>, '__module__': 'labgrid.step', '__dict__': <attribute '__dict__' of 'Steps' objects>, 'push': <function Steps.push>, 'notify': <function Steps.notify>, 'get_current': <function Steps.get_current>, 'pop': <function Steps.pop>, '__doc__': None, '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({'__weakref__': <attribute '__weakref__' of 'StepEvent' objects>, '__dict__': <attribute '__dict__' of 'StepEvent' objects>, '__init__': <function StepEvent.__init__>, '__module__': 'labgrid.step', 'merge': <function StepEvent.merge>, '_invalidate': <function StepEvent._invalidate>, '__str__': <function StepEvent.__str__>, '__doc__': None, 'age': <property object>})
__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({'__weakref__': <attribute '__weakref__' of 'Step' objects>, '__init__': <function Step.__init__>, '__module__': 'labgrid.step', 'is_active': <property object>, '_notify': <function Step._notify>, '__dict__': <attribute '__dict__' of 'Step' objects>, '__str__': <function Step.__str__>, 'skip': <function Step.skip>, 'status': <property object>, '__del__': <function Step.__del__>, 'start': <function Step.start>, '__repr__': <function Step.__repr__>, 'is_done': <property object>, 'duration': <property object>, 'stop': <function Step.stop>, '__doc__': None})
__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({'start': <classmethod object>, '__weakref__': <attribute '__weakref__' of 'StepReporter' objects>, 'instance': None, '__init__': <function StepReporter.__init__>, 'stop': <classmethod object>, '__dict__': <attribute '__dict__' of 'StepReporter' objects>, '__module__': 'labgrid.stepreporter', 'notify': <staticmethod object>, '__doc__': None})
__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 None.

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.

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), Attribute(name='env', default=None, validator=None, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None))
__dict__ = mappingproxy({'await_resources': <function Target.await_resources>, '__init__': <function Target.__init__>, '__module__': 'labgrid.target', 'activate': <function Target.activate>, 'deactivate': <function Target.deactivate>, '__attrs_post_init__': <function Target.__attrs_post_init__>, 'get_driver': <function Target.get_driver>, '_get_driver': <function Target._get_driver>, 'update_resources': <function Target.update_resources>, 'get_active_driver': <function Target.get_active_driver>, '__getitem__': <function Target.__getitem__>, 'interact': <function Target.interact>, '__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), Attribute(name='env', default=None, validator=None, repr=True, cmp=True, hash=None, init=True, metadata=mappingproxy({}), type=None, converter=None)), '__weakref__': <attribute '__weakref__' of 'Target' objects>, '__dict__': <attribute '__dict__' of 'Target' objects>, 'set_binding_map': <function Target.set_binding_map>, '__repr__': <function Target.__repr__>, 'bind_resource': <function Target.bind_resource>, 'cleanup': <function Target.cleanup>, 'bind': <function Target.bind>, 'get_resource': <function Target.get_resource>, '__doc__': None, '_class_from_string': <function Target._class_from_string>, 'bind_driver': <function Target.bind_driver>})
__init__(name, env=None) → None
__module__ = 'labgrid.target'
__repr__()

Automatically created by attrs.

__weakref__

list of weak references to the object (if defined)