Ejemplo n.º 1
0
    def test_filehandler_open_url_status_not_200(self, mock_urlopen):
        cm = MagicMock()
        cm.status = 404
        cm.msg = 'Not found.'
        cm.__enter__.return_value = cm
        mock_urlopen.return_value = cm

        with self.assertRaises(urllib.error.HTTPError):
            filehandler.parse_schedules(uri='http://kenpom.com/cbbga17.txt')
Ejemplo n.º 2
0
def main():
    args = parser.parse_args()
    teams = filehandler.load_teams(path=args.teams)
    schedule_items = filehandler.parse_schedules(uri=args.uri,
                                                 store_file=args.store)

    for team in teams:
        team.load_schedule(schedule_items, include_postseason=args.postseason)

    try:
        method = rankings.methods[args.method.lower()]
    except KeyError:
        msg = f'Specified method not recognized: `{args.method}`'
        raise RuntimeError(msg)
    ranked = method(teams)

    if args.format.lower() == 'plain':
        output = '{:>3}\t{:05.4f}\t({})\t{}'
        for ranked_team in ranked:
            print(
                output.format(ranked_team.rank, ranked_team.score,
                              ranked_team.record, ranked_team.name))
    elif args.format.lower() == 'json':
        print(json.dumps(ranked, cls=TeamEncoder, indent=2))
    else:
        msg = f'Specified output format not recognized: `{args.format}`'
        raise RuntimeError(msg)
Ejemplo n.º 3
0
    def setUp(self):
        self.teams = filehandler.load_teams(path='tests/teams.txt')
        schedule_items = filehandler.parse_schedules(uri='tests/data.txt')

        for team in self.teams:
            team.load_schedule(schedule_items)

        self.ranked = rankings.do_bubble(self.teams)
Ejemplo n.º 4
0
    def test_filehandler_open_url(self, mock_urlopen):
        with open('tests/data.txt', 'rb') as f:
            data = f.readlines()
        cm = MagicMock()
        cm.status = 200
        cm.readlines.return_value = data
        cm.__enter__.return_value = cm
        mock_urlopen.return_value = cm

        schedule_items = filehandler.parse_schedules(
            uri='http://kenpom.com/cbbga17.txt')
        self.assertEquals(len(schedule_items), 34)
Ejemplo n.º 5
0
 def test_empty_txt_file(self):
     with self.assertRaises(ValueError):
         filehandler.parse_schedules(uri='tests/empty_data.txt')
Ejemplo n.º 6
0
 def test_open_csv_file(self):
     schedule_items = filehandler.parse_schedules(uri='tests/data.csv')
     self.assertEquals(len(schedule_items), 34)