Пример #1
0
 def test_connecting_to_missing_socket_raises_file_not_found_error(self) -> None:
     with tempfile.TemporaryDirectory() as temporary_directory:
         socket_path = pathlib.Path(temporary_directory) / "test_socket"
         dbus = DBusAddress(self.dbus_address_from_unix_socket_path(socket_path))
         with self.assertRaises(DBusFileNotFoundError) as expectation:
             dbus.open()
         self.assertEqual(expectation.exception.errno, -errno.ENOENT)
Пример #2
0
    def test_connecting_to_serverless_socket_raises_connection_refused_error(
        self
    ) -> None:
        with tempfile.TemporaryDirectory() as temporary_directory:
            socket_path = pathlib.Path(temporary_directory) / "test_socket"
            with socket.socket(
                family=socket.AF_UNIX, type=socket.SOCK_STREAM
            ) as server:
                server.bind(bytes(socket_path))

                dbus = DBusAddress(self.dbus_address_from_unix_socket_path(socket_path))
                with self.assertRaises(DBusConnectionRefusedError) as expectation:
                    dbus.open()
                self.assertEqual(expectation.exception.errno, -errno.ECONNREFUSED)
Пример #3
0
 def bus_factory():
     if address:
         return DBusAddress(x2char_star(address))
     elif machine:
         return DBusMachine(x2char_star(machine))
     else:
         return DBus(user_mode=user_mode)