mirror of
https://github.com/rr-/pq-cli.git
synced 2026-11-12 22:40:36 -07:00
tests: cover the roster and the command line
The roster tests pin down the .old backup rotation and the five minute periodic save, with a fake clock in place of datetime. The command line tests call main() in-process with the save and data paths in a temporary directory, so coverage counts them. They cover listing, loading, importing and exporting saves, dumping and loading word lists, and the first-run character creation. The curses UI is swapped for a stub there so a stray code path fails instead of taking over the terminal. --load-save 0 falls through to the menu and --load-save -1 plays the last character instead of being rejected; both are marked xfail. A shared fixture restores pytest's SIGINT handler after the UIs install their own.
This commit is contained in:
4 files changed
+561
No files matched your search
@@ -0,0 +1,43 @@
|
||||
"""Characters, rosters and .pqw files for the UI and CLI tests."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from test_pqw import played
|
||||
|
||||
from pqcli import pqw
|
||||
from pqcli.game_data import load_game_data
|
||||
from pqcli.mechanic import Player
|
||||
from pqcli.roster import Roster
|
||||
|
||||
DATA = load_game_data()
|
||||
|
||||
|
||||
def hero(name: str = "Exportée", ticks: int = 300) -> Player:
|
||||
"""A character that has played for a while."""
|
||||
player = played(ticks).player
|
||||
player.name = name
|
||||
return player
|
||||
|
||||
|
||||
def save_path(config: Path) -> Path:
|
||||
"""Where pqcli keeps its roster with XDG_CONFIG_HOME set to config."""
|
||||
return config / "pqcli" / "save.dat"
|
||||
|
||||
|
||||
def write_roster(config: Path, *players: Player) -> Path:
|
||||
path = save_path(config)
|
||||
Roster(path, list(players)).save()
|
||||
return path
|
||||
|
||||
|
||||
def read_names(config: Path) -> list[str]:
|
||||
return [player.name for player in Roster.load(save_path(config)).players]
|
||||
|
||||
|
||||
def write_pqw(path: Path, player: Player, *, online: bool = False) -> Path:
|
||||
"""Write player as a .pqw; online adds fields the import warns about."""
|
||||
game = pqw.export_game(player, DATA)
|
||||
if online:
|
||||
game["online"] = {"realm": "Alpaquil", "passkey": 1}
|
||||
path.write_text(pqw.encode(game), encoding="ascii")
|
||||
return path
|
||||
Reference in new issue
Block a user