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)
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)
def bus_factory(): if address: return DBusAddress(x2char_star(address)) elif machine: return DBusMachine(x2char_star(machine)) else: return DBus(user_mode=user_mode)