def team_bias(pick_context): config = PickConfig() team_biases = [ models.team_from_str(team_bias) for team_bias in config.team_biases ] team1 = pick_context.team1 team2 = pick_context.team2 two_biases_reason = '{} is a bigger bias than {}.' one_bias_reason = '{} is one of the team biases, but {} is not.' for team in team_biases: if team is team1: reason = two_biases_reason if team2 in team_biases else one_bias_reason return PickResult().team1_wins().because( reason.format(team1, team2)) if team is pick_context.team2: reason = two_biases_reason if team1 in team_biases else one_bias_reason return PickResult().team2_wins().because( reason.format(team2, team1)) return None
def __init__(self, team1, team2): self._team1 = models.team_from_str(team1) self._team2 = models.team_from_str(team2)
def test_teamFromStr_givenInvalidTeamName_raisesRuntimeError(self): with self.assertRaisesRegex(RuntimeError, 'not-a-valid-team-name'): models.team_from_str('not-a-valid-team-name')
def test_teamFromStr_givenTeamCode_returnsSameTeamGivenTeamName(self): expected = models.team_from_str('NYG') actual = models.team_from_str('giants') self.assertIs(actual, expected)
def test_teamFromStr_givenInvalidTeamCode_raisesRuntimeError(self): with self.assertRaisesRegex(RuntimeError, 'ABC'): models.team_from_str('ABC')