Exemple #1
0
def test_change_wargear(ui_setup):
    interface = ui_setup
    mock_input = [
        "1",  # Select Patrol
        "Elites",
        "7"
    ]  # Riptide
    userint.input = lambda x: mock_input.pop(0)
    interface.add_unit()  # add changeable unit

    mock_input = [
        "1",
        "Elites",
        "Hello",  # False input
        "1",
        "1a 2b 3a, 3c"
    ]
    userint.input = lambda x: mock_input.pop(0)
    interface.change_unit_wargear()
    riptide = interface.army.detachments[0].units_dict["Elites"][0]
    wargear_added = [
        init.WargearItem("2*Smart missile system"),
        init.WargearItem("Ion accelerator"),
        init.WargearItem("Greater advanced targeting system"),
        init.WargearItem("Drone controller")
    ]
    for i in wargear_added:
        assert i in riptide.wargear

    assert len(wargear_added) == len(riptide.wargear)
Exemple #2
0
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
Exemple #3
0
def test_Option_class():
    """
    Checks list facilities in the Options class and that the object can be
    inialised successfully
    """
    init.init("Necron")
    item_list = [
        init.WargearItem("Tesla carbine"),
        init.WargearItem("Gauss cannon"),
        init.WargearItem("Gauss blaster")
    ]
    option = option_parser.Option(item_list)
    assert item_list[1] == option[1]
    for i, j in enumerate(option):
        assert j == item_list[i]
Exemple #4
0
def test_re_size_poly_model(unit):
    """
    Checks the Unit.test_resize() method for unist containing multiple models
    """
    # check that changes no applied to the whole unit creates a new model
    assert unit.size == 3
    assert unit.models[0].size == 2
    assert unit.models[1].wargear == [init.WargearItem("Heavy gauss cannon")]

    # check that when re-sizing and repeating the existing extra model is modified
    size = (5, 1)
    unit.re_size(*size)
    assert unit.size == 6
    assert unit.models[0].size == 5
    assert unit.models[1].wargear == [init.WargearItem("Heavy gauss cannon")]
    return
Exemple #5
0
def test_add_WargearItem():
    """Checks add functionality between wargear items behaves as desired."""
    sword = init.WargearItem("Hyperphase sword")
    shield = init.WargearItem("Dispersion shield")
    combined = sword + shield

    assert combined.pts == 15
    assert combined.item == ["Hyperphase sword", "Dispersion shield"]
    assert combined.no_of == 1

    blaster = init.WargearItem("Gauss blaster")
    combined += blaster
    assert combined.pts == 15 +9
    assert combined.item == ["Hyperphase sword", "Dispersion shield",
                             "Gauss blaster"]
    assert combined.no_of == 1
    return
Exemple #6
0
def test_init_Model(model):
    """Checks that a model can be initialised."""
    assert model.pts == 30 + 27
    assert model.type == "Heavy Destroyer"
    assert model.type == "Heavy Destroyer"
    assert model.wargear == [init.WargearItem("Heavy gauss cannon")]
    assert model.limit == 1
    return
Exemple #7
0
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
Exemple #8
0
def test_save_Model(model):
    """Checks that models are saved in the correct dictionary format."""
    save = model.save()
    assert save == {
        "type": "Heavy Destroyer",
        "size": 1,
        "wargear": [init.WargearItem("Heavy gauss cannon").save()]
    }

    model1 = squad.Model(model.parent, save)
    print(model)
    print(model1)
    assert model == model1
Exemple #9
0
def test_mult_WargearItem():
    """Checks multiplication and set_no_of() work."""
    item = init.WargearItem("Gauss blaster")
    assert item.pts == 9
    item *= 2
    assert item.pts == 18
    assert item.no_of == 2

    item.set_no_of(5)
    assert item.pts == 5*9
    assert item.no_of == 5
    try:
        item = item*item
        raise AssertionError("Error should have raised by now")
    except TypeError:
        pass
    return
Exemple #10
0
    def __init__(self, type):
        self.parent = None
        self.treeid = None
        self.__name = None
        self.__parsed = False
        if isinstance(type, dict):  # data is being loaded
            self.__type = type["type"]
            source = type["wargear"]
        else:
            self.__type = type
            source = self.root_data["wargear"]

        if source is not None:
            self.__wargear = list(
                map(
                    lambda x: init.MultipleItem(x.split('+'))
                    if '+' in x else init.WargearItem(x), source))
        else:
            self.__wargear = None
        return
Exemple #11
0
    def load(self, loaded_dict):
        """Loads the unit from a pre-made dictionary."""
        self.__type = loaded_dict["type"]
        if loaded_dict["wargear"] is None:
            self.__wargear = None
        else:
            self.__wargear = list(
                map(
                    lambda x: init.MultipleItem(x.split('+'))
                    if '+' in x else init.WargearItem(x),
                    loaded_dict["wargear"]))

        try:
            # first condition will raise KeyError for models
            if loaded_dict["models"] is not None:
                self.__models = [Model(self, i) for i in loaded_dict["models"]]
            if loaded_dict["name"] is None:
                self.__name = self.type
            else:
                self.__name = loaded_dict["name"]
                self.__default_name = False

        except KeyError:
            pass
Exemple #12
0
 def t_ITEM(self, t):
     r'[a-zA-Z_][\w -]*[\w]+[\w]'
     t.value = init.WargearItem(t.value)
     return t
Exemple #13
0
def test_save_WargearItem():
    item = init.WargearItem("Gauss blaster")
    item *= 2
    assert item.save() == "2*Gauss blaster"
    return
Exemple #14
0
def test_init_WargearItem():
    """Checks that items can be created properly"""
    for cat, wargear_list in init.armoury_dict.items():
        for i in wargear_list:
            item = init.WargearItem(i)
Exemple #15
0
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