Пример #1
0
    def test_calc_standings(self):
        home = Team(u'TOP Oss')
        away = Team(u'Go Ahead Eagles')
        m = Match(home, 0, away, 3)
        l = League(u'Eerste Divisie')

        match_outcome = l.__calc_league_stats__(m)
        self.assertEqual(match_outcome, [{
            u'goals_for': 0,
            u'won': 0,
            u'goals_against': 3,
            u'lost': 1,
            u'team': home,
            u'played': 1,
            u'drew': 0,
            u'points': 0
        }, {
            u'goals_for': 3,
            u'won': 1,
            u'goals_against': 0,
            u'lost': 0,
            u'team': away,
            u'played': 1,
            u'drew': 0,
            u'points': 3
        }])
Пример #2
0
    def parse(match_result):
        """
        Takes a match and parses it into objects, then adds the match to the league. It splits the line
        across the comma for each team and then further along the last space to seperate team and score,
        it *could* potentially use a regex such as (.*) ([0-9]+) ?, ?(.*) ?([0-9]+)

        :param match_result:
        """

        teams = match_result.split(u',')
        team_types = [u'home', u'away']
        match_data = {}
        try:
            for i, result in enumerate(teams):
                score_list = result.strip().rsplit(u' ', 1)
                match_data.update({
                    u'{}_team'.format(team_types[i]):
                    Team(score_list[0]),
                    u'{}_score'.format(team_types[i]):
                    int(score_list[1]),
                })
            match = Match(**match_data)
        except (IndexError, ValueError) as e:
            logger.exception(u'Error in parsing: {}'.format(match_result))
            raise e

        return match
Пример #3
0
    def test_incomplete_standings(self):
        l = League(u'Lega Procrastica')
        home = Team(u'Anubis Incompeta')
        away = Team(u'Doitus Latero')
        m = Match(home, 0, away, 0)
        l.add_match(m)

        standings = l.get_league_table
        self.assertEqual(standings, [
            {
                u'points': 1,
                u'position': 1,
                u'team': u'Anubis Incompeta'
            },
            {
                u'points': 1,
                u'position': 1,
                u'team': u'Doitus Latero'
            },
        ])
Пример #4
0
    def __gen_matches__():
        teams = [
            Team(u'Gençlerbirliği'),
            Team(u'Feriköy'),
            Team(u'Ankaragücü'),
            Team(u'Kasımpaşa'),
        ]

        matches = [
            Match(teams[0], 1, teams[1], 0),
            Match(teams[0], 6, teams[2], 6),
            Match(teams[0], 3, teams[3], 3),
            Match(teams[1], 1, teams[0], 2),
            Match(teams[1], 0, teams[2], 5),
            Match(teams[1], 1, teams[3], 3),
            Match(teams[2], 1, teams[0], 0),
            Match(teams[2], 1, teams[1], 1),
            Match(teams[2], 3, teams[3], 1),
            Match(teams[3], 6, teams[0], 0),
            Match(teams[3], 2, teams[1], 2),
            Match(teams[3], 4, teams[2], 5),
        ]

        return teams, matches
Пример #5
0
 def test_match_dupes(self):
     home = Team(u'BK Häcken')
     with self.assertRaises(MatchTeamException):
         Match(home, 0, home, 0)
Пример #6
0
 def test_team_home_win(self):
     home = Team(u'Liddlypool')
     away = Team(u'Chelski')
     match = Match(home, 1, away, 0)
     self.assertEqual(match.result, {u'home': u'won', u'away': u'lost'})
Пример #7
0
 def test_match_negative(self):
     home = Team(u'Supa Strikers')
     away = Team(u'FC Aqua')
     with self.assertRaises(MatchScoreException):
         Match(home, 0, away, -1)
Пример #8
0
 def test_match_draw(self):
     home = Team(u'East Crom Ganglion')
     away = Team(u'Wensleydale')
     match = Match(home, 0, away, 0)
     self.assertEqual(match.result, {u'home': u'drew', u'away': u'drew'})
Пример #9
0
 def test_match_away_win(self):
     home = Team(u'Man Citeh')
     away = Team(u'Gleeds')
     match = Match(home, 1, away, 3)
     self.assertEqual(match.result, {u'home': u'lost', u'away': u'won'})
Пример #10
0
 def test_team_define(self):
     t = Team(u'Liddlypool')
     self.assertEqual(unicode(t), u'Liddlypool')
Пример #11
0
 def test_match_international(self):
     away = Team(u'Александра')
     self.assertEqual(away.team_name, u'Александра')