def __parse_team_stats(self): """ Set up the team stats dictionaries and add it to self.json """ soup = self.soups["team_stats"] # Find each row of the table rows = soup.find_all("tr") home_dict = self.json["team stats"]["home"] away_dict = self.json["team stats"]["away"] for row in rows: # Find each column of the table cols = row.find_all("td") if cols: # This if removes the header # Extract the key and both the home and away team values key = cols[0].get_text(strip=True) tmp_away = cols[1].get_text(strip=True) tmp_home = cols[2].get_text(strip=True) if key == "First downs": away_dict["first downs"] = int(tmp_away) home_dict["first downs"] = int(tmp_home) elif key == "Rush-yards-TDs": away_dict["rush"] = convert_rush_info(tmp_away) home_dict["rush"] = convert_rush_info(tmp_home) elif key == "Comp-Att-Yd-TD-INT": away_dict["pass"] = convert_pass_info(tmp_away) home_dict["pass"] = convert_pass_info(tmp_home) elif key == "Sacked-yards": away_dict["sacks"] = convert_sack_info(tmp_away) home_dict["sacks"] = convert_sack_info(tmp_home) elif key == "Fumbles-lost": away_dict["fumbles"] = convert_fumble_info(tmp_away) home_dict["fumbles"] = convert_fumble_info(tmp_home) elif key == "Penalties-yards": away_dict["penalties"] = convert_penalty_info(tmp_away) home_dict["penalties"] = convert_penalty_info(tmp_home)
def test_convert_sack_info(self): # Successful self.assertEqual(convert_sack_info("1-7"), {"plays": 1, "yards": -7}) # Failure returns None self.assertEqual(convert_sack_info("18 34"), None) self.assertEqual(convert_sack_info("2-A"), None) self.assertEqual(convert_sack_info("A-2"), None)
def test_convert_sack_info(self): # Successful self.assertEqual(convert_sack_info("1-7"), {"plays": 1, "yards": -7}) # Failure raises ValueError self.assertRaises(ValueError, convert_sack_info, "18 34") self.assertRaises(ValueError, convert_sack_info, "2-A") self.assertRaises(ValueError, convert_sack_info, "A-2")