def test_contract(self):
        james = lebron_james()
        assert james.contract
        assert len(james.contract.years) == 3
        assert all([year.season for year in james.contract.years])
        assert all([year.amount for year in james.contract.years])

        first_year = james.contract.years[0]
        assert first_year.season == "2019-20"
        assert first_year.amount == 37436858
        assert first_year.option is None

        third_year = james.contract.years[2]
        assert third_year.season == "2021-22"
        assert third_year.amount == 41002273
        # assert third_year.option == "Player"

        chamberlain = wilt_chamberlain()
        assert not chamberlain.contract

        shayok = PlayerPageScraper(get_resource("shayok.html")).get_content()
        assert not shayok.contract

        simons = PlayerPageScraper(
            get_resource("anfernee_simons.html")).get_content()
        assert simons.contract.years[0].option == "player"
        assert simons.contract.years[1].option == "early termination"
        assert simons.contract.years[2].option == "team"
示例#2
0
 def test_scrape(self):
     s = PlayerListScraper(get_resource("w.html"))
     urls = s.get_content()
     assert len(urls) == 364
     assert all([
         url.startswith("https://www.basketball-reference.com/players/")
         for url in urls
     ])
 def test_season(self):
     team = TeamPageScraper(get_resource("cavs.html")).get_content()
     last_season = team.seasons[-1]
     assert last_season.losses == 27
     assert last_season.wins == 10
     assert last_season.pace == 98.8
     assert last_season.rel_pace == -1.6
     assert last_season.ortg == 105.6
     assert last_season.rel_ortg == -3.6
     assert last_season.season == "2019-20"
     assert not last_season.won_championship
     assert not last_season.made_playoffs
     team = TeamPageScraper(get_resource("cavs.html")).get_content()
     championship_season = team.season("2015-16")
     assert championship_season.wins == 57
     assert championship_season.won_championship
     assert championship_season.made_playoffs
示例#4
0
 def test_stats_where_partially_available(self):
     mullin = PlayerPageScraper(
         get_resource("chris_mullin.html")).get_content()
     seasons = list(mullin.seasons)
     rookie_season = seasons[0]
     assert rookie_season.stats.shooting_data is None
     final_season = seasons[-1]
     assert final_season.stats.shooting_data
     assert final_season.stats.shooting_data.avg_distance == 18.8
 def test_team_with_url(self):
     team = TeamPageScraper(get_resource("cavs.html")).get_content()
     assert team.name == "Cleveland Cavaliers"
     assert team.wins == 1858
     assert team.losses == 2149
     assert team.playoff_appearances == 22
     assert team.championships == 1
     assert team.code == "CLE"
     assert len(team.seasons) == 50
示例#6
0
 def test_scrape(self):
     iterator = DraftPageScraper(
         get_resource("draft_2003.html")).get_content()
     draft_pick = next(iterator)
     assert isinstance(draft_pick, PlayerInDraft)
     assert draft_pick.player.name == "LeBron James"
     assert draft_pick.college is None
     assert draft_pick.pick == 1
     assert draft_pick.years_in_league > 16
     assert draft_pick.team.name == "Cleveland Cavaliers"
示例#7
0
    def test_career_stats_encapsulated(self):
        mullin = PlayerPageScraper(
            get_resource("chris_mullin.html")).get_content()
        career_stats = mullin.career_stats
        first_season = next(mullin.seasons)
        first_playoffs = next(mullin.playoffs)

        for attr in ["age", "all_star", "team", "season"]:
            assert not hasattr(career_stats, attr)
            assert hasattr(first_season, attr)
            assert hasattr(first_playoffs, attr)
示例#8
0
    def test_stats_where_none_available(self):
        chamberlain = PlayerPageScraper(
            get_resource("chamberlain.html")).get_content()
        rookie_season = next(chamberlain.seasons)
        assert rookie_season.stats.rebounds is None
        assert rookie_season.stats.offensive_rebounds is None
        assert rookie_season.stats.defensive_rebounds is None
        assert rookie_season.stats.turnovers is None
        assert rookie_season.stats.three_fg_percentage is None
        assert rookie_season.stats.three_fg_made is None
        assert rookie_season.stats.three_fg_attempted is None
        assert rookie_season.stats.shooting_data is None

        advanced_stats = rookie_season.stats.advanced
        assert advanced_stats.value_over_replacement_player is None
        assert advanced_stats.ft_attempt_rate == 0.429
        assert advanced_stats.assist_percentage is None
        assert advanced_stats.offensive_rebound_percentage is None
        assert advanced_stats.defensive_rebound_percentage is None
        assert advanced_stats.usage_percentage is None
def julius_erving():
    return PlayerPageScraper(get_resource("julius_erving.html")).get_content()
 def test_roster(self):
     team = TeamPageScraper(get_resource("cavs.html")).get_content()
     s = team.seasons[-1]
     assert len(s.roster) > 10
示例#11
0
 def test_career_stats_advanced(self):
     mullin = PlayerPageScraper(
         get_resource("chris_mullin.html")).get_content()
     assert mullin.career_stats.advanced.usage_percentage
def lebron_james():
    return PlayerPageScraper(get_resource("lebron_james.html")).get_content()
示例#13
0
 def test_get_commented_table_with_id(self):
     scr = Scraper(get_resource("lebron_james.html"))
     table = scr.get_commented_table_with_id("contracts_.*")
     assert table["id"] == "contracts_lal"
 def test_seasons(self):
     erving = PlayerPageScraper(
         get_resource("julius_erving.html")).get_content()
     assert len(list(erving.seasons)) == 11  # ABA seasons must be discarded
 def test_all_star(self):
     erving = PlayerPageScraper(
         get_resource("julius_erving.html")).get_content()
     assert len([
         season for season in list(erving.seasons) if season.all_star
     ]) == 11
def wilt_chamberlain():
    return PlayerPageScraper(get_resource("chamberlain.html")).get_content()
示例#17
0
class TestStats:
    player = PlayerPageScraper(
        get_resource("carmelo_anthony.html")).get_content()
    seasons = list(player.seasons)
    rookie_season = seasons[0]

    def test_season_stats(self):
        rookie_season = self.rookie_season
        assert repr(rookie_season).endswith("(2004, DEN)")
        assert rookie_season.stats.position == "SF"
        assert rookie_season.season == 2004
        assert rookie_season.stats.games_started == 82
        assert rookie_season.stats.games_played == 82
        assert rookie_season.stats.minutes_played == 2995
        assert rookie_season.stats.fg_attempted == 1465
        assert rookie_season.stats.fg_made == 624
        assert rookie_season.stats.three_fg_made == 69
        assert rookie_season.stats.three_fg_attempted == 214
        assert rookie_season.stats.two_fg_attempted == 1251
        assert rookie_season.stats.two_fg_made == 555
        assert rookie_season.stats.effective_fg_percentage == 0.449
        assert rookie_season.stats.ft_made == 408
        assert rookie_season.stats.ft_attempted == 525
        assert rookie_season.stats.offensive_rebounds == 183
        assert rookie_season.stats.defensive_rebounds == 315
        assert rookie_season.stats.rebounds == 498
        assert round(rookie_season.stats.two_fg_percentage, 3) == 0.444
        assert rookie_season.stats.fg_percentage == 0.426
        assert rookie_season.stats.three_fg_percentage == 0.322
        assert rookie_season.stats.free_throw_percentage == 0.777
        assert not rookie_season.all_star
        assert rookie_season.stats.assists == 227
        assert rookie_season.stats.blocks == 41
        assert rookie_season.stats.turnovers == 247
        assert rookie_season.stats.steals == 97
        assert rookie_season.stats.fouls == 225
        assert rookie_season.stats.points == 1725

    def test_advanced_stats(self):
        rookie_season = self.rookie_season
        assert repr(rookie_season.stats.advanced) == "AdvancedStatLine(2004)"
        assert rookie_season.stats.advanced.assist_percentage == 13.8
        assert rookie_season.stats.advanced.player_efficiency_rating == 17.6
        assert rookie_season.stats.advanced.true_shooting_percentage == 0.509
        assert rookie_season.stats.advanced.three_fg_attempt_rate == 0.146
        assert rookie_season.stats.advanced.ft_attempt_rate == 0.358
        assert rookie_season.stats.advanced.offensive_rebound_percentage == 6.8
        assert rookie_season.stats.advanced.defensive_rebound_percentage == 12.1
        assert rookie_season.stats.advanced.total_rebound_percentage == 9.4
        assert rookie_season.stats.advanced.steal_percentage == 1.7
        assert rookie_season.stats.advanced.block_percentage == 1.0
        assert rookie_season.stats.advanced.turnover_percentage == 12.7
        assert rookie_season.stats.advanced.usage_percentage == 28.5
        assert rookie_season.stats.advanced.offensive_win_shares == 3.7
        assert rookie_season.stats.advanced.defensive_win_shares == 2.4
        assert rookie_season.stats.advanced.win_shares == 6.1
        assert rookie_season.stats.advanced.win_shares_per_48 == 0.098
        assert rookie_season.stats.advanced.offensive_box_plus_minus == 1.2
        assert rookie_season.stats.advanced.defensive_box_plus_minus == -1.2
        assert rookie_season.stats.advanced.box_plus_minus == 0
        assert rookie_season.stats.advanced.value_over_replacement_player == 1.6

    def test_stats_where_none_available(self):
        chamberlain = PlayerPageScraper(
            get_resource("chamberlain.html")).get_content()
        rookie_season = next(chamberlain.seasons)
        assert rookie_season.stats.rebounds is None
        assert rookie_season.stats.offensive_rebounds is None
        assert rookie_season.stats.defensive_rebounds is None
        assert rookie_season.stats.turnovers is None
        assert rookie_season.stats.three_fg_percentage is None
        assert rookie_season.stats.three_fg_made is None
        assert rookie_season.stats.three_fg_attempted is None
        assert rookie_season.stats.shooting_data is None

        advanced_stats = rookie_season.stats.advanced
        assert advanced_stats.value_over_replacement_player is None
        assert advanced_stats.ft_attempt_rate == 0.429
        assert advanced_stats.assist_percentage is None
        assert advanced_stats.offensive_rebound_percentage is None
        assert advanced_stats.defensive_rebound_percentage is None
        assert advanced_stats.usage_percentage is None

    def test_stats_where_partially_available(self):
        mullin = PlayerPageScraper(
            get_resource("chris_mullin.html")).get_content()
        seasons = list(mullin.seasons)
        rookie_season = seasons[0]
        assert rookie_season.stats.shooting_data is None
        final_season = seasons[-1]
        assert final_season.stats.shooting_data
        assert final_season.stats.shooting_data.avg_distance == 18.8

    def test_career_stats_advanced(self):
        mullin = PlayerPageScraper(
            get_resource("chris_mullin.html")).get_content()
        assert mullin.career_stats.advanced.usage_percentage

    def test_career_stats_encapsulated(self):
        mullin = PlayerPageScraper(
            get_resource("chris_mullin.html")).get_content()
        career_stats = mullin.career_stats
        first_season = next(mullin.seasons)
        first_playoffs = next(mullin.playoffs)

        for attr in ["age", "all_star", "team", "season"]:
            assert not hasattr(career_stats, attr)
            assert hasattr(first_season, attr)
            assert hasattr(first_playoffs, attr)
 def test_get_playoff_totals(self):
     erving = PlayerPageScraper(
         get_resource("julius_erving.html")).get_content()
     playoffs = list(erving.playoffs)
     assert len(playoffs) == 11
     assert sum([season.stats.points for season in playoffs]) == 3088
def carmelo_anthony():
    return PlayerPageScraper(
        get_resource("carmelo_anthony.html")).get_content()
 def test_historical_player(self):
     player = PlayerPageScraper(
         get_resource("tom_hawkins.html")).get_content()
     assert player.name == "Tom Hawkins"
     assert player.date_of_birth == date(1936, 12, 22)