示例#1
0
 def test_fits_isolated(self, volume_mock):
     volume_mock.return_value = 10
     # get_box_volume is mocked so radius doesn't matter anymore
     self.assertFalse(
         fits([Basketball(1), Basketball(1),
               Basketball(1)], 25), "Doesn't work if volume is 10")
     # We made sure user calls get_box_volume and doesn't calculate volume in fits_or_not function
     self.assertEqual(volume_mock.call_count, 3,
                      "Are you calling get_box_volume()")
示例#2
0
 def sport_command(*args):
     """
     After choosing 1 sport retrieve a leagues list
     :param args:
     :return:
     """
     b1.state(['disabled'])
     if sportName.get() == '':
         sentlbl.config(text="Please choose 1 sport from above")
         b1.state(['!disabled'])
         return
     sentlbl.config(text="Please wait..")
     sentlbl.update_idletasks()
     global sport
     if sportName.get() == 'tennis':
         sport = Tennis(sportName.get())
     elif sportName.get() == 'basket':
         sport = Basketball(sportName.get())
     else:
         sport = Football(sportName.get())
     lst = sport.get_leagues()
     leagueList.set(lst)
     for i in range(0, len(lst), 2):
         list1.itemconfigure(i, background='#f0f0ff')
     sentlbl.config(text='')
     list1.bind('<Double-1>', show_games)
    async def get_games_v1(testing: bool):
        game_sets = await asyncio.gather(*[
            CollegeBasketball.get_games(testing),
            Basketball.get_games(testing),
            Hockey.get_games(testing),
            Baseball.get_games(testing),
            Football.get_games(testing),
            CollegeFootball.get_games(testing),
        ])
        flatten_list = [game for game_set in game_sets for game in game_set]

        return flatten_list
    async def get_games_v4(testing: bool):
        print("[ALL] Beginning fetching all sports")
        game_sets = await asyncio.gather(*[
            Golf.get_games(testing),
            CollegeBasketball.get_games(testing),
            Basketball.get_games(testing),
            Hockey.get_games(testing),
            Baseball_v2.get_games(testing),
            Football_v2.get_games(testing),
            CollegeFootball_v2.get_games(testing),
        ])
        print("[ALL] Finished fetching all sports")
        flatten_list = [game for game_set in game_sets for game in game_set]

        return flatten_list
示例#5
0
    def test_fits(self):
        self.assertTrue(
            fits([Basketball(1), Basketball(1),
                  Basketball(1)], 25),
            "Doesn't work if there are 3 balls with radius=1")

        self.assertFalse(
            fits([Basketball(2), Basketball(5)], 1000),
            "Doesn't work if there are 2 balls with radius=2 and radius=5")

        self.assertTrue(fits([Basketball(5)], 1000),
                        "Doesn't work if there is 1 ball with radius=5")
def lambda_handler(event, context):
    # First, hit the cache
    loop = asyncio.get_event_loop()
    print(event)
    sport = event["path"][1:]
    if sport in cache:
        item, timestamp = cache[sport]
        if time.time() - timestamp < REFRESH_WINDOW:
            return success_response(item)

    if sport == "college-basketball":
        result = wrap_games(loop.run_until_complete(CollegeBasketball.get_games(False)))
    elif sport == "basketball":
        result = wrap_games(loop.run_until_complete(Basketball.get_games(False)))
    elif sport == "hockey":
        result = wrap_games(loop.run_until_complete(Hockey.get_games(False)))
    elif sport == "college_football":
        result = wrap_games(loop.run_until_complete(CollegeFootball.get_games(False)))
    elif sport == "football":
        result = wrap_games(loop.run_until_complete(Football.get_games(False)))
    elif sport == "baseball":
        result = wrap_games(loop.run_until_complete(Baseball.get_games(False)))
    elif sport == "baseball_v2":
        result = wrap_games(loop.run_until_complete(Baseball_v2.get_games(False)))
    elif sport == "golf":
        result = wrap_games(loop.run_until_complete(Golf.get_games(False)))
    elif sport == "all":
        result = wrap_games(loop.run_until_complete(All.get_games_v1(False)))
    elif sport == "all_v2":
        result = wrap_games(loop.run_until_complete(All.get_games_v2(False)))
    elif sport == "all_v3":
        result = wrap_games(loop.run_until_complete(All.get_games_v3(False)))
    elif sport == "all_v4":
        result = wrap_games(loop.run_until_complete(All.get_games_v4(False)))
    else:
        result = None

    if result is not None:
        cache[sport] = (result, time.time())
        return success_response(result)

    print(f"ERROR: unknown sport {sport}")
    return None
示例#7
0
 def test_get_box_volume(self):
     ball = Basketball(1)
     self.assertEqual(8, ball.get_box_volume(), 
         "get_box_volume() fails if radius is 1")
示例#8
0
def basketball():
    return {"data": {"games": loop.run_until_complete(Basketball.get_games(testing))}}
示例#9
0
 def test_get_box_volume(self):
     ball = Basketball(1)
     self.assertEqual(8, ball.get_box_volume(),
                      "get_box_volume() fails if radius is 1")