How to use labgrid - 10 common examples

To help you get started, we’ve selected a few labgrid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github labgrid-project / labgrid / tests / test_environment.py View on Github external
def test_instance_invalid_yaml(self, tmpdir):
        p = tmpdir.join("config.yaml")
        p.write(
            """
        I a(m) no yaml:
          - keks
          cookie
        """
        )
        with pytest.raises(InvalidConfigError):
            e = Environment(str(p))
github labgrid-project / labgrid / tests / test_timeout.py View on Github external
def test_create(self):
        t = Timeout()
        assert (isinstance(t, Timeout))
        t = Timeout(5.0)
        assert (isinstance(t, Timeout))
        with pytest.raises(TypeError):
            t = Timeout(10)
        with pytest.raises(ValueError):
            t = Timeout(-1.0)
github labgrid-project / labgrid / tests / test_timeout.py View on Github external
def test_create(self):
        t = Timeout()
        assert (isinstance(t, Timeout))
        t = Timeout(5.0)
        assert (isinstance(t, Timeout))
        with pytest.raises(TypeError):
            t = Timeout(10)
        with pytest.raises(ValueError):
            t = Timeout(-1.0)
github labgrid-project / labgrid / tests / test_timeout.py View on Github external
def test_create(self):
        t = Timeout()
        assert (isinstance(t, Timeout))
        t = Timeout(5.0)
        assert (isinstance(t, Timeout))
        with pytest.raises(TypeError):
            t = Timeout(10)
        with pytest.raises(ValueError):
            t = Timeout(-1.0)
github labgrid-project / labgrid / tests / test_target.py View on Github external
pass


class ResourceB(Resource):
    pass


class DriverWithA(Driver):
    bindings = {"res": ResourceA}


class DriverWithASet(Driver):
    bindings = {"res": {ResourceA}, }


class DriverWithAB(Driver):
    bindings = {"res": {ResourceA, ResourceB}, }


def test_suppliers_a(target):
    ra = ResourceA(target, "resource")
    d = DriverWithA(target, "resource")
    assert d.res is ra


def test_suppliers_aset(target):
    ra = ResourceA(target, "resource")
    d = DriverWithASet(target, "driver")
    assert d.res is ra


def test_suppliers_ab_a(target):
github labgrid-project / labgrid / tests / test_target.py View on Github external
class DriverWithNamedA(Driver):
    bindings = {
        "res": Driver.NamedBinding(ResourceA),
    }


def test_suppliers_named_a(target):
    ra = ResourceA(target, "resource")
    target.set_binding_map({"res": "resource"})
    d = DriverWithNamedA(target, "driver")
    assert d.res is ra


class DriverWithMultiA(Driver):
    bindings = {
        "res1": ResourceA,
        "res2": ResourceA,
    }


def test_suppliers_multi_a(target):
    ra1 = ResourceA(target, "resource1")
    with pytest.raises(BindingError) as excinfo:
        DriverWithMultiA(target, "driver")
    assert "duplicate bindings" in excinfo.value.msg


def test_suppliers_multi_a_explict(target):
    ra1 = ResourceA(target, "resource1")
    ra2 = ResourceA(target, "resource2")
github labgrid-project / labgrid / tests / test_target.py View on Github external
def test_getitem(target):
    class AProtocol(abc.ABC):
        pass

    class A(Driver, AProtocol):
        pass

    class B(Driver):
        pass

    a = A(target, "adriver")
    target.activate(a)
    assert isinstance(target[A], A)
    assert target[A] is a
    assert target[AProtocol] is a
    assert target[A, "adriver"] is a
    assert target[AProtocol, "adriver"] is a
    with pytest.raises(NoDriverFoundError) as excinfo:
        target[A, "bdriver"]
    assert "matching resources with other names" in excinfo.value.msg
    with pytest.raises(NoDriverFoundError) as excinfo:
        target[B, "adriver"]
    assert re.match("no active .*? driver named '{}' found in Target".format(a.name),
                    excinfo.value.msg)
github labgrid-project / labgrid / tests / test_target.py View on Github external
assert "duplicate bindings" in excinfo.value.msg


def test_suppliers_multi_a_explict(target):
    ra1 = ResourceA(target, "resource1")
    ra2 = ResourceA(target, "resource2")
    target.set_binding_map({
        "res1": "resource1",
        "res2": "resource2",
    })
    d = DriverWithMultiA(target, "driver")
    assert d.res1 is ra1
    assert d.res2 is ra2


class DriverWithNamedMultiA(Driver):
    bindings = {
        "res1": Driver.NamedBinding(ResourceA),
        "res2": Driver.NamedBinding(ResourceA),
    }


def test_suppliers_multi_named_a(target):
    ra1 = ResourceA(target, "resource1")
    ra2 = ResourceA(target, "resource2")
    target.set_binding_map({
        "res1": "resource1",
        "res2": "resource2",
    })
    d = DriverWithNamedMultiA(target, "driver")
    assert d.res1 is ra1
    assert d.res2 is ra2
github labgrid-project / labgrid / tests / test_target.py View on Github external
def test_suppliers_multi_named_a(target):
    ra1 = ResourceA(target, "resource1")
    ra2 = ResourceA(target, "resource2")
    target.set_binding_map({
        "res1": "resource1",
        "res2": "resource2",
    })
    d = DriverWithNamedMultiA(target, "driver")
    assert d.res1 is ra1
    assert d.res2 is ra2


# test optional bindings

class DriverWithOptionalA(Driver):
    bindings = {"res": {ResourceA, None}, }


class DriverWithOptionalAB(Driver):
    bindings = {"res": {ResourceA, ResourceB, None}, }


def test_suppliers_optional_a(target):
    ra = ResourceA(target, "resource")
    d = DriverWithOptionalA(target, "driver")
    assert d.res is ra


def test_suppliers_optional_a_missing(target):
    rb = ResourceB(target, "resource")
    d = DriverWithOptionalA(target, "driver")
github labgrid-project / labgrid / tests / test_target.py View on Github external
def test_suppliers_ab_missing(target):
    with pytest.raises(NoSupplierFoundError):
        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),
    }


def test_suppliers_named_a(target):
    ra = ResourceA(target, "resource")
    target.set_binding_map({"res": "resource"})
    d = DriverWithNamedA(target, "driver")
    assert d.res is ra


class DriverWithMultiA(Driver):
    bindings = {
        "res1": ResourceA,
        "res2": ResourceA,