def test_entry_allowed(self, mock_verify_entry): mock_verify_entry.return_value = True my_hero = Hero(room=Room('Init Room')) move_room = Room('Move room', condition_to_enter=Obj.RANDOM_KEY) my_hero.entry(move_room) self.assertEqual(my_hero.current_room, move_room) self.assertIsNone(move_room.condition_to_enter)
def test_entry_not_allowed(self, mock_verify_entry, mock_input): mock_verify_entry.return_value = False mock_input.return_value = None init_room = Room('Init Room') my_hero = Hero(room=init_room) move_room = Room(name='Move room', condition_to_enter=Obj.RANDOM_KEY) my_hero.entry(move_room) self.assertEqual(my_hero.current_room, init_room) self.assertIsNotNone(move_room.condition_to_enter)
def test_use_obj_inv_punch(self, mock_input): mock_input.return_value = 1 my_hero = Hero(room=Room(), inventory=[]) self.assertEqual(my_hero.use_obj_inv(is_punch=True), Obj.PUNCH)
def test_use_obj_inv_no_punch(self, mock_input): mock_input.side_effect = [2, 1] my_hero = Hero(room=Room(), inventory=[Obj.GUN]) self.assertEqual(my_hero.use_obj_inv(is_punch=False), Obj.GUN)
def test_defeat_enemy(self, mock_use_obj_inv): mock_use_obj_inv.return_value = Obj.GUN my_hero = Hero(room=Room(enemy=Enemy(kill_by=Obj.GUN)), inventory=[Obj.GUN]) self.assertTrue(my_hero.defeat_enemy())
def test_pick_key_without_key(self): my_hero = Hero(room=Room(obj_in_room=None)) self.assertNotIn(Obj.BATHROOM_KEY, my_hero.inventory) my_hero.pick_obj() self.assertNotIn(Obj.BATHROOM_KEY, my_hero.inventory)
def test_pick_key_with_key(self): my_hero = Hero(room=Room(obj_in_room=Obj.BATHROOM_KEY)) self.assertNotIn(Obj.BATHROOM_KEY, my_hero.inventory) my_hero.pick_obj() self.assertIn(Obj.BATHROOM_KEY, my_hero.inventory) self.assertIsNone(my_hero.current_room.obj_in_room)
def test_action_dead(self): my_hero = Hero(room=Room(obj_in_room=Obj.BATHROOM_KEY)) my_hero.is_alive = False self.assertIsNone(my_hero.action())
def test_action_not_dead(self, mock_input): mock_input.return_value = 'N' my_hero = Hero(room=Room(obj_in_room=Obj.BATHROOM_KEY)) self.assertEqual(Direction.NORTH, my_hero.action()) self.assertIn(Obj.BATHROOM_KEY, my_hero.inventory)
def test_verify_entry_key_needed_bad_key_selected(self, mock_use_obj_inv): mock_use_obj_inv.return_value = Obj.RANDOM_KEY my_hero = Hero(inventory=[Obj.RANDOM_KEY]) my_room = Room(condition_to_enter=Obj.BATHROOM_KEY) self.assertFalse(my_hero.verify_entry(my_room))
def test_verify_entry_key_needed_no_inventory(self): my_hero = Hero(inventory=[]) my_room = Room(condition_to_enter=Obj.BATHROOM_KEY) self.assertFalse(my_hero.verify_entry(my_room))
def test_verify_entry_no_key_needed(self): my_hero = Hero(inventory=[]) my_room = Room(obj_in_room=None) self.assertTrue(my_hero.verify_entry(my_room))
def test_meet_enemy_when_loose_fight(self, mock_defeat_enemy): mock_defeat_enemy.return_value = False my_hero = Hero(room=Room(enemy=Enemy(kill_by=Obj.GUN))) my_hero.meet_enemy() self.assertFalse(my_hero.is_alive) self.assertIsNotNone(my_hero.current_room.enemy)
def test_meet_enemy_when_no_enemy(self): my_hero = Hero(room=Room(enemy=None)) self.assertIsNone(my_hero.meet_enemy())