def set_name_and_team(re_match, group_name, game, sample): if group_name in re_match.groupdict() and re_match.group( group_name) is not None: player = re_match.group(group_name) sample.set_arg(group_name, f'[[{player}]]') if sample.get_arg(f'{group_name}Team') is None: try: playerObj = Player.find_by_name(player) playerId = playerObj.id historicalPlayerObj = Player.load_by_gameday( playerId, game.season, game.day) if historicalPlayerObj is not None: teamId = historicalPlayerObj.team_id teamObj = Team.load(teamId) print( f'{player}: Found historical team data: {teamObj.full_name}' ) sample.set_arg(f'{group_name}Team', f'[[{teamObj.full_name}]]') elif playerObj.team_id is not None: teamObj = Team.load(playerObj.team_id) print( f'{player}: Falling back to current team: {teamObj.full_name}' ) sample.set_arg( f'{group_name}Team', f'maybe? [[{playerObj.league_team.full_name}]]') else: print(f'Tried but failed to look up {player}') sample.set_arg(f'{group_name}Team', 'Unknown') except: print(f'Failed to look up {player}') sample.set_arg(f'{group_name}Team', 'Unknown')
def test_load_bad_team(self): with pytest.raises(ValueError): bad_team = Team.load("00000000-0000-0000-0000-000000000000")
def team_crabs(self): """common case""" return Team.load("8d87c468-699a-47a8-b40d-cfb73a5660ad")
def test_load(self): bad_team = Team.load("3f8bbb15-61c0-4e3f-8e4a-907a5fb1565e") assert isinstance(bad_team, Team)