Пример #1
0
    def test_get_proxy(self):
        """Test getting a proxy."""
        bus = Mock()
        namespace = ("a", "b", "c")

        service = DBusServiceIdentifier(namespace=namespace, message_bus=bus)

        obj = DBusObjectIdentifier(basename="object", namespace=namespace)

        service.get_proxy()
        bus.get_proxy.assert_called_with("a.b.c", "/a/b/c")
        bus.reset_mock()

        service.get_proxy(obj.object_path)
        bus.get_proxy.assert_called_with("a.b.c", "/a/b/c/object")
        bus.reset_mock()
Пример #2
0
    def test_get_proxy_for_interface(self):
        """Test getting a proxy for an interface."""
        bus = Mock()
        namespace = ("a", "b", "c")

        service = DBusServiceIdentifier(namespace=namespace, message_bus=bus)

        interface = DBusInterfaceIdentifier(basename="interface",
                                            namespace=namespace)

        service.get_proxy(interface_name="a.b.c.interface")
        bus.get_proxy.assert_called_with("a.b.c", "/a/b/c", "a.b.c.interface")
        bus.reset_mock()

        service.get_proxy(interface_name=interface)
        bus.get_proxy.assert_called_with("a.b.c", "/a/b/c", "a.b.c.interface")
        bus.reset_mock()
Пример #3
0
    def test_get_proxy_with_bus_arguments(self):
        """Test getting a proxy with an additional arguments."""
        bus = Mock()
        error_mapper = Mock()
        namespace = ("a", "b", "c")

        service = DBusServiceIdentifier(namespace=namespace, message_bus=bus)

        service.get_proxy(error_mapper=error_mapper)
        bus.get_proxy.assert_called_with("a.b.c",
                                         "/a/b/c",
                                         None,
                                         error_mapper=error_mapper)
        bus.reset_mock()

        service.get_proxy(interface_name=service, error_mapper=error_mapper)
        bus.get_proxy.assert_called_with("a.b.c",
                                         "/a/b/c",
                                         "a.b.c",
                                         error_mapper=error_mapper)
        bus.reset_mock()
Пример #4
0
#
# Show the current hostname.
#
from dasbus.connection import SystemMessageBus
from dasbus.identifier import DBusServiceIdentifier

# Define the message bus.
SYSTEM_BUS = SystemMessageBus()

# Define services and objects.
HOSTNAME = DBusServiceIdentifier(namespace=("org", "freedesktop", "hostname"),
                                 service_version=1,
                                 object_version=1,
                                 interface_version=1,
                                 message_bus=SYSTEM_BUS)

if __name__ == "__main__":
    # Create a proxy of the object /org/freedesktop/hostname1
    # provided by the service org.freedesktop.hostname1.
    proxy = HOSTNAME.get_proxy()

    # Print a value of the DBus property Hostname.
    print(proxy.Hostname)