def _update_competitors(self): worthy_competitors = self._get_worthy_competitors() for competitor in self._competitors: try: utils.sorted_list_get_with_key(worthy_competitors, competitor.kingdom.name) except ValueError: competitor.is_competing = False self._competitors = worthy_competitors
def test_register_competitors(input_mock, southeros_ballot): southeros_ballot.register_competitors() assert southeros_ballot._competitors == [ utils.sorted_list_get_with_key(southeros_ballot._ballot_kingdoms, "Air"), utils.sorted_list_get_with_key(southeros_ballot._ballot_kingdoms, "Land"), ] for competitor in southeros_ballot._competitors: assert competitor.is_competing
def _get_kingdom(self, kingdom_name: str) -> Kingdom: kingdom_name = kingdom_name.capitalize() try: kingdom = utils.sorted_list_get_with_key(self._kingdoms, kingdom_name) except ValueError: raise ValueError( "Kingdom '{}' is not part of the '{}' universe".format( kingdom_name, self.name)) return kingdom
def register_competitors(self): if self._competitors: raise RuntimeError("Registration for the competition is now closed!") print("Enter the kingdoms competing to be the ruler:") self._competitors = [ utils.sorted_list_get_with_key(self._ballot_kingdoms, competitor_name) for competitor_name in self._process_input(input("Input: ")) ] print() for competitor in self._competitors: competitor.is_competing = True
def test_kingdoms_getter(westeros): kingdoms = westeros.kingdoms for kingdom in kingdoms: original_kingdom = utils.sorted_list_get_with_key(westeros._kingdoms, kingdom.name) assert kingdom is not original_kingdom
def test__get_kingdom(westeros): assert westeros.get_kingdom("Stark") == utils.sorted_list_get_with_key(westeros._kingdoms, "Stark") with pytest.raises(ValueError): assert westeros.get_kingdom("Tully")
def test_sorted_list_get_with_key(): sorted_list = SortedKeyList([(1, 3), (2, 2), (3, 1)], key=lambda x: x[1]) assert utils.sorted_list_get_with_key(sorted_list, 1) == (3, 1) assert utils.sorted_list_get_with_key(sorted_list, 2) == (2, 2) with pytest.raises(ValueError): utils.sorted_list_get_with_key(sorted_list, 10)