Improve game lobby simulation in tests
- Vorherrschende Sprache
- Python
- Sterne
- 72
- Forks
- 84
- Ø Merge
- 5 Std. 11 Min.
- Gemergte PRs (30 T.)
- 1
Beschreibung
There are a lot of commands that the game will send during lobby setup and also throughout the course of the game that are currently skipped in the tests because it's annoying to write that many `send_message` commands especially for commands that don't seem to be directly relevant for the current test. However, I already had it happen once that one of my tests therefore failed to catch a bug when I changed an interaction in one of these messages that it was skipping.
I suggest we add a class that wraps a `Protocol` instance and supplies a few helper methods like:
```python3
class TestFAClient():
def __init__(self, proto: Protocol, player_id: int, *other_needed_args):
...
async def open(self):
"FA process start up"
async def close(self):
"FA process graceful termination"
async def host(self):
"Game lobby set up by host"
async def set_game_option(self):
...
async def set_player_option(self):
...
async def set_ai_option(self):
...
async def add_guest(self, other: TestFAClient, *options):
"Player joins lobby (as seen by host). Maybe tells `other` to send some messages as well?"
assert self.is_host
async def launch(self):
"Host clicks the "launch" button"
async def army_defeated(self, army_id: int):
"Send defeat game result for army and report stats"
async def end_game(self):
"Game ends. Alive players get a victory result, and GameEnded is reported"
async def end_coop_game(self, *operation_complete_args):
"Coop game end. Send GameEnded followed by OperationComplete"
```
There are probably a bunch more that would be useful, but these should provide a good start. The test client should track some minimal state information like game options, game state (lobby, playing), which armies are alive, etc, although we should probably strive to keep this class as simple as possible so we don't introduce bugs by simulating incorrect behavior. Again the primary purpose is to automatically send a bunch of bulk messages that would otherwise be tedious to write out in the test.
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.