def get_hands(): unavailable_cards = [] hands = {} for player_i in range(basic_utils.ask_int("How many human players?\n")): hand = request_cards(str(player_i + 1)) hands["p" + str(player_i)] = hand unavailable_cards += hand missing_card = select_card(excluded=unavailable_cards) hands["missing"] = missing_card unavailable_cards.append(missing_card) comp_card_amount = basic_utils.ask_int("How many cards for the computer?\n") hands["comp"] = select_cards(comp_card_amount, unavailable_cards) hands["extra"] = [] for _ in range(36 - len(unavailable_cards)): card = select_card(excluded=unavailable_cards) hands["extra"].append(card) unavailable_cards.append(card) save_cards(hands) basic_utils.clear_screen() return hands
def test_ask_int_with_invalid_int_as_input(self): """ Tests that ask_int returns an int by passing an invalid int and then a valid int, both in the form of a string""" expected = "test error message\n" with pcutils.MockInput( ["a", "2"], loop=False), pcutils.MockPrint() as mocked_print: self.assertEqual( 2, basic_utils.ask_int("", error_message="test error message")) self.assertEqual(expected, mocked_print.stdout)
def test_ask_int_with_valid_int_as_input(self): """ Tests that ask_int returns an int by passing a valid int in the form of a string""" with pcutils.MockInput(["1", "2"]): self.assertEqual(1, basic_utils.ask_int(""))