예제 #1
0
class TestBRefStandings:
    @pytest.mark.parametrize(
        "season",
        [(x)
         for x in range(1871,
                        most_recent_season() + 1)] + [(None)]  # type: ignore
    )
    def test_standings(self, season: Optional[int]) -> None:
        standings_list = standings(season)

        assert standings_list is not None
        assert len(standings_list) == get_division_counts_by_season(season)

        for data in standings_list:
            assert data is not None
            assert not data.empty
            assert len(data.columns) > 0
            assert len(data.index) > 0

    def test_standings_pre_1871(self) -> None:
        season = 1870

        with pytest.raises(ValueError):
            standings(season)

    def test_standings_future(self) -> None:
        season = most_recent_season() + 1

        standings_list = standings(season)

        assert standings_list == []
def test_pitching_stats_bref_none() -> None:
    pitching_stats_range_mock =  MagicMock()
    this_year = most_recent_season()

    with patch('pybaseball.league_pitching_stats.pitching_stats_range', pitching_stats_range_mock):
        league_pitching_stats.pitching_stats_bref(None)

    pitching_stats_range_mock.assert_called_once_with(f'{this_year}-03-01', f"{this_year}-11-01")
예제 #3
0
def get_soup(season: Optional[int], team: str) -> BeautifulSoup:
    # get most recent year's schedule if year not specified
    if season is None:
        season = most_recent_season()
    url = "http://www.baseball-reference.com/teams/{}/{}-schedule-scores.shtml".format(
        team, season)
    print(url)
    s = requests.get(url).content
    return BeautifulSoup(s, "lxml")
예제 #4
0
def get_division_counts_by_season(season: Optional[int]) -> int:
    if season is None:
        season = most_recent_season()

    if season >= 1994:
        return 6
    if season >= 1969:
        return 4
    return 1
def test_amateur_draft_future() -> None:
    result = amateur_draft(most_recent_season() + 1, 1, keep_stats=False)

    assert result is not None
    assert not result.empty

    print(result)

    assert len(result.columns) == 8
    assert len(result) == 37
예제 #6
0
def test_amateur_draft_future() -> None:
    result = amateur_draft(most_recent_season() + 1, 1, keep_stats=False)

    assert result is not None
    assert not result.empty

    print(result)

    assert len(result.columns) == 8
    assert len(result) in (
        36, 37)  # the Astros getting docked a pick throws this off for 2021
def test_pitching_stats_bref_future() -> None:
    with pytest.raises(IndexError):
        league_pitching_stats.pitching_stats_bref(most_recent_season() + 1)
예제 #8
0
def test_schedule_and_record_future() -> None:
    with pytest.raises(ValueError):
        schedule_and_record(most_recent_season() + 1, 'TBR')
예제 #9
0
    def test_standings_future(self) -> None:
        season = most_recent_season() + 1

        standings_list = standings(season)

        assert standings_list == []