def test_populate(self): self.assertIsNotNone(self.teams) self.assertGreater(len(self.teams), 0) self.assertIsNotNone(self.argentina.friendly_results) # argentina beat mexico, make sure this is apparent self.assertIn(Team.get_for_country(self.teams, 'Mexico'), self.argentina.friendly_results['wins']) self.assertIn(self.argentina, Team.get_for_country(self.teams, "Mexico").friendly_results['losses']) self.assertIsNotNone(self.cote.friendly_results.get('wins', None)) self.assertIsNotNone(self.cote.friendly_results.get('losses', None)) # make sure all teams have at least one win and one loss (draws could possibly be missing) for team in self.teams: self.assertIsNotNone(len(team.friendly_results.get('wins', None))) self.assertIsNotNone(len(team.friendly_results.get('losses', None)))
def test_add_friendly_result(self): self.usa.add_friendly_result(opponent=self.brazil) self.usa.add_friendly_result(opponent=self.brazil, result=Team.DRAW) self.usa.add_friendly_result(opponent=self.brazil, result=Team.LOSS) self.assertIn(self.brazil, self.usa.friendly_results['wins']) self.assertIn(self.brazil, self.usa.friendly_results['draws']) self.assertIn(self.brazil, self.usa.friendly_results['losses']) # try adding a friendly result for a team not in the tourney prev_draws = len(self.usa.friendly_results['draws']) self.usa.add_friendly_result(opponent=Team.get_for_country(self.teams, "Israel"), result=Team.DRAW) self.assertEqual(prev_draws + 1, len(self.usa.friendly_results['draws']))
def populate(self): """ :return: ``list`` the ``teams`` with player information added """ if not self._players_csv_exists(): self._create_csv_from_webpage() teams = self.tournament.teams with open(self.csv_path, 'rb') as csvfile: reader = csv.reader(csvfile, delimiter=',', quotechar='|') for i, row in enumerate(reader): team = Team.get_for_country(teams, row[1]) if team and len(team.players) <= self.num_players_allowed: # since the players are sorted by skill level, we say the best 20 players are stars new_player = Player(name=row[0], age=row[2], skill_rank=int(row[3]), is_star=i < 20) team.players.append(new_player) return teams
def _set_friendly_results(self): """ populate the friendly_results hash for each team from results.csv """ with open('data/results.csv') as results_csv: reader = csv.reader(results_csv) for result in reader: get_team = lambda index: Team.get_for_country(self.tournament.teams, result[index].strip()) home_team, away_team = get_team(1), get_team(2) home_goals, away_goals = result[3], result[4] try: home_team.add_friendly_result(opponent=away_team, result=home_team.result_from_scores(home_goals, away_goals)) except AttributeError: # either the header row or the away / home team isn't in the tourney pass try: away_team.add_friendly_result(opponent=home_team, result=away_team.result_from_scores(away_goals, home_goals)) except AttributeError: # either the header row or the away team isn't in the tourney pass
def test_get_opponent_at_stage(self): brazil = Team.get_for_country(self.teams, 'Brazil') mexico = Team.get_for_country(self.teams, 'Mexico') cameroon = Team.get_for_country(self.teams, 'Cameroon') spain = Team.get_for_country(self.teams, 'Spain') netherlands = Team.get_for_country(self.teams, 'Netherlands') opp = self.tree.get_opponent_at_stage(brazil, 0) self.assertEqual(opp.country, netherlands.country) opp = self.tree.get_opponent_at_stage(brazil, 1) self.assertEqual(opp.country, Team.get_for_country(self.teams, 'Colombia').country) opp = self.tree.get_opponent_at_stage(brazil, 3) self.assertEqual(opp.country, spain.country) opp = self.tree.get_opponent_at_stage(netherlands, 0) self.assertEqual(opp.country, brazil.country) opp = self.tree.get_opponent_at_stage(mexico, 0) self.assertEqual(opp.country, spain.country) # test for a team that isn't in the probability tree self.assertEqual(self.tree.get_opponent_at_stage(cameroon, 0).country, self.tree.get_opponent_at_stage(mexico, 0).country)
def setUp(self): self.tournament = Tournament() self.teams = self.tournament.teams self.usa = Team.get_for_country(self.teams, 'United States') self.brazil = Team.get_for_country(self.teams, 'Brazil')
def test_get_for_group(self): self.assertIn(Team.get_for_country(self.teams, 'Brazil'), Team.get_for_group(self.teams, 'A')) self.assertNotIn(Team.get_for_country(self.teams, 'Brazil'), Team.get_for_group(self.teams, 'B'))
def test_get_for_country(self): self.assertEqual(Team.get_for_country(self.teams, 'Brazil').country, 'Brazil')
def test_base_score(self): # these tests operate using some basic, commonly held assumptions (which could actually be a source of human error) self.assertGreater(self.brazil.base_score, self.usa.base_score) self.assertGreater(self.usa.base_score, Team.get_for_country(self.teams, "Ghana").base_score)
def setUp(self): self.tournament = Tournament() self.teams = self.tournament.teams self.argentina = Team.get_for_country(self.teams, 'Argentina')
def setUp(self): self.tournament = Tournament() self.teams = self.tournament.teams self.argentina = Team.get_for_country(self.teams, 'Argentina') self.cote = Team.get_for_country(self.teams, "Cote D'Ivoire")