async def test_auto_update(skip_qtbot, qapp): # Setup update_mock = AsyncMock() backend = MagicMock() game_connection = GameConnection(backend) game_connection._notify_status = MagicMock() game_connection.update = update_mock # Run await game_connection._auto_update() # Assert update_mock.assert_awaited_once_with(game_connection._dt) game_connection._notify_status.assert_called_once_with()
async def qt_main(app: QtWidgets.QApplication, data_dir: Path, args): app.network_client = None logging.info("Loading server client...") from randovania.gui.lib.qt_network_client import QtNetworkClient logging.info("Configuring server client...") app.network_client = QtNetworkClient(data_dir) logging.info("Server client ready.") options = _load_options() backend = create_backend(args.debug_game_backend, options) logging.info("Configuring game connection with the backend...") from randovania.game_connection.game_connection import GameConnection app.game_connection = GameConnection(backend) logging.info("Configuring qasync...") import qasync @qasync.asyncClose async def _on_last_window_closed(): await app.network_client.disconnect_from_server() await app.game_connection.stop() logger.info("Last QT window closed") app.lastWindowClosed.connect(_on_last_window_closed, QtCore.Qt.QueuedConnection) await asyncio.gather(app.game_connection.start(), display_window_for(app, options, args.command, args))
def _setup(skip_qtbot): parent = QtWidgets.QWidget() skip_qtbot.addWidget(parent) tool = QtWidgets.QToolButton(parent) label = QtWidgets.QLabel(parent) return GameConnectionSetup(parent, tool, label, GameConnection(DolphinBackend()), MagicMock())
async def test_update(skip_qtbot, qapp): # Setup backend_update = AsyncMock() backend = MagicMock() backend.update = backend_update game_connection = GameConnection(backend) game_connection._notify_status = MagicMock() # Run await game_connection._update() # Assert backend_update.assert_awaited_once_with(game_connection._dt) game_connection._notify_status.assert_called_once_with()
def test_pretty_current_status(skip_qtbot): # Setup connection = GameConnection(DolphinExecutor()) # Run result = connection.pretty_current_status # Assert assert result == f"Dolphin: Disconnected"
async def test_update(skip_qtbot, qapp): # Setup backend_update = AsyncMock() game_connection = GameConnection() game_connection._connection_status = ConnectionStatus.Disconnected game_connection.StatusUpdated = MagicMock() # game_connection.backend = MagicMock() game_connection.backend.update = backend_update game_connection.backend.current_status = ConnectionStatus.InGame # Run await game_connection._update() # Assert backend_update.assert_awaited_once_with(1.0) game_connection.StatusUpdated.emit.assert_called_once_with(ConnectionStatus.InGame)
def _setup(skip_qtbot): parent = QtWidgets.QWidget() skip_qtbot.addWidget(parent) tool = QtWidgets.QToolButton(parent) label = QtWidgets.QLabel(parent) result = GameConnectionSetup(parent, label, GameConnection(DolphinExecutor()), MagicMock()) result.setup_tool_button_menu(tool) return result
async def worker(app: QCoreApplication, backend: ConnectionBackend): connection = GameConnection(backend) await connection.start() try: while connection.current_status not in (GameConnectionStatus.InGame, GameConnectionStatus.TrackerOnly): await asyncio.sleep(1) print(connection.pretty_current_status) await asyncio.sleep(20) except KeyboardInterrupt: return finally: await connection.stop()
async def qt_main(app: QtWidgets.QApplication, data_dir: Path, args): app.setQuitOnLastWindowClosed(False) app.network_client = None logging.info("Loading server client...") from randovania.gui.lib.qt_network_client import QtNetworkClient logging.info("Configuring server client...") app.network_client = QtNetworkClient(data_dir) logging.info("Server client ready.") if args.login_as_guest: logging.info("Logging as %s", args.login_as_guest) await app.network_client.login_as_guest(args.login_as_guest) options = await _load_options() if options is None: app.exit(1) return executor = create_memory_executor(args.debug_game_backend, options) logging.info("Configuring game connection with the backend...") from randovania.game_connection.game_connection import GameConnection app.game_connection = GameConnection(executor) logging.info("Configuring qasync...") import qasync @qasync.asyncClose async def _on_last_window_closed(): if app.quitOnLastWindowClosed(): await app.network_client.disconnect_from_server() await app.game_connection.stop() logger.info("Last QT window closed") else: logger.warning( "Last Qt window closed, but currently not doing anything") app.setQuitOnLastWindowClosed(True) app.lastWindowClosed.connect(_on_last_window_closed, QtCore.Qt.QueuedConnection) await asyncio.gather(app.game_connection.start(), display_window_for(app, options, args.command, args))
async def worker(app: QCoreApplication): connection = GameConnection(DolphinBackend()) await connection.start() try: while connection.current_status != GameConnectionStatus.InGame: await asyncio.sleep(1) print(connection.pretty_current_status) await connection.display_message("Hello Samus.") await connection.display_message( "I see you are trying to do a multiworld.") await connection.display_message("But are you authorized for that?") await asyncio.sleep(20) except KeyboardInterrupt: return finally: await connection.stop()
async def qt_main(app: QApplication, data_dir: Path, args): from randovania.gui.lib.qt_network_client import QtNetworkClient from randovania.game_connection.game_connection import GameConnection app.network_client = QtNetworkClient(data_dir) backend = create_backend(args.debug_game_backend) app.game_connection = GameConnection(backend) @asyncClose async def _on_last_window_closed(): await app.network_client.disconnect_from_server() await app.game_connection.stop() app.lastWindowClosed.connect(_on_last_window_closed, QtCore.Qt.QueuedConnection) options = _load_options() await asyncio.gather(app.game_connection.start(), display_window_for(app, options, args.command, args))
def run(args): QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True) app = QApplication(sys.argv) preview: bool = getattr(args, "preview", False) os.environ['QT_API'] = "PySide2" import asyncqt loop = asyncqt.QEventLoop(app) asyncio.set_event_loop(loop) sys.excepthook = catch_exceptions app.game_connection = GameConnection() if getattr(args, "debug_game_backend", False): backend = DebugBackendWindow() backend.show() else: backend = DolphinBackend() app.game_connection.set_backend(backend) @asyncClose async def _on_last_window_closed(): await app.game_connection.stop() app.lastWindowClosed.connect(_on_last_window_closed, Qt.QueuedConnection) target_window = getattr(args, "window", None) if target_window == "data-editor": show_data_editor(app) elif target_window == "tracker": show_tracker(app) else: show_main_window(app, preview) with loop: loop.create_task(app.game_connection.start()) sys.exit(loop.run_forever())
async def qt_main(app: QtWidgets.QApplication, data_dir: Path, args): from randovania.gui.lib.qt_network_client import QtNetworkClient from randovania.game_connection.game_connection import GameConnection app.network_client = QtNetworkClient(data_dir) options = _load_options() backend = create_backend(args.debug_game_backend, options) app.game_connection = GameConnection(backend) app.game_connection.tracking_inventory = options.tracking_inventory app.game_connection.displaying_messages = options.displaying_messages @asyncClose async def _on_last_window_closed(): await app.network_client.disconnect_from_server() await app.game_connection.stop() logger.info("Last QT window closed") app.lastWindowClosed.connect(_on_last_window_closed, QtCore.Qt.QueuedConnection) await asyncio.gather(app.game_connection.start(), display_window_for(app, options, args.command, args))
async def test_set_backend(skip_qtbot): # Setup backend1 = ConnectionBackend() backend2 = ConnectionBackend() game_connection = GameConnection(backend1) listener = AsyncMock() game_connection.set_location_collected_listener(listener) # Run await backend1._emit_location_collected(5) await backend2._emit_location_collected(6) game_connection.set_backend(backend2) await backend1._emit_location_collected(7) await backend2._emit_location_collected(8) # Assert listener.assert_has_awaits([call(5), call(8)])
def test_set_backend(skip_qtbot): # Setup game_connection = GameConnection() backend1 = ConnectionBackend() backend2 = ConnectionBackend() listener = MagicMock() game_connection.LocationCollected.connect(listener) # Run game_connection.set_backend(backend1) backend1.LocationCollected.emit(5) backend2.LocationCollected.emit(6) game_connection.set_backend(backend2) backend1.LocationCollected.emit(7) backend2.LocationCollected.emit(8) # Assert listener.assert_has_calls([call(5), call(8)])
def _connection(skip_qtbot): return GameConnection(MagicMock())