def test_pickup(self): player = players.Thief() #If scroll learn it #If weapon equip it - if no weapon equipped and proficient #If armor equip it - if no armor equipped and proficient #Scroll scroll = MockHelper.get_mock_scroll() player.learn_spell = Mock(return_value=True) self.assertTrue(player.pickup(scroll)) player.learn_spell.assert_called_once() #Weapon weapon = MockHelper.get_mock_weapon() weapon.get_modifier_value = Mock(return_value=0) #Not proficient player.character_class.is_weapon_proficient = Mock(return_value=False) self.assertFalse(player.has_weapon_equipped()) self.assertTrue(player.pickup(weapon)) self.assertFalse(player.has_weapon_equipped()) self.assertNotEqual(player.get_equipped_weapon(), weapon) #Proficient player.character_class.is_weapon_proficient = Mock(return_value=True) self.assertFalse(player.has_weapon_equipped()) self.assertTrue(player.pickup(weapon)) self.assertTrue(player.has_weapon_equipped()) self.assertEqual(player.get_equipped_weapon(), weapon) #Already equipped another_weapon = MockHelper.get_mock_weapon() self.assertTrue(player.pickup(another_weapon)) self.assertTrue(player.has_weapon_equipped()) self.assertEqual(player.get_equipped_weapon(), weapon) #Armor myarmor = MockHelper.get_mock_armor() myarmor.get_modifier_value = Mock(return_value=0) #Not proficient player.character_class.is_armor_proficient = Mock(return_value=False) self.assertFalse(player.has_armor_equipped()) self.assertTrue(player.pickup(myarmor)) self.assertFalse(player.has_armor_equipped()) self.assertNotEqual(player.get_equipped_armor(), myarmor) #Proficient player.character_class.is_armor_proficient = Mock(return_value=True) self.assertFalse(player.has_armor_equipped()) self.assertTrue(player.pickup(myarmor)) self.assertTrue(player.has_armor_equipped()) self.assertEqual(player.get_equipped_armor(), myarmor) #Already equipped another_armor = MockHelper.get_mock_armor() self.assertTrue(player.pickup(another_armor)) self.assertTrue(player.has_armor_equipped()) self.assertEqual(player.get_equipped_armor(), myarmor)
def test_items(self): player = Mock() inventory = standard_items.Inventory(player) #Nothing in inventory self.assertEqual(inventory.items(), []) beer = MockHelper.get_mock_beer() self.assertTrue(inventory.add(beer)) self.assertTrue(inventory.add(MockHelper.get_mock_beer())) self.assertEqual(inventory.items(), [beer]) scroll = MockHelper.get_mock_scroll() self.assertTrue(inventory.add(scroll)) self.assertTrue(inventory.add(MockHelper.get_mock_scroll())) self.assertEqual(inventory.items(), [beer, scroll])
def test_loot_body(self): player = players.Thief() rat = players.Rat() zombie_rat = players.ZombieRat() another_rat = players.Rat() #Inventory is empty #Is looted #Inventory has 1 item #Inventory has 2 items #Empty self.assertEqual(player.loot_body(rat), []) #Already looted self.assertFalse(player.loot_body(rat)) penny = MockHelper.get_mock_item() quarter = MockHelper.get_mock_scroll() #1 item self.assertTrue(zombie_rat.pickup(penny)) self.assertEqual(player.loot_body(zombie_rat), [penny]) self.assertTrue(player.is_carrying(penny)) self.assertFalse(zombie_rat.is_carrying(penny)) #2 items self.assertTrue(another_rat.pickup(penny)) self.assertTrue(another_rat.pickup(quarter)) self.assertEqual(player.loot_body(another_rat), [penny, quarter]) self.assertTrue(player.is_carrying(penny)) self.assertTrue(player.is_carrying(quarter)) self.assertFalse(another_rat.is_carrying(penny)) self.assertFalse(another_rat.is_carrying(quarter))
def test_weight(self): player = Mock() inventory = standard_items.Inventory(player) self.assertEqual(inventory.weight, 0) beer = MockHelper.get_mock_beer() scroll = MockHelper.get_mock_scroll() inventory.add(beer) self.assertEqual(inventory.weight, 1) inventory.add(beer) self.assertEqual(inventory.weight, 2) inventory.add(scroll) self.assertEqual(inventory.weight, 3) inventory.remove(scroll) self.assertEqual(inventory.weight, 2)