Пример #1
0
def test_key_can_open():
    """Tests that a key object calls openable"""
    test_key = types.Item()
    test_door = types.Item()
    test_door.name = "rock"
    test_key.make({
        "name": "test key",
        "description": "jingly keys",
        "type": "key"
    })
    test_key.set_usable(test_key.type)
    out = test_key.use(test_door, test_key.name)
    assert "You insert the test key into rock" in out,\
           "use method failed for key items"
Пример #2
0
def test_use_not_in_uses():
    """Checks if types unrecognized are unusable"""
    test_item = types.Item()
    test_item.type = "yargle has come to bargle"
    test_item.set_usable(test_item.type)
    assert test_item.usable == types.NotUsable,\
        "Failed to set NotUsable on unknown type item"
Пример #3
0
def test_legendary_items():
    """Makes sure legendary items are attackable"""
    test_item = types.Item()
    test_item.type = "legendary bacon"
    test_item.set_usable(test_item.type)
    assert test_item.usable == types.Attackable,\
        "legendary item failed to be attackable"
Пример #4
0
def test_inventory_has_item(mocker):
    """testing the inventory function
    """
    mocked_input = mocker.patch('builtins.input')
    mocked_input.side_effect = ["bobby b"]
    test_game = types.Gamebuilder.build('bobby b')
    test_item = types.Item()
    test_item.name = "wobblelobbledobdob"
    test_game.hero.inventory[test_item.name] = test_item
    assert test_item.name in test_game.hero.inventory,\
        "Failed to store items in inventory"
Пример #5
0
def test_none_item():
    """Checks that an object with none is unusable"""
    test_key = types.Item()
    test_key.make({
        "name": "empty thing",
        "description": "nothin",
        "type": None
    })
    out = test_key.use("player", "player")
    assert "You find no use of this item" in out,\
           "use method failed for gold items"
Пример #6
0
def test_sword_can_swing():
    """Tests that a sword object calls swingable"""
    test_sword = types.Item()
    test_player = types.Player()
    test_player.name = "player"
    test_sword.name = "sword"
    test_sword.type = "weapon "
    test_sword.usable = types.Attackable
    assert "You swing the sword at player"\
        in test_sword.use(test_player, "sword"),\
           "use method failed for sword items"
Пример #7
0
def test_gold_can_pay():
    """Checks that a gold object calls payable"""
    test_key = types.Item()
    test_player = types.Player()
    test_player.name = "player"
    test_key.make({
        "name": "bag 'o MOLTEN GOOOLD",
        "description": "der bee gould een dem der bag",
        "type": "gold"
    })
    test_key.set_usable(test_key.type)
    out = test_key.use(test_player, test_key.name)
    assert "You use the bag 'o MOLTEN GOOOLD to pay player" in out,\
           "use method failed for gold items"
Пример #8
0
def test_potion_can_speed_up():
    """Tests that a stat changing object calls statable"""
    test_potion = types.Item()
    test_player = types.Player()
    test_player.name = "player"
    test_potion.make({
        "name": "test potion",
        "description": "Looks like booze to me",
        "type": "magic items"
    })
    test_potion.set_usable(test_potion.type)
    out = test_potion.use(test_player, test_potion.name)
    assert "The test potion takes effect on player" in out,\
           "use method failed for stat changing items"
Пример #9
0
def test_only_stat(mocker):
    """Checks that an object with only a stat is unusable"""
    with mocker.patch('builtins.input') as inpt:
        inpt.side_effect = ["player"]
        test_key = types.Item()
        test_player = types.Player()
        test_player.name = "player"
        test_key.make({
            "name": "empty thing",
            "description": "nothin",
            "type": 1
        })
        out = test_key.use(test_player, "empty thing")
        assert out == ("You find no use of this item"),\
            "use method failed for gold items"
Пример #10
0
def test_set_use_not_str():
    """Tests that unkown object becomes filled in usable"""
    test_item = types.Item()
    test_item.set_usable(object)
    assert test_item.usable == types.NotUsable,\
        "Failed to set unknown object use to notusable"
Пример #11
0
def test_type_not_str_item_make():
    """Tests that empty dict creates unusable filler item"""
    test_item = types.Item()
    test_item.make({"type": {}})
    assert test_item.usable == types.NotUsable,\
        "Failed to set empty string item to NotUsable"