Exemplo n.º 1
0
    def test_boxscores_search_string_representation(self, *args, **kwargs):
        result = Boxscores(datetime(2017, 2, 4))

        assert result.__repr__() == 'NHL games for 2-4-2017'
Exemplo n.º 2
0
    def test_boxscores_search_multiple_days(self, *args, **kwargs):
        expected = {
            '2-4-2017': [{
                'boxscore': '201702040BOS',
                'away_name': 'Toronto Maple Leafs',
                'away_abbr': 'TOR',
                'away_score': 6,
                'home_name': 'Boston Bruins',
                'home_abbr': 'BOS',
                'home_score': 5,
                'winning_name': 'Toronto Maple Leafs',
                'winning_abbr': 'TOR',
                'losing_name': 'Boston Bruins',
                'losing_abbr': 'BOS'
            }, {
                'boxscore': '201702040BUF',
                'away_name': 'Ottawa Senators',
                'away_abbr': 'OTT',
                'away_score': 0,
                'home_name': 'Buffalo Sabres',
                'home_abbr': 'BUF',
                'home_score': 4,
                'winning_name': 'Buffalo Sabres',
                'winning_abbr': 'BUF',
                'losing_name': 'Ottawa Senators',
                'losing_abbr': 'OTT'
            }, {
                'boxscore': '201702040CBJ',
                'away_name': 'New Jersey Devils',
                'away_abbr': 'NJD',
                'away_score': 5,
                'home_name': 'Columbus Blue Jackets',
                'home_abbr': 'CBJ',
                'home_score': 1,
                'winning_name': 'New Jersey Devils',
                'winning_abbr': 'NJD',
                'losing_name': 'Columbus Blue Jackets',
                'losing_abbr': 'CBJ'
            }, {
                'boxscore': '201702040COL',
                'away_name': 'Winnipeg Jets',
                'away_abbr': 'WPG',
                'away_score': 2,
                'home_name': 'Colorado Avalanche',
                'home_abbr': 'COL',
                'home_score': 5,
                'winning_name': 'Colorado Avalanche',
                'winning_abbr': 'COL',
                'losing_name': 'Winnipeg Jets',
                'losing_abbr': 'WPG'
            }, {
                'boxscore': '201702040DAL',
                'away_name': 'Chicago Blackhawks',
                'away_abbr': 'CHI',
                'away_score': 5,
                'home_name': 'Dallas Stars',
                'home_abbr': 'DAL',
                'home_score': 3,
                'winning_name': 'Chicago Blackhawks',
                'winning_abbr': 'CHI',
                'losing_name': 'Dallas Stars',
                'losing_abbr': 'DAL'
            }, {
                'boxscore': '201702040MTL',
                'away_name': 'Washington Capitals',
                'away_abbr': 'WSH',
                'away_score': 3,
                'home_name': 'Montreal Canadiens',
                'home_abbr': 'MTL',
                'home_score': 2,
                'winning_name': 'Washington Capitals',
                'winning_abbr': 'WSH',
                'losing_name': 'Montreal Canadiens',
                'losing_abbr': 'MTL'
            }, {
                'boxscore': '201702040NSH',
                'away_name': 'Detroit Red Wings',
                'away_abbr': 'DET',
                'away_score': 1,
                'home_name': 'Nashville Predators',
                'home_abbr': 'NSH',
                'home_score': 0,
                'winning_name': 'Detroit Red Wings',
                'winning_abbr': 'DET',
                'losing_name': 'Nashville Predators',
                'losing_abbr': 'NSH'
            }, {
                'boxscore': '201702040NYI',
                'away_name': 'Carolina Hurricanes',
                'away_abbr': 'CAR',
                'away_score': 5,
                'home_name': 'New York Islanders',
                'home_abbr': 'NYI',
                'home_score': 4,
                'winning_name': 'Carolina Hurricanes',
                'winning_abbr': 'CAR',
                'losing_name': 'New York Islanders',
                'losing_abbr': 'NYI'
            }, {
                'boxscore': '201702040PHI',
                'away_name': 'Los Angeles Kings',
                'away_abbr': 'LAK',
                'away_score': 1,
                'home_name': 'Philadelphia Flyers',
                'home_abbr': 'PHI',
                'home_score': 0,
                'winning_name': 'Los Angeles Kings',
                'winning_abbr': 'LAK',
                'losing_name': 'Philadelphia Flyers',
                'losing_abbr': 'PHI'
            }, {
                'boxscore': '201702040SJS',
                'away_name': 'Arizona Coyotes',
                'away_abbr': 'ARI',
                'away_score': 3,
                'home_name': 'San Jose Sharks',
                'home_abbr': 'SJS',
                'home_score': 2,
                'winning_name': 'Arizona Coyotes',
                'winning_abbr': 'ARI',
                'losing_name': 'San Jose Sharks',
                'losing_abbr': 'SJS'
            }, {
                'boxscore': '201702040STL',
                'away_name': 'Pittsburgh Penguins',
                'away_abbr': 'PIT',
                'away_score': 4,
                'home_name': 'St. Louis Blues',
                'home_abbr': 'STL',
                'home_score': 1,
                'winning_name': 'Pittsburgh Penguins',
                'winning_abbr': 'PIT',
                'losing_name': 'St. Louis Blues',
                'losing_abbr': 'STL'
            }, {
                'boxscore': '201702040TBL',
                'away_name': 'Anaheim Ducks',
                'away_abbr': 'ANA',
                'away_score': 2,
                'home_name': 'Tampa Bay Lightning',
                'home_abbr': 'TBL',
                'home_score': 3,
                'winning_name': 'Tampa Bay Lightning',
                'winning_abbr': 'TBL',
                'losing_name': 'Anaheim Ducks',
                'losing_abbr': 'ANA'
            }, {
                'boxscore': '201702040VAN',
                'away_name': 'Minnesota Wild',
                'away_abbr': 'MIN',
                'away_score': 6,
                'home_name': 'Vancouver Canucks',
                'home_abbr': 'VAN',
                'home_score': 3,
                'winning_name': 'Minnesota Wild',
                'winning_abbr': 'MIN',
                'losing_name': 'Vancouver Canucks',
                'losing_abbr': 'VAN'
            }],
            '2-5-2017': [{
                'boxscore': '201702050MTL',
                'away_name': 'Edmonton Oilers',
                'away_abbr': 'EDM',
                'away_score': 1,
                'home_name': 'Montreal Canadiens',
                'home_abbr': 'MTL',
                'home_score': 0,
                'winning_name': 'Edmonton Oilers',
                'winning_abbr': 'EDM',
                'losing_name': 'Montreal Canadiens',
                'losing_abbr': 'MTL'
            }, {
                'boxscore': '201702050NYR',
                'away_name': 'Calgary Flames',
                'away_abbr': 'CGY',
                'away_score': 3,
                'home_name': 'New York Rangers',
                'home_abbr': 'NYR',
                'home_score': 4,
                'winning_name': 'New York Rangers',
                'winning_abbr': 'NYR',
                'losing_name': 'Calgary Flames',
                'losing_abbr': 'CGY'
            }, {
                'boxscore': '201702050WSH',
                'away_name': 'Los Angeles Kings',
                'away_abbr': 'LAK',
                'away_score': 0,
                'home_name': 'Washington Capitals',
                'home_abbr': 'WSH',
                'home_score': 5,
                'winning_name': 'Washington Capitals',
                'winning_abbr': 'WSH',
                'losing_name': 'Los Angeles Kings',
                'losing_abbr': 'LAK'
            }]
        }
        result = Boxscores(datetime(2017, 2, 4), datetime(2017, 2, 5)).games

        assert result == expected
Exemplo n.º 3
0
    def test_boxscores_search_invalid_end(self, *args, **kwargs):
        result = Boxscores(datetime(2017, 2, 4), datetime(2017, 2, 3)).games

        assert result == self.expected
Exemplo n.º 4
0
    def test_boxscores_search(self, *args, **kwargs):
        result = Boxscores(datetime(2020, 3, 4)).games

        assert result == self.expected
Exemplo n.º 5
0
 def setup_method(self, *args, **kwargs):
     flexmock(Boxscores) \
         .should_receive('_find_games') \
         .and_return(None)
     self.boxscores = Boxscores(None)
Exemplo n.º 6
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/DET/2019.html">Detroit Red Wings</a></td>
    <td class="right">3</td>
    <td class="right">&nbsp;
    </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/LAK/2019.html">Los Angeles Kings</a></td>
    <td class="right">1</td>
    <td class="right gamelink">
        <a href="/boxscores/201812100DET.html">Final</a>
    </td>
</tr>
<tr class="winner">
    <td class="right">3</td>
    <td class="right">&nbsp;
    </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/LAK/2019.html">Los Angeles Kings</a></td>
    <td class="right gamelink">
        <a href="/boxscores/201812100DET.html">Final</a>
    </td>
</tr>
<tr class="loser">
    <td><a href="/teams/DET/2019.html">Detroit Red Wings</a></td>
    <td class="right">&nbsp;
    </td>
</tr>
</tbody>
</table>""")
        games = self.boxscores._extract_game_info([mock_html])

        assert games == [{
            'away_abbr': 'LAK',
            'away_name': 'Los Angeles Kings',
            'away_score': None,
            'boxscore': '201812100DET',
            'home_abbr': 'DET',
            'home_name': 'Detroit Red Wings',
            'home_score': None,
            'losing_abbr': None,
            'losing_name': None,
            'winning_abbr': None,
            'winning_name': None
        }]