Added /log single, all but uncapped complete Added check_uncapped_advance, ai on defense complete
79 lines
2.1 KiB
Python
79 lines
2.1 KiB
Python
import pytest
|
|
from sqlmodel import Session, select, func
|
|
|
|
from in_game.gameplay_models import Lineup, Play, Game
|
|
from in_game.gameplay_queries import get_last_team_play
|
|
from tests.factory import session_fixture
|
|
|
|
|
|
def test_create_play(session: Session):
|
|
all_plays = session.exec(select(Play)).all()
|
|
|
|
assert len(all_plays) == 2
|
|
|
|
play_1 = session.get(Play, 1)
|
|
|
|
assert play_1.game_id == 1
|
|
assert play_1.pa == 1
|
|
assert play_1.pitcher_id == 20
|
|
|
|
|
|
def test_get_current_play(session: Session):
|
|
game_1 = session.get(Game, 1)
|
|
curr_play = game_1.current_play_or_none(session)
|
|
|
|
assert curr_play.play_num == 2
|
|
|
|
|
|
def test_scorebug_ascii(session: Session):
|
|
new_play = Play(
|
|
game_id=3,
|
|
play_num=69,
|
|
batter=session.get(Lineup, 1),
|
|
batter_pos='DH',
|
|
pitcher=session.get(Lineup, 20),
|
|
catcher=session.get(Lineup, 11),
|
|
starting_outs=1,
|
|
inning_num=6
|
|
)
|
|
session.add(new_play)
|
|
session.commit()
|
|
|
|
assert new_play.scorebug_ascii == '```\nNCB3 0 ○ ▲ 6\n WV4 0 ○ ○ 1 Out\n```'
|
|
|
|
|
|
def test_last_team_play(session: Session):
|
|
this_game = session.get(Game, 1)
|
|
this_team = this_game.away_team
|
|
|
|
last_play = get_last_team_play(session, this_game, this_team)
|
|
assert last_play is not None
|
|
assert last_play.play_num == 2
|
|
|
|
this_team = this_game.home_team
|
|
|
|
assert get_last_team_play(session, this_game, this_team, none_okay=True) is None
|
|
|
|
|
|
def test_query_scalars(session: Session):
|
|
this_game = session.get(Game, 1)
|
|
all_plays = session.exec(select(Play.id, Play.error, Play.outs).where(Play.game == this_game)).all()
|
|
|
|
assert len(all_plays) == 2
|
|
assert all_plays[0].error == 0
|
|
|
|
with pytest.raises(AttributeError) as exc_info:
|
|
all_plays[0].batter_id == None
|
|
|
|
assert str(exc_info) == "<ExceptionInfo AttributeError('batter_id') tblen=4>"
|
|
|
|
count_plays = session.exec(select(func.count(Play.id)).where(Play.game == this_game)).one()
|
|
|
|
assert count_plays == 2
|
|
|
|
outs = session.exec(select(func.sum(Play.outs)).where(Play.game == this_game)).one()
|
|
|
|
assert outs == 1
|
|
|
|
|
|
# TODO: test get_ai_note |