def test_parseLegaProPrimaDivisione(self):
     leaguetext = open('tests/wikidumps/Lega_Pro_Prima_Divisione.txt', 'r').read()
     seasontext = open('tests/wikidumps/2012–13_Lega_Pro_Prima_Divisione.txt', 'r').read()
     leaguedata = soccer.LeagueData()
     parser.getLeagueData(leaguetext, leaguedata)
     self.assertEqual(leaguedata.numteams, 33)
     groups = parser.getSeasonTeams(seasontext, leaguedata)
     self.assertEqual(len(groups), 2)
    def parseDump(self, name, seasontitle, numteams, numgroups = 0, levelnum = 0):
        leaguetext = open('tests/wikidumps/%s.txt' % name, 'r').read()
        if seasontitle:
            seasontext = open('tests/wikidumps/%s.txt' % seasontitle, 'r').read()
        else:
            seasontext = None

        leaguedata = soccer.LeagueData(name)
        parser.getLeagueData(leaguetext, leaguedata)

        groups = None
        if seasontext:
            parser.getLeagueData(seasontext, leaguedata)
            groups = parser.getSeasonTeams(seasontext, leaguedata)
        if not groups:
            groups = parser.getSeasonTeams(leaguetext, leaguedata)

        self.assertEqual(leaguedata.numteams, numteams)
        if numgroups:
            self.assertEqual(len(groups), numgroups)
        if levelnum:
            self.assertEqual(leaguedata.levelnum, levelnum)
        return leaguedata
 def test_parseEnglishTopSeasons(self):
     for file in ['tests/wikidumps/2012–13_Football_League_Championship.txt',
             'tests/wikidumps/2012–13_Football_League_One.txt',
             'tests/wikidumps/2012–13_Football_League_Two.txt']:
         with open(file, 'r') as f:
             l = soccer.LeagueData()
             l.numteams = 24
             groups = parser.getSeasonTeams(f.read(), l)
             self.assertEqual(len(groups), 1)
             teams = groups[0][1]
             teamnames = [t[0] for t in teams if t]
             teamlinks = [t[1] for t in teams if t]
             self.assertEqual(len(teams), 24)
             self.assertEqual(len(teamnames), 24)
             self.assertEqual(len(teamlinks), 24)
 def test_parseEnglishPremierLeagueSeason(self):
     for file in ['tests/wikidumps/2012–13_Premier_League.txt', 'tests/wikidumps/Premier_League.txt']:
         with open(file, 'r') as f:
             l = soccer.LeagueData()
             l.numteams = 20
             groups = parser.getSeasonTeams(f.read(), l)
             self.assertEqual(len(groups), 1)
             teams = groups[0][1]
             teamnames = [t[0] for t in teams if t]
             teamlinks = [t[1] for t in teams if t]
             self.assertEqual(len(teams), 20)
             self.assertEqual(len(teamnames), 20)
             self.assertEqual(len(teamlinks), 20)
             self.assertIn(('Chelsea', 'Chelsea F.C.'), teams)
             self.assertIn(('Everton', 'Everton F.C.'), teams)
             self.assertIn(('Liverpool', 'Liverpool F.C.'), teams)
             self.assertIn(('Manchester United', 'Manchester United F.C.'), teams)
             self.assertIn('Tottenham Hotspur', teamnames)
             self.assertIn('West Ham United F.C.', teamlinks)
 def test_parseScottishLeague(self):
     leagues = [('Scottish Premier League', 12), ('Scottish Football League First Division', 10),
             ('Scottish Football League Second Division', 10), ('Scottish Football League Third Division', 10)]
     for i in xrange(len(leagues)):
         leaguename = leagues[i][0]
         numteams = leagues[i][1]
         nextleaguename = leagues[i + 1][0] if i < len(leagues) - 1 else None
         seasonname = '2012–13 ' + leaguename.replace('Football League ', '')
         promotionleague = '' if i == 0 else leagues[i - 1][0]
         leaguepath = 'tests/wikidumps/' + wikiutils.titleToFilename(leaguename) + '.txt'
         seasonpath = 'tests/wikidumps/' + wikiutils.titleToFilename(seasonname) + '.txt'
         leaguedata = soccer.LeagueData(leaguename, promotionleague)
         parser.getLeagueData(open(leaguepath, 'r').read(), leaguedata)
         if not nextleaguename:
             self.assertEqual(len(leaguedata.relegationleagues), 0)
         else:
             self.assertEqual(len(leaguedata.relegationleagues), 1)
             self.assertIn(nextleaguename, leaguedata.relegationleagues.keys())
         self.assertEqual(leaguedata.title, leaguename)
         self.assertEqual(leaguedata.promotionleague, promotionleague)
         groups = parser.getSeasonTeams(open(seasonpath, 'r').read(), leaguedata)
         self.assertEqual(len(groups), 1)
         teams = groups[0][1]
         self.checkLeagueData(numteams, leaguedata, teams)
 def test_ignoreHistoricalTeamList(self):
     with open('tests/wikidumps/Regionalliga_Süd.txt', 'r') as f:
         l = soccer.LeagueData()
         l.numteams = 18
         teams = parser.getSeasonTeams(f.read(), l)
         self.assertTrue(not teams)