예제 #1
0
def test_parameters():
    def method1(arg: typing.Dict[str, typing.Dict[str, str]]):
        pass  # pragma: no cover

    def method2() -> typing.List[typing.List[DBusObject]]:
        pass  # pragma: no cover

    def method3(arg: typing.Dict[int, str]) -> typing.Dict[int, str]:
        pass  # pragma: no cover

    def method4(self, arg: typing.Dict[str, typing.Dict[str, str]]) -> int:
        pass  # pragma: no cover

    sig = DBusSignature(method1, 'method1', skip_first_argument=False)
    assert sig.input == 'a{sa{ss}}'
    assert sig.output == ''
    # assert sig.input_names == ['arg']

    sig = DBusSignature(method2, 'method2', skip_first_argument=False)
    assert sig.input == ''
    assert sig.output == 'aao'
    assert sig.input_names == []

    sig = DBusSignature(method3, 'method3', skip_first_argument=False)
    assert sig.input == 'a{is}'
    assert sig.output == 'a{is}'
    # assert sig.input_names == ['arg']

    sig = DBusSignature(method4,
                        'method4',
                        skip_first_argument=True,
                        return_names=['ret'])
    assert sig.input == 'a{sa{ss}}'
    assert sig.output == 'i'
    assert sig.input_names == ['arg']
예제 #2
0
def test_dbus_case(input, output):
    def method() -> None:
        pass  # pragma: no cover

    method_sig = DBusSignature(method, input, skip_first_argument=False)

    assert method_sig.name == output
예제 #3
0
def test_signature(subtests, types, signature):
    def method() -> types:
        pass  # pragma: no cover

    method_sig = DBusSignature.from_return(method)

    assert str(method_sig) == signature
예제 #4
0
def test_signature(subtests, types, signature):
    def method() -> types:
        pass  # pragma: no cover

    method_sig = DBusSignature(method, 'method', skip_first_argument=False)

    with subtests.test(msg='DBus signature'):
        assert method_sig.output == signature

    with subtests.test(msg='DBus signature'):
        assert (
            ET.tostring(method_sig.xml).decode() ==
            f'<method name="Method"><arg direction="out" type="{signature}" /></method>'
        )
예제 #5
0
def test_parameters():
    def method1(arg: typing.Dict[str, typing.Dict[str, str]]):
        pass  # pragma: no cover

    def method2() -> typing.List[typing.List[DBusObject]]:
        pass  # pragma: no cover

    def method3(arg: typing.Dict[int, str]) -> typing.Dict[int, str]:
        pass  # pragma: no cover

    def method4(self, arg: typing.Dict[str, typing.Dict[str, str]]) -> int:
        pass  # pragma: no cover

    in_sig = DBusSignature.from_parameters(method1, skip_first_argument=False)
    out_sig = DBusSignature.from_return(method1)
    assert str(in_sig) == 'a{sa{ss}}'
    assert str(out_sig) == ''
    # assert in_sig.names == ['arg']

    in_sig = DBusSignature.from_parameters(method2)
    out_sig = DBusSignature.from_return(method2)
    assert str(in_sig) == ''
    assert str(out_sig) == 'aao'
    assert in_sig.names == []

    in_sig = DBusSignature.from_parameters(method3, skip_first_argument=False)
    out_sig = DBusSignature.from_return(method3)
    assert str(in_sig) == 'a{is}'
    assert str(out_sig) == 'a{is}'
    assert in_sig.names == ['arg']

    in_sig = DBusSignature.from_parameters(method4)
    out_sig = DBusSignature.from_return(method4, return_names=['ret'])
    assert str(in_sig) == 'a{sa{ss}}'
    assert str(out_sig) == 'i'
    assert in_sig.names == ['arg']
예제 #6
0
def test_signature_error():
    with pytest.raises(DBusObjectException):
        DBusSignature._type_signature(complex)
예제 #7
0
def test_get_dbus_sigature_no_annotations():
    def method(arg):
        pass  # pragma: no cover

    with pytest.raises(DBusObjectException):
        DBusSignature(method, 'method', skip_first_argument=False)