def list_of_items(): nokia_phone = Item(name="Nokia Phone", weight=1, value=100, itype=Item_Type.Weapon) stick = Item(name="A nice stick", weight=12, value=13, itype=Item_Type.Weapon) coffee = Item(name="3 Liters of Coffee", weight=3, value=20, itype=Item_Type.Consumable) Ear = Item(name="Enemy's Ear", weight=1, value=1, itype=Item_Type.Consumable) silly_hat = Item(name="Silly hat", weight=5, value=34, itype=Item_Type.Gear) return [nokia_phone,stick,coffee,Ear,silly_hat]
def loaded_inventory(): """ Creates an inventory already loaded with items """ inventory = Inventory() nokia_phone = Item(name="Nokia Phone", weight=1, value=100, itype=Item_Type.Weapon) stick = Item(name="A nice stick", weight=12, value=13, itype=Item_Type.Weapon) coffee = Item(name="3 Liters of Coffee", weight=3, value=20, itype=Item_Type.Consumable) Ear = Item(name="Enemy's Ear", weight=1, value=1, itype=Item_Type.Consumable) silly_hat = Item(name="Silly hat", weight=5, value=34, itype=Item_Type.Gear) inventory.pickup(nokia_phone) inventory.pickup(coffee) inventory.pickup(silly_hat) inventory.pickup(stick) inventory.pickup(Ear) return inventory
def test_consumable(): item = Item(name="my gear", weight=43, value=65, itype=Item_Type.Gear) assert item.type == Item_Type.Gear assert item.name == "my gear" assert item.weight == 43 assert item.value == 65 assert item.id == "my gear<Item_Type.Gear: 1>"
def test_weapon(): item = Item(name="my weapon", weight=10, value=20, itype=Item_Type.Weapon) assert item.type == Item_Type.Weapon assert item.name == "my weapon" assert item.weight == 10 assert item.value == 20 assert item.id == "my weapon<Item_Type.Weapon: 0>"
def medium_item(): """ Creates a medium item weight=20, value=5 """ return Item(name="Heavy item", weight=20, value=5, itype=Item_Type.Consumable)
def test_consumable(): item = Item(name="my consumable", weight=13, value=32, itype=Item_Type.Consumable) assert item.type == Item_Type.Consumable assert item.name == "my consumable" assert item.weight == 13 assert item.value == 32 assert item.id == "my consumable<Item_Type.Consumable: 2>"
def test_inventory_pickup(): # Test pick up one item empty_inventory = Inventory() item_small = Item(name="Test item", weight=1, value=1) assert empty_inventory.pickup(item_small) # Test inventory full for x in range(24): empty_inventory.pickup(item_small) assert empty_inventory.get_totalnr_items() == 25 assert empty_inventory.current_weight() == 25 assert not empty_inventory._itemlist_freespace() with pytest.raises(InvalidQuantityException, match=r"Inventory full") as ex: empty_inventory.pickup(item_small)
def test_basic_item(): item = Item() assert item.type == Item_Type.Weapon assert item.name == "None" assert item.weight == 0 assert item.value == 0
def heavy_item(): """ Creates a heavy and expensive item weight=99, value=99 """ return Item(name="Heavy item", weight=99, value=99, itype=Item_Type.Gear)
def item_weapon(): """ Creates an light item weight=1, value=1 """ return Item(name="Test item", weight=1, value=1)