Skip to content

Commit

Permalink
Added TopPerformer class for BoxScore and fixed a few bad tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mspah-dp committed Feb 3, 2024
1 parent 87ad299 commit 37f6793
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 59 deletions.
7 changes: 4 additions & 3 deletions mlbstatsapi/models/game/livedata/boxscore/boxscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class TopPerformer:
player: Union[PlayersDictPerson, dict]
type: str
gamescore: int
hittinggamescore: int

hittinggamescore: Optional[int] = None
pitchinggamescore: Optional[int] = None

def __post_init__(self):
self.player = PlayersDictPerson(**self.player)

Expand All @@ -50,7 +51,7 @@ class BoxScore:
officials: Union[List[BoxScoreOffical], List[dict]]
info: Union[List[BoxScoreVL], List[dict]]
pitchingnotes: List[str]
topperformers: Optional[List[Union[TopPerformer, dict]]] = field(default_factory=dict)
topperformers: Optional[List[Union[TopPerformer, dict]]] = field(default_factory=list)

def __post_init__(self):
self.teams = BoxScoreTeams(**self.teams)
Expand Down
56 changes: 0 additions & 56 deletions tests/external_tests/stats/test_player_game_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,15 @@ class TestHittingStats(unittest.TestCase):
def setUpClass(cls) -> None:
cls.mlb = Mlb()
cls.al_team = 133
cls.shoei_ohtani = 660271
cls.ty_france = 664034
cls.shoei_game_id = 531368
cls.ty_game_id = 715757
cls.cal_realeigh = 663728
cls.cal_game_id = 715757
cls.archie_bradley = 605151
cls.archie_game_id = 531368

@classmethod
def tearDownClass(cls) -> None:
pass


def test_get_players_stats_for_shoei_ohtana(self):
"""return player stat objects"""

game_stats = self.mlb.get_players_stats_for_game(person_id=self.shoei_ohtani,
game_id=self.shoei_game_id)

# game stats should not be None
self.assertIsNotNone(game_stats)

# game_stats should be a dict
self.assertIsInstance(game_stats, dict)

print(game_stats)
# game_stats should have hitting stats
self.assertTrue(game_stats['pitching'])

# game_stats should have vsplayer5y and playlog stats
self.assertTrue(game_stats['pitching']['vsplayer5y'])

stat = game_stats['pitching']['vsplayer5y']

for split in stat.splits:
self.assertTrue(split.team)
self.assertTrue(split.stat)

def test_get_players_stats_for_ty_france(self):
"""return player stat objects"""
Expand Down Expand Up @@ -94,32 +65,5 @@ def test_get_players_stats_for_cal_r(self):
self.assertTrue(game_stats['hitting']['playlog'])
self.assertTrue(game_stats['stats']['gamelog'])

stat = game_stats['stats']['gamelog']


def test_get_players_stats_for_archie(self):
"""return player stat objects"""

self.game_stats = self.mlb.get_players_stats_for_game(person_id=self.archie_bradley,
game_id=self.archie_game_id)

# game stats should not be None
self.assertIsNotNone(self.game_stats)

# game_stats should be a dict
self.assertIsInstance(self.game_stats, dict)

# game_stats should have hitting stats
self.assertTrue(self.game_stats['pitching'])

# game_stats should have vsplayer5y and playlog stats
self.assertTrue(self.game_stats['pitching']['vsplayer5y'])
self.assertTrue(self.game_stats['stats']['gamelog'])

game_log_stat = self.game_stats['stats']['gamelog']
self.assertTrue(len(game_log_stat.splits) == 3)
stat = self.game_stats['pitching']['vsplayer5y']

for split in stat.splits:
self.assertTrue(split.team)
self.assertTrue(split.stat)

0 comments on commit 37f6793

Please sign in to comment.