Skip to content
Permalink
Browse files

target: make sure drivers consume all given bindings

This helps discovering errors in complex yaml configs.

Signed-off-by: Bastian Krause <bst@pengutronix.de>
  • Loading branch information
Bastian-Krause authored and jluebbe committed Nov 21, 2019
1 parent b6a8c41 commit cb33052d733879e9c940e0f9cb430b138400d622
Showing with 15 additions and 1 deletion.
  1. +7 −1 labgrid/target.py
  2. +8 −0 tests/test_target.py
@@ -292,7 +292,7 @@ def bind_driver(self, client):
if isinstance(requirements, Driver.NamedBinding):
requirements = requirements.value
explicit = True
supplier_name = mapping.get(name)
supplier_name = mapping.pop(name, None)
if explicit and supplier_name is None:
raise BindingError(
"supplier for {} ({}) of {} in target {} requires an explicit name".format(
@@ -356,6 +356,12 @@ def bind_driver(self, client):
"duplicate bindings {} found in target {}".format(duplicates, self)
)

# make sure drivers consume all given bindings
if mapping and not isinstance(client, Strategy):
raise BindingError(
"{} got unexpected bindings: {}".format(client, list(mapping.keys()))
)

# update relationship in both directions
self.drivers.append(client)
# update lookup table
@@ -134,6 +134,14 @@ def test_suppliers_ab_missing(target):
d = DriverWithAB(target, "driver")


def test_suppliers_unexpected_binding(target):
ra = ResourceA(target, "resource")
target.set_binding_map({"res": "resource", "unexpected": "foo"})
with pytest.raises(BindingError) as excinfo:
DriverWithA(target, "driver")
assert "got unexpected bindings" in excinfo.value.msg


class DriverWithNamedA(Driver):
bindings = {
"res": Driver.NamedBinding(ResourceA),

0 comments on commit cb33052

Please sign in to comment.
You can’t perform that action at this time.