def test_load_army(detach): """Tests the army can be loaded from the file correctly.""" army1 = army_list.ArmyList("./tests/test_army.army", True) army2 = army_list.ArmyList("Necron") army2.add_detachment(detach) for detachment in army1.detachments: assert detachment.parent == army1 assert army1.faction == army2.faction assert army1.detachments == army2.detachments
def test_army_list(): """ Checks adding of simple detachments and minimum requirement units in different formats """ army = army_list.ArmyList("Necron") assert army.faction == "Necron" army = army_list.ArmyList("Tau") assert army.faction == "Tau" return
def test_save_army(detach): """Tests the army can be saved to a file.""" army = army_list.ArmyList("Necron") army.add_detachment(detach) save = army.save("./tests/test_army.army") assert save == {"faction": "Necron", "detachments": [i.save() for i in army.detachments]} return
def test_auto_naming(): """Checks the automatic numbering of repeated detachment types""" army = army_list.ArmyList("Necron") detach1 = army_list.Detachment("Patrol") detach2 = army_list.Detachment("Patrol") detach3 = army_list.Detachment("Patrol") army.add_detachment(detach1) army.add_detachment(detach2) army.add_detachment(detach3) for i in range(len(army.detachments)): assert army.detachments[i].name == "Patrol {}".format(i + 1) assert army.detachment_names == ['Patrol 1', 'Patrol 2', 'Patrol 3'] return
def test_add_detachment(): """Checks that combinations of inputs create valid detachments""" detach = army_list.Detachment("Patrol") army = army_list.ArmyList("Necron") army.add_detachment(detach) assert army.cp == 0 detach = army_list.Detachment("Battalion") army.add_detachment(detach) assert army.cp == 5 for detach, type in zip(army.detachments, ["Patrol", "Battalion"]): assert detach.type == type try: detach = army_list.Detachment("ERROR") raise RuntimeError("Should have raised an error by this point") except KeyError: pass return