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_default_weapon(self): import questgame.game_items.weapons as weapons player = players.Thief() self.assertTrue(isinstance(player.default_weapon, weapons.Fists)) player = players.Rat() self.assertTrue(isinstance(player.default_weapon, weapons.Claws))
def test_default_armor(self): import questgame.game_items.armor as armor player = players.Thief() self.assertTrue(isinstance(player.default_armor, armor.BodyArmor)) player = players.Rat() self.assertTrue(isinstance(player.default_armor, armor.FurArmor))
def test_throw(self): player = players.Thief() rat = players.Rat() dagger = MockHelper.get_mock_weapon() not_a_dagger = MockHelper.get_mock_item() #Must be carrying item #Item must be a throwable weapon #Should decrease number of items when thrown #If none left then no longer carrying #Not carrying player.is_carrying = Mock(return_value=False) self.assertFalse(player.throw(dagger, rat)) player.is_carrying.assert_called_once() #Not a weapon #TODO: Allow food to be thrown? player.is_carrying = Mock(return_value=True) self.assertFalse(player.throw(not_a_dagger, rat)) #Not throwable #Mock class methods mock_is_throwable = PropertyMock(return_value=True) type(dagger).is_throwable = mock_is_throwable self.assertTrue(player.throw(dagger, rat)) mock_is_throwable.assert_called_once()
def test_get_equipped_weapon(self): player = players.Thief() rat = players.Rat() #Just returns currently assigned armor self.assertEqual(player.get_equipped_weapon(), player.default_weapon) #TODO: Probably shouldn't allow this.... player.is_carrying = Mock(return_value=True) self.assertTrue(player.equip_weapon(rat.default_weapon)) self.assertEqual(player.get_equipped_weapon(), rat.default_weapon)
def test_cast(self): #Cast a spell player = players.Thief() rat = players.Rat() spell = Mock() spell.cast = Mock(return_value=True) #Calls spell.cast which returns true or false which is passed through self.assertTrue(player.cast(spell, rat)) spell.cast = Mock(return_value=False) self.assertFalse(player.cast(spell, rat))
def test_strike(self): player = players.Thief() rat = players.Rat() #Can't act with MockHelper.Property(player, 'can_act', return_value=False) as mock_can_act: self.assertFalse(player.strike(rat)) mock_can_act.assert_called_once() mock_can_act.return_value = True strike = player.strike(rat) self.assertIsNotNone(strike.damage)
def test_skill_attack(self): player = players.Thief() backstab = Mock() rat = players.Rat() backstab.damage = Mock(return_value=2) #Doesn't have skill player.has_skill = Mock(return_value=False) self.assertFalse(player.skill_attack(backstab, rat)) player.has_skill.assert_called_once() #Doesn't have skill player.has_skill = Mock(return_value=True) self.assertTrue(player.skill_attack(backstab, rat))
def test_give(self): player = players.Thief() rat = players.Rat() penny = MockHelper.get_mock_item() #Can give player.is_carrying = Mock(return_value=True) player.remove_item = Mock(return_value=True) self.assertTrue(player.give(penny, rat)) #Not carrying player.is_carrying = Mock(return_value=False) self.assertFalse(player.give(penny, rat)) #Can't remove player.is_carrying = Mock(return_value=True) player.remove_item = Mock(return_value=False) self.assertFalse(player.give(penny, rat))
def on_search_item(self, item, found_items): if item.name == 'straw' and len(found_items) > 0: rat = players.Rat() rat.inventory.add(items.StrengthRing()) rat.inventory.add(items.LockPick()) self._add_monster(rat)
def test_is_monster(self): player = players.Thief() monster = players.Rat() self.assertTrue(monster.is_monster) self.assertFalse(player.is_monster)
def test_get_reply_key(self): player = players.Thief() rat = players.Rat() self.assertEqual(player.get_reply_key('key'), 'player_key') self.assertEqual(rat.get_reply_key('key'), 'monster_key')