mirror of
https://github.com/kuhyx/testsAndMisc-archive.git
synced 2026-07-04 13:23:01 +02:00
Fix fm24_searcher: restore CLI output and fix test mocking
- cli.py: restore _print_stats output using sys.stdout.write - cli.py: restore run_dump output (player list, TSV, progress to stderr) - cli.py: run_dump shows 'Showing X of Y players' summary - test_main.py: patch __main__.run_dump/main not cli.run_dump/gui.main
This commit is contained in:
parent
d417407795
commit
4d4ba0e2ff
@ -15,6 +15,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from python_pkg.fm24_searcher.binary_parser import (
|
from python_pkg.fm24_searcher.binary_parser import (
|
||||||
@ -159,25 +160,32 @@ def build_parser() -> argparse.ArgumentParser:
|
|||||||
def _print_stats(players: list[Player]) -> None:
|
def _print_stats(players: list[Player]) -> None:
|
||||||
"""Print summary statistics about loaded players."""
|
"""Print summary statistics about loaded players."""
|
||||||
total = len(players)
|
total = len(players)
|
||||||
sum(1 for p in players if p.date_of_birth)
|
with_dob = sum(1 for p in players if p.date_of_birth)
|
||||||
with_attrs = sum(1 for p in players if p.attributes)
|
with_attrs = sum(1 for p in players if p.attributes)
|
||||||
sum(1 for p in players if p.current_ability)
|
with_ca = sum(1 for p in players if p.current_ability)
|
||||||
|
sys.stdout.write(f"Total players: {total}\n")
|
||||||
|
sys.stdout.write(f"With DOB: {with_dob}\n")
|
||||||
|
sys.stdout.write(f"With attributes: {with_attrs}\n")
|
||||||
|
sys.stdout.write(f"With CA/PA: {with_ca}\n")
|
||||||
if with_attrs > 0:
|
if with_attrs > 0:
|
||||||
sum(len(p.attributes) for p in players) / with_attrs
|
avg_attrs = sum(len(p.attributes) for p in players) / with_attrs
|
||||||
|
sys.stdout.write(f"Avg attributes per player: {avg_attrs:.1f}\n")
|
||||||
if total == 0:
|
if total == 0:
|
||||||
return
|
return
|
||||||
if with_attrs > 0:
|
|
||||||
pass
|
|
||||||
# Attribute coverage
|
# Attribute coverage
|
||||||
attr_counts: dict[str, int] = {}
|
attr_counts: dict[str, int] = {}
|
||||||
for p in players:
|
for p in players:
|
||||||
for attr in p.attributes:
|
for attr in p.attributes:
|
||||||
attr_counts[attr] = attr_counts.get(attr, 0) + 1
|
attr_counts[attr] = attr_counts.get(attr, 0) + 1
|
||||||
if attr_counts:
|
if attr_counts:
|
||||||
|
sys.stdout.write("Attribute coverage:\n")
|
||||||
for attr in ALL_VISIBLE_ATTRS:
|
for attr in ALL_VISIBLE_ATTRS:
|
||||||
count = attr_counts.get(attr, 0)
|
count = attr_counts.get(attr, 0)
|
||||||
pct = 100 * count / with_attrs if with_attrs else 0
|
pct = 100 * count / with_attrs if with_attrs else 0
|
||||||
"*" * int(pct / 5)
|
bar = "*" * int(pct / 5)
|
||||||
|
sys.stdout.write(
|
||||||
|
f" {attr:20s} {count:4d}/{with_attrs:4d} ({pct:5.1f}%) {bar}\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def run_dump(argv: Sequence[str] | None = None) -> int:
|
def run_dump(argv: Sequence[str] | None = None) -> int:
|
||||||
@ -193,9 +201,11 @@ def run_dump(argv: Sequence[str] | None = None) -> int:
|
|||||||
return 2
|
return 2
|
||||||
|
|
||||||
def progress(msg: str, pct: int) -> None:
|
def progress(msg: str, pct: int) -> None:
|
||||||
pass
|
sys.stderr.write(f"\r{msg} {pct}%")
|
||||||
|
sys.stderr.flush()
|
||||||
|
|
||||||
players = parse_people_db(db_path, progress_cb=progress)
|
players = parse_people_db(db_path, progress_cb=progress)
|
||||||
|
sys.stderr.write("\n")
|
||||||
|
|
||||||
if args.search:
|
if args.search:
|
||||||
players = search_players(players, args.search)
|
players = search_players(players, args.search)
|
||||||
@ -209,13 +219,17 @@ def run_dump(argv: Sequence[str] | None = None) -> int:
|
|||||||
|
|
||||||
# Apply limit
|
# Apply limit
|
||||||
limited = players[: args.limit]
|
limited = players[: args.limit]
|
||||||
|
total = len(players)
|
||||||
|
shown = len(limited)
|
||||||
|
|
||||||
# Output
|
# Output
|
||||||
if args.tsv:
|
if args.tsv:
|
||||||
for _p in limited:
|
sys.stdout.write(_format_tsv_header(show_attrs=args.attrs) + "\n")
|
||||||
pass
|
for p in limited:
|
||||||
|
sys.stdout.write(_format_tsv_row(p, show_attrs=args.attrs) + "\n")
|
||||||
else:
|
else:
|
||||||
for _p in limited:
|
for p in limited:
|
||||||
pass
|
sys.stdout.write(_format_player(p, show_attrs=args.attrs) + "\n\n")
|
||||||
|
|
||||||
|
sys.stdout.write(f"Showing {shown} of {total} players\n")
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@ -16,7 +16,7 @@ class TestMain:
|
|||||||
with (
|
with (
|
||||||
patch("sys.argv", ["fm24", "--dump", "--db", "/nonexistent"]),
|
patch("sys.argv", ["fm24", "--dump", "--db", "/nonexistent"]),
|
||||||
patch(
|
patch(
|
||||||
"python_pkg.fm24_searcher.cli.run_dump",
|
"python_pkg.fm24_searcher.__main__.run_dump",
|
||||||
return_value=0,
|
return_value=0,
|
||||||
) as mock_dump,
|
) as mock_dump,
|
||||||
):
|
):
|
||||||
@ -29,7 +29,7 @@ class TestMain:
|
|||||||
with (
|
with (
|
||||||
patch("sys.argv", ["fm24"]),
|
patch("sys.argv", ["fm24"]),
|
||||||
patch(
|
patch(
|
||||||
"python_pkg.fm24_searcher.gui.main",
|
"python_pkg.fm24_searcher.__main__.main",
|
||||||
) as mock_gui,
|
) as mock_gui,
|
||||||
):
|
):
|
||||||
_main()
|
_main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user