Exemple #1
0
class BasicTestSchema(DBusSchema):
    cls = BasicTestObj

    int_field = Int32()
    uint_field = UInt32()
    str_field = Str()
    nested_field = Nested(NestedTestSchema)
    list_field = List(Str())
    tuple_field = Tuple((Int32(), Str()))
Exemple #2
0
class BasicTestObj:
    int_field = attr.ib(metadata={DBUS_FIELD: Int32()})
    uint_field = attr.ib(metadata={DBUS_FIELD: UInt32()})
    str_field = attr.ib(metadata={DBUS_FIELD: Str()})
    nested_field = attr.ib(metadata={DBUS_NESTED: NestedTestObj})

    # TODO: Support nested attrs classes, ie List(NestedTestObj)
    list_field = attr.ib(metadata={DBUS_FIELD: List(Str())})
    tuple_field = attr.ib(metadata={DBUS_FIELD: Tuple((Int32(), Str()))})
Exemple #3
0
class WrappedFieldTestSchema(WrappedFieldSchema):
    cls = WrappedField
    wrapped_field = Str()
Exemple #4
0
class NestedTestSchema(DBusSchema):
    cls = NestedTestObj
    str_field = Str()
Exemple #5
0
class NestedTestObj:
    str_field = attr.ib(metadata={DBUS_FIELD: Str()})
Exemple #6
0
basic_test_signature = "(ius(s)as(is))"

basic_test_dump = [3, 5, "foo", ["bar"], ["baz", "quux"], (7, "moo")]


@pytest.mark.parametrize(
    "schema", [BasicTestSchema(), from_attrs(BasicTestObj)])
def test_base_schema(schema):
    assert schema.dump(basic_test_obj) == basic_test_dump
    assert schema.load(basic_test_dump) == basic_test_obj
    assert schema_signature(schema) == basic_test_signature


wrapped_field = "hello"
wrapped_field_signature = "s"


class WrappedFieldTestSchema(WrappedFieldSchema):
    cls = WrappedField
    wrapped_field = Str()


wrapped_field_schema = WrappedFieldTestSchema()


@pytest.mark.parametrize("schema", [wrapped_field_schema, from_field(Str())])
def test_singleton_schema(schema):
    assert schema.dump(wrapped_field) == wrapped_field
    assert schema.load(wrapped_field) == wrapped_field
    assert schema_signature(schema) == "s"
Exemple #7
0
class NestedContainer:
    list_of = dbus_attr(List(SimpleContainer))
    dict_of = dbus_attr(Dict(Str(), SimpleContainer))
Exemple #8
0
class SimpleContainer:
    some_str = dbus_attr(Str())
    some_int32 = dbus_attr(Int32())
    some_list = dbus_attr(List(Str()))
    some_dict = dbus_attr(Dict(Str(), Int32()))
Exemple #9
0
    False,
    recently_dumped,
    ages_ago_dumped,
    ages_ago_dumped,
    config_dumped,
    executor_empty_dumped,
    executor_some_dumped,
]

session_signature = f"(bxxx{config_signature}{executor_signature}{executor_signature})"


@pytest.mark.parametrize(
    "type_,dumped,loaded,sig",
    [
        (Str(), "hello", "hello", "s"),
        (List(Str()), ["hello"], ["hello"], "as"),
        (Dict(Str(), Int32()), dict(foo=1, bar=2), dict(foo=1,
                                                        bar=2), "a{si}"),
        (
            SimpleContainer,
            simple_container_dumped,
            simple_container_loaded,
            "(siasa{si})",
        ),
        (
            NestedContainer,
            nested_container_dumped,
            nested_container_loaded,
            "(a(siasa{si})a{s(siasa{si})})",
        ),