def test_summarize(monkeypatch): """ . """ ship = Ship() # pylint: disable=unused-argument monkeypatch.setattr(utils, "organize_components_by_classification", lambda components: []) monkeypatch.setattr( utils, "get_component_summary_by_classification", lambda components, func: "a description", ) assert ship.summarize() == "a description", "Ship summary returned"
def add_component(ship: Ship): """ Adds a component to the ship """ global LAST_MOD_ADDED component_map = {component.name: component for component in ALL_COMPONENTS} options = list(component_map.keys()) if "" in options: options.remove("") options.sort(key=lambda option: str(component_map[option]. component_classification) + option) component = inputs.make_choice("component", [None] + options, LAST_MOD_ADDED) if component: LAST_MOD_ADDED = component ship.add_component(component_map[component]())
def test_add_remove_components(monkeypatch): """ . """ ship = Ship() monkeypatch.setattr(BaseComponent, "configure", lambda self: None) power = PowerPlant() shield = ShieldGenerator() laser1 = BeamLaser() laser2 = BeamLaser() ship.add_component(power) ship.add_component(laser1) ship.add_component(shield) ship.add_component(laser2) assert ship.component_list == [ laser1, laser2, power, shield, ], "Component list correct" assert ship.outfitted == { power.name: power, shield.name: shield, laser1.name: [laser1, laser2], }, "Outfitted modules correct" ship.remove_component(laser1) ship.remove_component(shield) assert ship.component_list == [ laser2, power, ], "Component list correct post-removal" assert ship.outfitted == { power.name: power, laser1.name: [laser2], }, "Outfitted modules correct"
def remove_component(ship: Ship): """ Remove a component from the ship """ # NOTE: this will collapse multiple components with same configurations to one entry # NOTE: only one instance will be removed, so this is okay component_map = { str(component): component for component in ship.component_list } options = list(component_map.keys()) if "" in options: options.remove("") options.sort(key=lambda option: str(component_map[option]. component_classification) + option) component = inputs.make_choice("component", [None] + options, None) if component: ship.remove_component(component_map[component])
def save_shopping_list(ship: Ship, cmdr_name: str, grade_counts: Dict[int, int]) -> bool: """ Save the ship configuration to an output Returns True if saved and should exit, False otherwise """ output_file = inputs.single_prompt( "Output ship to file? (leave BLANK to return to editing) ", default="ship.shoppingList", ) if not output_file: return False if path.isfile(output_file): if not inputs.check_confirmation("Overwrite file?"): return False shopping_list = ship.to_shopping_list(cmdr_name, grade_counts) save_data_to_file(output_file, shopping_list) return True
def make_shopping_list(): """ Makes the actual shopping list """ cmdr = get_cmdr(sys.argv) count_per_grade = get_grade_counts() ship = Ship() while True: selected_action = inputs.get_action() print(selected_action) if selected_action == "Add": add_component(ship) elif selected_action == "Update": update_component(ship) elif selected_action == "Remove": remove_component(ship) elif selected_action == "Review": summarize_ship(ship) elif selected_action == "Done": summarize_ship(ship) if save_shopping_list(ship, cmdr, count_per_grade): break
def test_to_shopping_list(monkeypatch): """ . """ ship = Ship() monkeypatch.setattr(BaseComponent, "configure", lambda self: None) power = PowerPlant() power.max_modification_grade = 4 power.selected_modification = Modification.ARMOURED power.selected_effect = ExperimentalEffect.MONSTERED beam = BeamLaser() beam.max_modification_grade = 5 beam.selected_modification = Modification.EFFICIENT_WEAPON beam.selected_effect = ExperimentalEffect.THERMAL_VENT shield = ShieldGenerator() shield.max_modification_grade = 5 shield.selected_effect = ExperimentalEffect.FAST_CHARGE chaff = ChaffLauncher() chaff.max_modification_grade = 2 chaff.selected_modification = Modification.AMMO_CAPACITY ship.add_component(power) ship.add_component(beam) ship.add_component(shield) ship.add_component(chaff) grade_counts = {i: i for i in range(1, 6)} shopping_list = ship.to_shopping_list("cmdr", grade_counts) assert (shopping_list == "[" + ",".join([ beam.to_shopping_list("cmdr", grade_counts), chaff.to_shopping_list("cmdr", grade_counts), power.to_shopping_list("cmdr", grade_counts), shield.to_shopping_list("cmdr", grade_counts), ]) + "]"), "Shopping list correct"
def summarize_ship(ship: Ship): """ . """ print(ship.summarize())