Exemplo n.º 1
0
    def test_extractTrainingExample_raisesExceptionIfInvalidArgument(self):
        endpoint_game = "/boxes/CHN/CHN201504050.shtml"
        page = ws.requests.get(ws.URL + endpoint_game)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        team_away, team_home = ws.extractTeams(soup)
        hitters_stats = {}
        pitchers_stats = {}

        with self.assertRaises(Exception) as ctx:
            ws.extractTrainingExample(endpoint_game, hitters_stats,
                                      pitchers_stats, soup, '', team_away,
                                      team_home, 2015)

        self.assertIsInstance(ctx.exception, ValueError)
Exemplo n.º 2
0
    def test_extractTrainingExample_instantiatesCorrectGameAway(self):
        endpoint_game = "/boxes/CHN/CHN201504050.shtml"
        page = ws.requests.get(ws.URL + endpoint_game)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        team_away, team_home = ws.extractTeams(soup)
        hitters_stats = {}
        pitchers_stats = {}

        game = ws.extractTrainingExample(endpoint_game, hitters_stats,
                                         pitchers_stats, soup, 'away',
                                         team_away, team_home, 2015)

        expected_id = '/boxes/CHN/CHN201504050.shtml-A'
        expected_len_hitters = 10
        expected_len_pitchers = 6
        expected_outcome = {
            '/players/c/carpema01.shtml': 2 / 10,
            '/players/h/heywaja01.shtml': 3 / 10,
            '/players/h/hollima01.shtml': 2 / 10,
            '/players/p/peraljh01.shtml': 1 / 10,
            '/players/j/jayjo02.shtml': 2 / 10
        }
        isCorrect = True
        for outcome in expected_outcome:
            if game.outcome[outcome] != expected_outcome[outcome]:
                isCorrect = False
        self.assertTrue(expected_id == game.id
                        and expected_len_hitters == len(game.hitters)
                        and expected_len_pitchers == len(game.pitchers)
                        and isCorrect)
Exemplo n.º 3
0
    def test_extractTrainingExample_instantiatesCorrectGameHome(self):
        endpoint_game = "/boxes/CHN/CHN201504050.shtml"
        page = ws.requests.get(ws.URL + endpoint_game)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        team_away, team_home = ws.extractTeams(soup)
        hitters_stats = {}
        pitchers_stats = {}

        game = ws.extractTrainingExample(endpoint_game, hitters_stats,
                                         pitchers_stats, soup, 'home',
                                         team_home, team_away, 2015)

        expected_id = '/boxes/CHN/CHN201504050.shtml-H'
        expected_len_hitters = 11
        expected_len_pitchers = 4
        expected_outcome = {
            '/players/f/fowlede01.shtml': 1 / 5,
            '/players/c/castrst01.shtml': 1 / 5,
            '/players/c/coghlch01.shtml': 1 / 5,
            '/players/r/rossda01.shtml': 1 / 5,
            '/players/l/lasteto01.shtml': 1 / 5
        }
        isCorrect = True
        for outcome in expected_outcome:
            if game.outcome[outcome] != expected_outcome[outcome]:
                isCorrect = False
        self.assertTrue(expected_id == game.id
                        and expected_len_hitters == len(game.hitters)
                        and expected_len_pitchers == len(game.pitchers)
                        and isCorrect)
Exemplo n.º 4
0
    def test_extractTrainingExample_makesDeepCopyPitchers(self):
        endpoint_game = "/boxes/CHN/CHN201504050.shtml"
        page = ws.requests.get(ws.URL + endpoint_game)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        team_away, team_home = ws.extractTeams(soup)
        hitters_stats = {}
        pitchers_stats = {}

        game = ws.extractTrainingExample(endpoint_game, hitters_stats,
                                         pitchers_stats, soup, 'away',
                                         team_away, team_home, 2015)
        pitcher = game.pitchers[0]
        print(pitcher, pitchers_stats[pitcher.endpoint])
        self.assertNotEqual(pitcher, pitchers_stats[pitcher.endpoint])
Exemplo n.º 5
0
    def test_extractTrainingExample_updatesPitchersStats_firstGame(self):
        endpoint_game = "/boxes/CHN/CHN201504050.shtml"
        page = ws.requests.get(ws.URL + endpoint_game)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        team_away, team_home = ws.extractTeams(soup)
        hitters_stats = {}
        pitchers_stats = {}

        game = ws.extractTrainingExample(endpoint_game, hitters_stats,
                                         pitchers_stats, soup, 'away',
                                         team_away, team_home, 2015)

        expected = ws.Pitcher('Phil Coke', '/players/c/cokeph01.shtml', 0,
                              58 + .2, 69, 41 + 2, 257 + 3, 0, 1)
        self.assertEqual(expected, pitchers_stats['/players/c/cokeph01.shtml'])
Exemplo n.º 6
0
    def test_extractTrainingExample_updatesHittersStats_firstGame(self):
        endpoint_game = "/boxes/CHN/CHN201504050.shtml"
        page = ws.requests.get(ws.URL + endpoint_game)
        soup = ws.BeautifulSoup(page.content, 'html.parser')
        team_away, team_home = ws.extractTeams(soup)
        hitters_stats = {}
        pitchers_stats = {}

        game = ws.extractTrainingExample(endpoint_game, hitters_stats,
                                         pitchers_stats, soup, 'away',
                                         team_away, team_home, 2015)

        expected = ws.Hitter('Matt Carpenter', '/players/c/carpema01.shtml',
                             709 + 5, 162 + 2, 111, 0, 1)
        self.assertEqual(expected, hitters_stats['/players/c/carpema01.shtml'])