Beispiel #1
0
    def test_searchForTable_returnsNoneIfNotFound(self):
        endpoint = "/boxes/CHN/CHN201504050.shtml"
        page = ws.requests.get(ws.URL + endpoint)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        search_id = "this_is_a_test_id"

        table = ws.searchForTable(soup, search_id)

        self.assertEqual(None, table)
Beispiel #2
0
    def test_extractPlayerEndpointsFromTable_extractsAllEndpointsPitcher(self):
        endpoint = "/boxes/LAN/LAN201509150.shtml"
        page = ws.requests.get(ws.URL + endpoint)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        search_id = "LosAngelesDodgerspitching"
        table = ws.searchForTable(soup, search_id)

        endpoint_players = ws.extractPlayerEndpointsFromTable(table, 'pitcher')

        self.assertEqual(11, len(endpoint_players))
Beispiel #3
0
    def test_extractPlayerEndpointsFromTable_extractsAllEndpointsHitter(self):
        endpoint = "/boxes/LAN/LAN201509150.shtml"
        page = ws.requests.get(ws.URL + endpoint)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        search_id = "ColoradoRockiesbatting"
        table = ws.searchForTable(soup, search_id)

        endpoint_players = ws.extractPlayerEndpointsFromTable(table, 'hitter')

        self.assertEqual(15, len(endpoint_players))
Beispiel #4
0
    def test_extractPlayerEndpointsFromTable_extractsCorrectEndpoint(self):
        endpoint = "/boxes/CHN/CHN201504050.shtml"
        page = ws.requests.get(ws.URL + endpoint)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        search_id = "StLouisCardinalsbatting"
        table = ws.searchForTable(soup, search_id)

        endpoint_players = ws.extractPlayerEndpointsFromTable(table, 'hitter')

        self.assertEqual("/players/c/carpema01.shtml", endpoint_players[0])
Beispiel #5
0
    def test_searchForTable_searchesTableWithID(self):
        endpoint = "/boxes/CHN/CHN201504050.shtml"
        page = ws.requests.get(ws.URL + endpoint)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        search_id = "StLouisCardinalsbatting"

        table = ws.searchForTable(soup, search_id)

        caption = table.find("caption").string
        self.assertEqual("St. Louis Cardinals Table", caption)
Beispiel #6
0
    def test_extractSeasonStatsFromTable_extractsStatsPitcher(self):
        endpoint = "/players/w/wainwad01.shtml"
        page = ws.requests.get(ws.URL + endpoint)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        table = ws.searchForTable(soup, 'pitching_standard')

        output = ws.extractSeasonStatsFromTable(table, 'pitcher', 2010)

        expected = {'SHO': 2, 'IP': 230.1, 'H': 186, 'SO': 213, 'BF': 910}
        self.assertEqual(expected, output)
Beispiel #7
0
    def test_extractSeasonStatsFromTable_extractsStatsHitter(self):
        endpoint = "/players/w/wainwad01.shtml"
        page = ws.requests.get(ws.URL + endpoint)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        table = ws.searchForTable(soup, 'batting_standard')

        output = ws.extractSeasonStatsFromTable(table, 'hitter', 2007)

        expected = {'PA': 74, 'H': 18, 'SO': 18}
        self.assertEqual(expected, output)
Beispiel #8
0
    def test_extractHitterOutcome_extractsCorrectOutcome(self):
        endpoint = "/boxes/CHN/CHN201504050.shtml"
        page = ws.requests.get(ws.URL + endpoint)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        search_id = "StLouisCardinalsbatting"
        table = ws.searchForTable(soup, search_id)
        endpoint_player = "/players/h/heywaja01.shtml"

        h_contribution = ws.extractHitterOutcome(table, endpoint_player)

        self.assertEqual(3 / 10, h_contribution)
Beispiel #9
0
    def test_extractPlayerGamePerformance_extractsPitcherData_SHO(self):
        endpoint_player = "/players/t/tanakma01.shtml"
        endpoint_game = "/boxes/TBA/TBA201807240.shtml"
        page = ws.requests.get(ws.URL + endpoint_game)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        table = ws.searchForTable(soup, 'NewYorkYankeespitching')

        output = ws.extractPlayerGamePerformance(table, endpoint_player,
                                                 'pitcher')

        expected = {'IP': 9, 'H': 3, 'SO': 9, 'BF': 29, 'SHO': 1}
        self.assertEqual(expected, output)
Beispiel #10
0
    def test_extractPlayerGamePerformance_extractsPitcherData_noSHO(self):
        endpoint_player = "/players/w/wainwad01.shtml"
        endpoint_game = "/boxes/CHN/CHN201504050.shtml"
        page = ws.requests.get(ws.URL + endpoint_game)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        table = ws.searchForTable(soup, 'StLouisCardinalspitching')

        output = ws.extractPlayerGamePerformance(table, endpoint_player,
                                                 'pitcher')

        expected = {'IP': 6, 'H': 5, 'SO': 6, 'BF': 23, 'SHO': 0}
        self.assertEqual(expected, output)
Beispiel #11
0
    def test_extractPlayerGamePerformance_extractsHitterData(self):
        endpoint_player = "/players/c/carpema01.shtml"
        endpoint_game = "/boxes/CHN/CHN201504050.shtml"
        page = ws.requests.get(ws.URL + endpoint_game)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        table = ws.searchForTable(soup, 'StLouisCardinalsbatting')

        output = ws.extractPlayerGamePerformance(table, endpoint_player,
                                                 'hitter')

        expected = {'PA': 5, 'H': 2, 'SO': 0}
        self.assertEqual(expected, output)
Beispiel #12
0
    def test_extractPlayerGamePerformance_raisesExceptionIfInvalidArgument(
            self):
        endpoint_player = "/players/t/tanakma01.shtml"
        endpoint_game = "/boxes/TBA/TBA201807240.shtml"
        page = ws.requests.get(ws.URL + endpoint_game)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        table = ws.searchForTable(soup, 'NewYorkYankeespitching')

        with self.assertRaises(Exception) as ctx:
            output = ws.extractPlayerGamePerformance(table, endpoint_player,
                                                     '')

        self.assertIsInstance(ctx.exception, ValueError)