def test_add_detachment(ui_setup): """Tests that a single detachment can be added to the army""" interface = ui_setup mock_input = [ "2", "Longstrike", # HQ 1 "3", # False input "Hello", # False Input "B2", # Crisis Commander "2", # Strike Team "b2", # False Input "1", # Breacher Team "Kroot Carnivores" ] userint.input = lambda x: mock_input.pop(0) interface.add_detachment() detach = interface.army.detachments[1] assert detach.units_dict["HQ"][0] == squad.Unit("Longstrike", "HQ") assert detach.units_dict["HQ"][1] == squad.Unit( "Commander in XV8 Crisis Battlesuit", "HQ") breachers = squad.Unit("Strike Team", "Troops") assert detach.units_dict["Troops"][0] == breachers breachers = squad.Unit("Breacher Team", "Troops") assert detach.units_dict["Troops"][1] == breachers breachers = squad.Unit("Kroot Carnivores", "Troops") assert detach.units_dict["Troops"][2] == breachers return
def test_ui_init(ui_setup): """Tests the initialisation of the User Interface""" interface = ui_setup detach = interface.army.detachments[0] assert detach.type == "Patrol" breachers = squad.Unit("Breacher Team", "Troops") assert detach.units_dict["HQ"][0] == squad.Unit("Aun'Shi", "HQ") assert detach.units_dict["Troops"][0] == breachers
def on_close(self, event): """ Event Handler for when the user closes the window by pressing either of the buttons. """ evt = event.GetEventObject().GetLabel() if evt == "Add": if wx.NOT_FOUND in { self.detach_combo.GetSelection(), self.foc_combo.GetSelection(), self.unit_choice.GetSelection() }: self.warntxt.SetLabel("Fill in all the fields") self.Layout() return detachment = self.army.detachments[ self.detach_combo.GetSelection()] battlefield_role = self.foc_combo.GetString( self.foc_combo.GetSelection()) unit_string = self.unit_choice.GetString( self.unit_choice.GetSelection()) unit = squad.Unit(unit_string, battlefield_role) detachment.add_unit(unit) self.GetParent().close_add_unit(unit) self.Destroy()
def test_reset(): """ Checks the Unit.reset() method returns the Unit back to its initial state """ mock_input = ["1b", 'no', 'y'] squad.input = lambda s: mock_input.pop(0) unit = squad.Unit("Immortals", "Troops") unit_copy = squad.Unit("Immortals", "Troops") unit.re_size(10) sel_option = unit.options[0] sel_option.select(1) unit.change_wargear([sel_option]) assert unit_copy.size != unit.size assert unit_copy.wargear != unit.wargear unit.reset() assert unit_copy.size == unit.size assert unit_copy.wargear == unit.wargear
def on_selection(self, evt): """Event Handler to add the selected unit to the army.""" if evt.GetItem() not in self.unit_nodes: return unit = self.tree.GetItemData(evt.GetItem()) battlefield_role = self.tree.GetItemParent(evt.GetItem()) battlefield_role = self.tree.GetItemText(battlefield_role) unit = squad.Unit(unit, battlefield_role) main_window = self.GetParent() main_window.add_unit_from_tree(unit) return
def test_add_unit(detach): """Checks adding a unit .""" unit = squad.Unit("Triarch Stalker", "Elites") detach.add_unit(unit) stalker = detach.units_dict["Elites"][0] assert stalker.name == "Triarch Stalker" assert stalker.pts == 171 assert set(stalker.wargear) == set([init.WargearItem("Heat ray"), init.WargearItem("Massive forelimbs")]) assert detach.pts == 456 + 171 return
def detach(): detach = army_list.Detachment("Patrol") units = [("Necron Warriors", "Troops"), ("Immortals", "Troops"), ("Overlord", "HQ"), ("Destroyers", "Fast Attack")] for unit in units: unit = squad.Unit(*unit) detach.add_unit(unit) unit.re_size(2, 1) return detach
def test_re_size(ui_setup): interface = ui_setup mock_input = [ "1", # Select Patrol "Troops", "1", "1,5" ] # Brecher Team userint.input = lambda x: mock_input.pop(0) breachers = squad.Unit("Breacher Team", "Troops") breachers.re_size(1, 5) interface.re_size_unit() detach = interface.army.detachments[0] assert detach.units_dict["Troops"][0] == breachers
def test_add_unit(ui_setup): """Tests that a single unit can be added to an existing detachment""" interface = ui_setup mock_input = [ "0", # False inputs "Hello", # False inputs "1", # Select Patrol "Elites", "8", # Stealth Suits "1.3" ] # Size Stealth Suits userint.input = lambda x: mock_input.pop(0) interface.add_unit() suits = squad.Unit("XV25 Stealth Battlesuit", "Elites") assert interface.army.detachments[0].units_dict["Elites"][0] == suits return
def test_re_size_mono_model(): """ Checks the Unit.re_size() method for unit containing one type of model """ warriors = squad.Unit("Necron Warriors", "Troops") warriors.re_size(15) # check valid input modifies the unit points assert warriors.pts == 180 assert warriors.models[0].size == 15 assert warriors.size == 15 # check programmer input raises the correct errors warriors.re_size(10) assert warriors.pts == 120 assert warriors.size == 10 return
def test_save_unit(unit): """Checks that units are saved in the correct dictionary format.""" save = unit.save() assert save == { "type": "Destroyers", "size": 3, "wargear": None, "models": [i.save() for i in unit.models], "name": None } unit2 = squad.Unit(save, "Fast Attack") print(unit2) print(unit) assert unit == unit2 return
def test_change_wargear(): """Checks the Unit.change_wargear() method""" unit = squad.Unit("Catacomb Command Barge", "HQ") choices = [(0, 1), (1, 2), (2, 0), (3, 0)] wargear_to_add = [] for choice in choices: sel_option = unit.options[choice[0]] sel_option.select(choice[1]) wargear_to_add.append(sel_option) unit.change_wargear(wargear_to_add) wargear_selected = [ init.WargearItem("Tesla cannon"), init.WargearItem("Hyperphase sword"), init.WargearItem("Phylactery"), init.WargearItem("Resurrection orb") ] for i in wargear_selected: assert i in unit.wargear
def load(self, loaded_dict): """ Loads the detachment from a pre-made dictionary. Parameters ---------- loaded_dict: dict {"type": str, "name": str, "units_dict":{"HQ": [unit_saves...]...}} dictionary of the base data required to re-construct the detachment. """ self.type = loaded_dict["type"] if loaded_dict["name"] is None: self.__name = self.type else: self.__name = loaded_dict["name"] self.__default_name = False for foc_role, unit_list in self.__units_dict.items(): self.__units_dict[foc_role] = [ squad.Unit(i, foc_role) for i in loaded_dict["units"][foc_role] ] for unit in self.__units_dict[foc_role]: unit.parent = self return
def test_add_multiple_detachments(ui_setup): """Tests that multiple detachments can be added at once to the army""" interface = ui_setup mock_input = [ "2, 1", "Longstrike", # HQ 1 "B2", # Crisis Commander "2", # Strike Team "bip", # size strike team "1", # Breacher Team "Kroot Carnivores", "Commander in XV85 Enforcer Battlesuit", "Kroot Carnivores" ] userint.input = lambda x: mock_input.pop(0) interface.add_detachment() print(interface.army) detach = interface.army.detachments[1] assert detach.units_dict["HQ"][0] == squad.Unit("Longstrike", "HQ") assert detach.units_dict["HQ"][1] == squad.Unit( "Commander in XV8 Crisis Battlesuit", "HQ") breachers = squad.Unit("Strike Team", "Troops") assert detach.units_dict["Troops"][0] == breachers breachers = squad.Unit("Breacher Team", "Troops") assert detach.units_dict["Troops"][1] == breachers breachers = squad.Unit("Kroot Carnivores", "Troops") assert detach.units_dict["Troops"][2] == breachers detach = interface.army.detachments[2] assert detach.units_dict["HQ"][0] == squad.Unit( "Commander in XV85 Enforcer Battlesuit", "HQ") assert detach.units_dict["Troops"] == [ squad.Unit("Kroot Carnivores", "Troops") ] return
def test_squad(): """Checks the attributes of the units class""" warriors = squad.Unit("Necron Warriors", "Troops") assert warriors.pts == 120 assert warriors.wargear == [init.WargearItem("Gauss flayer")] return
def _create_user_unit(self, battlefield_role): """Gets the user-chosen unit to create for the given battlefield_role""" print( "\nWhich {} unit would you like to add?".format(battlefield_role)) # if HQ add named characters as well if battlefield_role == "HQ": print("Named Characters (Including Wargear):") keys = list(init.units_dict["Named Characters"].keys()) top_len = len(max(keys, key=len)) for index, [keys, value] in enumerate( init.units_dict["Named Characters"].items()): print("A" + str(index + 1) + ". " + keys.ljust(top_len) + "\t({}pts)".format(value["pts"])) print('') # create space between set of options print("Other Characters (Including base Wargear):") units = list(init.units_dict[battlefield_role].keys()) top_len = len(max(units, key=len)) for index, [keys, value] in enumerate( init.units_dict[battlefield_role].items()): print("B" + str(index + 1) + ". " + keys.ljust(top_len) + "\t({}pts)".format(value["pts"])) else: # print available models and their points with the points value # left adjusted so they are in the same column print("Available Models (Including base Wargear):") units = list(init.units_dict[battlefield_role].keys()) top_len = len(max(units, key=len)) for index, [keys, value] in enumerate( init.units_dict[battlefield_role].items()): print( str(index + 1) + ". " + keys.ljust(top_len) + "\t({}pts for {} models)".format( value["pts"] * value["size"][0], value["size"][0])) user_input = input(">> ") try: if user_input.lower() in {'q', 'exit', 'cancel', 'quit', 'return'}: return False elif re.match('([aAbB][1-9][0-9]*)|([1-9][0-9]*)', user_input): if battlefield_role == "HQ": if user_input[0] in {'A', 'a'}: user_input = list( init.units_dict["Named Characters"].keys())[ int(user_input[1:]) - 1] elif user_input[0] in {'B', 'b'}: user_input = list( init.units_dict["HQ"].keys())[int(user_input[1:]) - 1] elif user_input[0].isdigit(): user_input = list( init.units_dict[battlefield_role].keys())[ int(user_input) - 1] return squad.Unit(user_input, battlefield_role) except (KeyError, IndexError): print( "{} is not a valid option, please select the unit by name or input" .format(user_input)) print("To quit please enter 'q'") unit = self._create_user_unit(battlefield_role) return unit
def unit(): unit = squad.Unit("Destroyers", "Fast Attack") unit.re_size(2, 1) return unit
def model(): unit = squad.Unit("Destroyers", "Fast Attack") model = squad.Model(unit, "Heavy Destroyer") return model