Beispiel #1
0
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')
Beispiel #2
0
 def test_load_by_gameday_bad_day_high(self):
     bad_day = Player.load_by_gameday("f70dd57b-55c4-4a62-a5ea-7cc4bf9d8ac1", season=6, day=999)
     assert bad_day is None
Beispiel #3
0
 def test_load_by_gameday_bad_day_low(self):
     with pytest.raises(ValueError):
         bad_day = Player.load_by_gameday("f70dd57b-55c4-4a62-a5ea-7cc4bf9d8ac1", season=6, day=-1)
Beispiel #4
0
 def test_load_by_gameday_bad_season_high(self):
     bad_season = Player.load_by_gameday("f70dd57b-55c4-4a62-a5ea-7cc4bf9d8ac1", season=999, day=100)
     assert bad_season is None
Beispiel #5
0
 def test_load_by_gameday_bad_id(self):
     bad_player = Player.load_by_gameday("00000000-0000-0000-0000-000000000000", season=4, day=1)
     assert bad_player is None
Beispiel #6
0
 def test_load_by_gameday(self):
     player = Player.load_by_gameday("f70dd57b-55c4-4a62-a5ea-7cc4bf9d8ac1", season=2, day=100)
     assert isinstance(player, Player)