paper-dynasty-discord/tests/gameplay_models/test_lineup_model.py
Cal Corum ee80cd72ae fix: apply Black formatting and resolve ruff lint violations
Run Black formatter across 83 files and fix 1514 ruff violations:
- E722: bare except → typed exceptions (17 fixes)
- E711/E712/E721: comparison style fixes with noqa for SQLAlchemy (44 fixes)
- F841: unused variable assignments (70 fixes)
- F541/F401: f-string and import cleanup (1383 auto-fixes)

Remaining 925 errors are all F403/F405 (star imports) — structural,
requires converting to explicit imports in a separate effort.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 11:37:46 -05:00

96 lines
2.9 KiB
Python

import pytest
from sqlmodel import Session, select
from in_game.gameplay_models import Game, Lineup
from in_game.gameplay_queries import (
get_game_lineups,
get_one_lineup,
get_sorted_lineups,
)
def test_create_lineup(session: Session):
all_lineups = session.exec(select(Lineup)).all()
assert len(all_lineups) == 40
query_ss = session.exec(
select(Lineup).where(
Lineup.game_id == 1,
Lineup.position == "SS",
Lineup.active == True, # noqa: E712
)
).all()
lineup_id_7 = session.get(Lineup, 7)
lineup_id_21 = session.get(Lineup, 21)
assert len(query_ss) == 2
assert lineup_id_7.position == "CF"
assert lineup_id_21.position == "C"
def test_get_game_lineups(session: Session):
this_game = session.get(Game, 1)
all_lineups = get_game_lineups(session, this_game=this_game)
away_lineups = get_game_lineups(
session, this_game=this_game, specific_team=this_game.away_team
)
assert len(all_lineups) == 20
assert len(away_lineups) == 10
for count in range(5):
away_lineups[count].active = False
session.add(away_lineups[count])
session.commit()
all_lineups = get_game_lineups(session, this_game=this_game)
away_lineups = get_game_lineups(
session, this_game=this_game, specific_team=this_game.away_team
)
active_away_lineups = get_game_lineups(
session, this_game=this_game, specific_team=this_game.away_team, is_active=True
)
inactive_home_lineups = get_game_lineups(
session, this_game=this_game, specific_team=this_game.home_team, is_active=False
)
assert len(all_lineups) == 20
assert len(away_lineups) == 10
assert len(active_away_lineups) == 5
assert len(inactive_home_lineups) == 0
def test_get_one_lineup(session: Session):
this_game = session.get(Game, 1)
ss = get_one_lineup(session, this_game, this_game.away_team, position="SS")
assert ss.batting_order == 5
leadoff = get_one_lineup(session, this_game, this_game.away_team, batting_order=1)
assert leadoff.position == "C"
with pytest.raises(KeyError) as exc_info:
get_one_lineup(session, this_game, this_game.away_team)
assert (
str(exc_info)
== "<ExceptionInfo KeyError('Position or batting order must be provided for get_one_lineup') tblen=2>"
)
def test_order_lineups_by_position(session: Session):
this_game = session.get(Game, 1)
all_lineups = get_sorted_lineups(session, this_game, this_game.home_team)
assert all_lineups[0].position == "P"
assert all_lineups[1].position == "C"
assert all_lineups[2].position == "1B"
assert all_lineups[3].position == "2B"
assert all_lineups[4].position == "3B"
assert all_lineups[5].position == "SS"
assert all_lineups[6].position == "LF"
assert all_lineups[7].position == "CF"
assert all_lineups[8].position == "RF"