Beispiel #1
0
    def test_boxscores_search_string_representation(self, *args, **kwargs):
        result = Boxscores(datetime(2020, 8, 17))

        assert result.__repr__() == 'MLB games for 8-17-2020'
Beispiel #2
0
    def test_boxscores_search_multiple_days(self, *args, **kwargs):
        expected = {
            '8-17-2020': [
                {'home_name': 'Los Angeles Angels',
                 'home_abbr': 'LAA',
                 'home_score': 7,
                 'boxscore': 'ANA/ANA202008170',
                 'away_name': 'San Francisco Giants',
                 'away_abbr': 'SFG',
                 'away_score': 6,
                 'winning_name': 'Los Angeles Angels',
                 'winning_abbr': 'LAA',
                 'losing_name': 'San Francisco Giants',
                 'losing_abbr': 'SFG'},
                {'home_name': 'Arizona Diamondbacks',
                 'home_abbr': 'ARI',
                 'home_score': 4,
                 'boxscore': 'ARI/ARI202008170',
                 'away_name': 'Oakland Athletics',
                 'away_abbr': 'OAK',
                 'away_score': 3,
                 'winning_name': 'Arizona Diamondbacks',
                 'winning_abbr': 'ARI',
                 'losing_name': 'Oakland Athletics',
                 'losing_abbr': 'OAK'},
                {'home_name': 'Atlanta Braves',
                 'home_abbr': 'ATL',
                 'home_score': 7,
                 'boxscore': 'ATL/ATL202008170',
                 'away_name': 'Washington Nationals',
                 'away_abbr': 'WSN',
                 'away_score': 6,
                 'winning_name': 'Atlanta Braves',
                 'winning_abbr': 'ATL',
                 'losing_name': 'Washington Nationals',
                 'losing_abbr': 'WSN'},
                {'home_name': 'Baltimore Orioles',
                 'home_abbr': 'BAL',
                 'home_score': 2,
                 'boxscore': 'BAL/BAL202008170',
                 'away_name': 'Toronto Blue Jays',
                 'away_abbr': 'TOR',
                 'away_score': 7,
                 'winning_name': 'Toronto Blue Jays',
                 'winning_abbr': 'TOR',
                 'losing_name': 'Baltimore Orioles',
                 'losing_abbr': 'BAL'},
                {'home_name': 'Chicago White Sox',
                 'home_abbr': 'CHW',
                 'home_score': 7,
                 'boxscore': 'CHA/CHA202008170',
                 'away_name': 'Detroit Tigers',
                 'away_abbr': 'DET',
                 'away_score': 2,
                 'winning_name': 'Chicago White Sox',
                 'winning_abbr': 'CHW',
                 'losing_name': 'Detroit Tigers',
                 'losing_abbr': 'DET'},
                {'home_name': 'Chicago Cubs',
                 'home_abbr': 'CHC',
                 'home_score': 1,
                 'boxscore': 'CHN/CHN202008171',
                 'away_name': 'St. Louis Cardinals',
                 'away_abbr': 'STL',
                 'away_score': 3,
                 'winning_name': 'St. Louis Cardinals',
                 'winning_abbr': 'STL',
                 'losing_name': 'Chicago Cubs',
                 'losing_abbr': 'CHC'},
                {'home_name': 'Chicago Cubs',
                 'home_abbr': 'CHC',
                 'home_score': 5,
                 'boxscore': 'CHN/CHN202008172',
                 'away_name': 'St. Louis Cardinals',
                 'away_abbr': 'STL',
                 'away_score': 4,
                 'winning_name': 'Chicago Cubs',
                 'winning_abbr': 'CHC',
                 'losing_name': 'St. Louis Cardinals',
                 'losing_abbr': 'STL'},
                {'home_name': 'Houston Astros',
                 'home_abbr': 'HOU',
                 'home_score': 2,
                 'boxscore': 'HOU/HOU202008170',
                 'away_name': 'Colorado Rockies',
                 'away_abbr': 'COL',
                 'away_score': 1,
                 'winning_name': 'Houston Astros',
                 'winning_abbr': 'HOU',
                 'losing_name': 'Colorado Rockies',
                 'losing_abbr': 'COL'},
                {'home_name': 'Los Angeles Dodgers',
                 'home_abbr': 'LAD',
                 'home_score': 11,
                 'boxscore': 'LAN/LAN202008170',
                 'away_name': 'Seattle Mariners',
                 'away_abbr': 'SEA',
                 'away_score': 9,
                 'winning_name': 'Los Angeles Dodgers',
                 'winning_abbr': 'LAD',
                 'losing_name': 'Seattle Mariners',
                 'losing_abbr': 'SEA'},
                {'home_name': 'Miami Marlins',
                 'home_abbr': 'MIA',
                 'home_score': 4,
                 'boxscore': 'MIA/MIA202008170',
                 'away_name': 'New York Mets',
                 'away_abbr': 'NYM',
                 'away_score': 11,
                 'winning_name': 'New York Mets',
                 'winning_abbr': 'NYM',
                 'losing_name': 'Miami Marlins',
                 'losing_abbr': 'MIA'},
                {'home_name': 'Minnesota Twins',
                 'home_abbr': 'MIN',
                 'home_score': 4,
                 'boxscore': 'MIN/MIN202008170',
                 'away_name': 'Kansas City Royals',
                 'away_abbr': 'KCR',
                 'away_score': 1,
                 'winning_name': 'Minnesota Twins',
                 'winning_abbr': 'MIN',
                 'losing_name': 'Kansas City Royals',
                 'losing_abbr': 'KCR'},
                {'home_name': 'New York Yankees',
                 'home_abbr': 'NYY',
                 'home_score': 6,
                 'boxscore': 'NYA/NYA202008170',
                 'away_name': 'Boston Red Sox',
                 'away_abbr': 'BOS',
                 'away_score': 3,
                 'winning_name': 'New York Yankees',
                 'winning_abbr': 'NYY',
                 'losing_name': 'Boston Red Sox',
                 'losing_abbr': 'BOS'},
                {'home_name': 'Texas Rangers',
                 'home_abbr': 'TEX',
                 'home_score': 4,
                 'boxscore': 'TEX/TEX202008170',
                 'away_name': 'San Diego Padres',
                 'away_abbr': 'SDP',
                 'away_score': 14,
                 'winning_name': 'San Diego Padres',
                 'winning_abbr': 'SDP',
                 'losing_name': 'Texas Rangers',
                 'losing_abbr': 'TEX'}
            ],
            '8-18-2020': [
                {'boxscore': 'ANA/ANA202008180',
                 'away_name': 'San Francisco Giants',
                 'away_abbr': 'SFG',
                 'away_score': 8,
                 'home_name': 'Los Angeles Angels',
                 'home_abbr': 'LAA',
                 'home_score': 2,
                 'winning_name': 'San Francisco Giants',
                 'winning_abbr': 'SFG',
                 'losing_name': 'Los Angeles Angels',
                 'losing_abbr': 'LAA'},
                {'boxscore': 'ARI/ARI202008180',
                 'away_name': 'Oakland Athletics',
                 'away_abbr': 'OAK',
                 'away_score': 1,
                 'home_name': 'Arizona Diamondbacks',
                 'home_abbr': 'ARI',
                 'home_score': 10,
                 'winning_name': 'Arizona Diamondbacks',
                 'winning_abbr': 'ARI',
                 'losing_name': 'Oakland Athletics',
                 'losing_abbr': 'OAK'},
                {'boxscore': 'ATL/ATL202008180',
                 'away_name': 'Washington Nationals',
                 'away_abbr': 'WSN',
                 'away_score': 8,
                 'home_name': 'Atlanta Braves',
                 'home_abbr': 'ATL',
                 'home_score': 5,
                 'winning_name': 'Washington Nationals',
                 'winning_abbr': 'WSN',
                 'losing_name': 'Atlanta Braves',
                 'losing_abbr': 'ATL'},
                {'boxscore': 'BAL/BAL202008180',
                 'away_name': 'Toronto Blue Jays',
                 'away_abbr': 'TOR',
                 'away_score': 8,
                 'home_name': 'Baltimore Orioles',
                 'home_abbr': 'BAL',
                 'home_score': 7,
                 'winning_name': 'Toronto Blue Jays',
                 'winning_abbr': 'TOR',
                 'losing_name': 'Baltimore Orioles',
                 'losing_abbr': 'BAL'},
                {'boxscore': 'BOS/BOS202008180',
                 'away_name': 'Philadelphia Phillies',
                 'away_abbr': 'PHI',
                 'away_score': 13,
                 'home_name': 'Boston Red Sox',
                 'home_abbr': 'BOS',
                 'home_score': 6,
                 'winning_name': 'Philadelphia Phillies',
                 'winning_abbr': 'PHI',
                 'losing_name': 'Boston Red Sox',
                 'losing_abbr': 'BOS'},
                {'boxscore': 'CHA/CHA202008180',
                 'away_name': 'Detroit Tigers',
                 'away_abbr': 'DET',
                 'away_score': 4,
                 'home_name': 'Chicago White Sox',
                 'home_abbr': 'CHW',
                 'home_score': 10,
                 'winning_name': 'Chicago White Sox',
                 'winning_abbr': 'CHW',
                 'losing_name': 'Detroit Tigers',
                 'losing_abbr': 'DET'},
                {'boxscore': 'CHN/CHN202008180',
                 'away_name': 'St. Louis Cardinals',
                 'away_abbr': 'STL',
                 'away_score': 3,
                 'home_name': 'Chicago Cubs',
                 'home_abbr': 'CHC',
                 'home_score': 6,
                 'winning_name': 'Chicago Cubs',
                 'winning_abbr': 'CHC',
                 'losing_name': 'St. Louis Cardinals',
                 'losing_abbr': 'STL'},
                {'boxscore': 'HOU/HOU202008180',
                 'away_name': 'Colorado Rockies',
                 'away_abbr': 'COL',
                 'away_score': 1,
                 'home_name': 'Houston Astros',
                 'home_abbr': 'HOU',
                 'home_score': 2,
                 'winning_name': 'Houston Astros',
                 'winning_abbr': 'HOU',
                 'losing_name': 'Colorado Rockies',
                 'losing_abbr': 'COL'},
                {'boxscore': 'LAN/LAN202008180',
                 'away_name': 'Seattle Mariners',
                 'away_abbr': 'SEA',
                 'away_score': 1,
                 'home_name': 'Los Angeles Dodgers',
                 'home_abbr': 'LAD',
                 'home_score': 2,
                 'winning_name': 'Los Angeles Dodgers',
                 'winning_abbr': 'LAD',
                 'losing_name': 'Seattle Mariners',
                 'losing_abbr': 'SEA'},
                {'boxscore': 'MIA/MIA202008180',
                 'away_name': 'New York Mets',
                 'away_abbr': 'NYM',
                 'away_score': 8,
                 'home_name': 'Miami Marlins',
                 'home_abbr': 'MIA',
                 'home_score': 3,
                 'winning_name': 'New York Mets',
                 'winning_abbr': 'NYM',
                 'losing_name': 'Miami Marlins',
                 'losing_abbr': 'MIA'},
                {'boxscore': 'MIN/MIN202008180',
                 'away_name': 'Milwaukee Brewers',
                 'away_abbr': 'MIL',
                 'away_score': 3,
                 'home_name': 'Minnesota Twins',
                 'home_abbr': 'MIN',
                 'home_score': 4,
                 'winning_name': 'Minnesota Twins',
                 'winning_abbr': 'MIN',
                 'losing_name': 'Milwaukee Brewers',
                 'losing_abbr': 'MIL'},
                {'boxscore': 'NYA/NYA202008180',
                 'away_name': 'Tampa Bay Rays',
                 'away_abbr': 'TBR',
                 'away_score': 6,
                 'home_name': 'New York Yankees',
                 'home_abbr': 'NYY',
                 'home_score': 3,
                 'winning_name': 'Tampa Bay Rays',
                 'winning_abbr': 'TBR',
                 'losing_name': 'New York Yankees',
                 'losing_abbr': 'NYY'},
                {'boxscore': 'PIT/PIT202008180',
                 'away_name': 'Cleveland Indians',
                 'away_abbr': 'CLE',
                 'away_score': 6,
                 'home_name': 'Pittsburgh Pirates',
                 'home_abbr': 'PIT',
                 'home_score': 3,
                 'winning_name': 'Cleveland Indians',
                 'winning_abbr': 'CLE',
                 'losing_name': 'Pittsburgh Pirates',
                 'losing_abbr': 'PIT'},
                {'boxscore': 'TEX/TEX202008180',
                 'away_name': 'San Diego Padres',
                 'away_abbr': 'SDP',
                 'away_score': 6,
                 'home_name': 'Texas Rangers',
                 'home_abbr': 'TEX',
                 'home_score': 4,
                 'winning_name': 'San Diego Padres',
                 'winning_abbr': 'SDP',
                 'losing_name': 'Texas Rangers',
                 'losing_abbr': 'TEX'}
            ]
        }
        result = Boxscores(datetime(2020, 8, 17), datetime(2020, 8, 18)).games

        assert result == expected
Beispiel #3
0
    def test_boxscores_search_invalid_end(self, *args, **kwargs):
        result = Boxscores(datetime(2020, 8, 17), datetime(2020, 8, 16)).games

        assert result == self.expected
Beispiel #4
0
 def setup_method(self, *args, **kwargs):
     flexmock(Boxscores) \
         .should_receive('_find_games') \
         .and_return(None)
     self.boxscores = Boxscores(None)
Beispiel #5
0
class TestMLBBoxscores:
    @patch('requests.get', side_effect=mock_pyquery)
    def setup_method(self, *args, **kwargs):
        flexmock(Boxscores) \
            .should_receive('_find_games') \
            .and_return(None)
        self.boxscores = Boxscores(None)

    def test_improper_loser_boxscore_format_skips_game(self):
        flexmock(Boxscores) \
            .should_receive('_get_team_details') \
            .and_return((None, None, None, None, None, None))
        mock_html = pq("""<table class="teams">
<tbody>
<tr class="loser">
    <td class="right">1</td>
    <td class="right gamelink">
    </td>
</tr>
<tr class="winner">
    <td><a href="/teams/BAL/2017.shtml">Baltimore Orioles</a></td>
    <td class="right">3</td>
    <td class="right">
    </td>
</tr>
</tbody>
</table>""")
        games = self.boxscores._extract_game_info([mock_html])

        assert len(games) == 0

    def test_improper_winner_boxscore_format_skips_game(self):
        flexmock(Boxscores) \
            .should_receive('_get_team_details') \
            .and_return((None, None, None, None, None, None))
        mock_html = pq("""<table class="teams">
<tbody>
<tr class="loser">
    <td><a href="/teams/TEX/2017.shtml">Texas Rangers</a></td>
    <td class="right">1</td>
    <td class="right gamelink">
        <a href="/boxes/BAL/BAL201707170.shtml">Final</a>
    </td>
</tr>
<tr class="winner">
    <td class="right">3</td>
    <td class="right">
    </td>
</tr>
</tbody>
</table>""")
        games = self.boxscores._extract_game_info([mock_html])

        assert len(games) == 0

    def test_boxscore_with_no_score_returns_none(self):
        mock_html = pq("""<table class="teams">
<tbody>
<tr class="loser">
    <td><a href="/teams/TEX/2017.shtml">Texas Rangers</a></td>
    <td class="right gamelink">
        <a href="/boxes/BAL/BAL201707170.shtml">Final</a>
    </td>
</tr>
<tr class="loser">
    <td><a href="/teams/BAL/2017.shtml">Baltimore Orioles</a></td>
    <td class="right">
    </td>
</tr>
</tbody>
</table>""")
        games = self.boxscores._extract_game_info([mock_html])

        assert games == [{
            'away_abbr': 'TEX',
            'away_name': 'Texas Rangers',
            'away_score': None,
            'boxscore': 'BAL/BAL201707170',
            'home_abbr': 'BAL',
            'home_name': 'Baltimore Orioles',
            'home_score': None,
            'losing_abbr': None,
            'losing_name': None,
            'winning_abbr': None,
            'winning_name': None
        }]
Beispiel #6
0
    def test_boxscores_search(self, *args, **kwargs):
        result = Boxscores(datetime(2017, 7, 17)).games

        assert result == self.expected