Esempio n. 1
0
 def test_prepare_turn_and_play_turn_each_object_specified_amount(self):
     unit = Warrior()
     unit.prepare_turn = mock.Mock()
     unit.perform_turn = mock.Mock()
     self.floor.add(unit, 0, 0, 'north')
     self.level.play(2)
     unit.prepare_turn.assert_called_with()
     unit.perform_turn.assert_called_with()
     self.assertEqual(2, unit.prepare_turn.call_count)
     self.assertEqual(2, unit.perform_turn.call_count)
Esempio n. 2
0
 def test_prepare_turn_and_play_turn_each_object_specified_amount(self):
     unit = Warrior()
     unit.prepare_turn = mock.Mock()
     unit.perform_turn = mock.Mock()
     self.floor.add(unit, 0, 0, 'north')
     self.level.play(2)
     unit.prepare_turn.assert_called_with()
     unit.perform_turn.assert_called_with()
     self.assertEqual(2, unit.prepare_turn.call_count)
     self.assertEqual(2, unit.perform_turn.call_count)
Esempio n. 3
0
class TestWarrior(unittest.TestCase):
    def setUp(self):
        self.warrior = Warrior()

    def test_should_default_name_to_warrior(self):
        self.assertEqual(self.warrior.name(), 'Warrior')

    def test_should_be_able_to_set_name(self):
        self.warrior.name_attr = "Joe"
        self.assertEqual(self.warrior.name(), "Joe")
        self.assertEqual(str(self.warrior), "Joe")

    def test_should_have_20_max_health(self):
        self.assertEqual(self.warrior.max_health, 20)

    def test_should_have_0_score_at_beginning_and_be_able_to_earn_points(self):
        self.assertEqual(self.warrior.score, 0)
        self.warrior.earn_points(5)
        self.assertEqual(self.warrior.score, 5)

    @mock.patch('pythonwarrior.units.warrior.Warrior.player')
    def test_should_call_player_play_turn_and_pass_turn_to_player(
            self, mock_player):
        returned_player = mock.Mock()
        mock_player.return_value = returned_player
        self.warrior.play_turn('turn')
        mock_player.assert_called_once_with()
        returned_player.play_turn.assert_called_once_with('turn')

    @unittest.skip
    @mock.patch('pythonwarrior.units.warrior.player.Player')
    def test_should_instantiate_player_first_time_and_return_same_object_next_time(
            self, mock_player):
        player = mock.Mock()
        mock_player.return_value = player
        self.assertEqual(self.warrior.player(), player)
        self.assertEqual(self.warrior.player(), player)

    def test_should_have_an_attack_power_of_5(self):
        self.assertEqual(self.warrior.attack_power, 5)

    def test_should_have_a_shoot_power_of_3(self):
        self.assertEqual(self.warrior.shoot_power, 3)

    def test_should_appear_as_AT_symbol_on_map(self):
        self.assertEqual(self.warrior.character, "@")

    def test_should_be_able_to_add_golem_abilities_which_are_used_on_base_golem(
            self):
        self.warrior.add_golem_abilities("walk")
        self.assertEqual(self.warrior.base_golem().abilities.keys(), ["walk"])
Esempio n. 4
0
 def setUp(self):
     self.floor = Floor()
     self.floor.width = 2
     self.floor.height = 3
     self.warrior = Warrior()
     self.floor.add(self.warrior, 0, 0)
     self.listen = Listen(self.warrior)
Esempio n. 5
0
    def test_should_print_map_with_stairs_and_unit(self):
        self.floor.add(Warrior(), 0, 0)
        self.floor.place_stairs(2, 0)
        self.assertEqual(self.floor.character, ''' ---
|@ >|
 ---
''')
Esempio n. 6
0
 def test_should_fetch_other_units_not_warrior(self):
     unit = UnitBase()
     warrior = Warrior()
     self.floor.add(unit, 0, 0, 'north')
     self.floor.add(warrior, 1, 0, 'north')
     self.assertNotIn(warrior, self.floor.other_units())
     self.assertIn(unit, self.floor.other_units())
Esempio n. 7
0
class TestWarrior(unittest.TestCase):
    def setUp(self):
        self.warrior = Warrior()

    def test_should_default_name_to_warrior(self):
        self.assertEqual(self.warrior.name(), 'Warrior')

    def test_should_be_able_to_set_name(self):
        self.warrior.name_attr = "Joe"
        self.assertEqual(self.warrior.name(), "Joe")
        self.assertEqual(str(self.warrior), "Joe")

    def test_should_have_20_max_health(self):
        self.assertEqual(self.warrior.max_health, 20)

    def test_should_have_0_score_at_beginning_and_be_able_to_earn_points(self):
        self.assertEqual(self.warrior.score, 0)
        self.warrior.earn_points(5)
        self.assertEqual(self.warrior.score, 5)

    @mock.patch('pythonwarrior.units.warrior.Warrior.player')
    def test_should_call_player_play_turn_and_pass_turn_to_player(self, mock_player):
        returned_player = mock.Mock()
        mock_player.return_value = returned_player
        self.warrior.play_turn('turn')
        mock_player.assert_called_once_with()
        returned_player.play_turn.assert_called_once_with('turn')

    @mock.patch('pythonwarrior.units.warrior.Player')
    def test_should_instantiate_player_first_time_and_return_same_object_next_time(self, mock_player):
        player = mock.Mock()
        mock_player.return_value = player
        self.assertEqual(self.warrior.player(), player)
        self.assertEqual(self.warrior.player(), player)

    def test_should_have_an_attack_power_of_5(self):
        self.assertEqual(self.warrior.attack_power, 5)

    def test_should_have_a_shoot_power_of_3(self):
        self.assertEqual(self.warrior.shoot_power, 3)

    def test_should_appear_as_AT_symbol_on_map(self):
        self.assertEqual(self.warrior.character, "@")

    def test_should_be_able_to_add_golem_abilities_which_are_used_on_base_golem(self):
        self.warrior.add_golem_abilities("walk")
        self.assertEqual(self.warrior.base_golem().abilities.keys(), ["walk"])
Esempio n. 8
0
    def setUp(self):
        self.floor = Floor()
        self.floor.width = 4
        self.floor.height = 3
        self.warrior = Warrior()
        self.warrior._health = 20
        self.detonate = Detonate(self.warrior)

        self.target = UnitBase()
        self.target._health = 10

        self.floor.add(self.warrior, 0, 1, 'east')
Esempio n. 9
0
 def warrior(self, *args, **kwargs):
     a_func = kwargs.get('func', None)
     warrior = Warrior(self.level)
     return self.level.setup_warrior(self.unit(warrior, *args, func=a_func))
Esempio n. 10
0
 def setUp(self):
     self.warrior = Warrior()
Esempio n. 11
0
 def setUp(self):
     self.warrior = Warrior()
Esempio n. 12
0
 def setUp(self):
     self.warrior = Warrior()
     self.rescue = Rescue(self.warrior)
Esempio n. 13
0
 def setUp(self):
     self.warrior = Warrior()
     self.health = Health(self.warrior)
Esempio n. 14
0
 def test_should_return_immediately_when_passed(self):
     unit = Warrior()
     unit.turn = mock.Mock()
     self.floor.add(unit, 0, 0, 'north')
     self.level.is_passed = mock.Mock(return_value=True)
     self.level.play(2)
Esempio n. 15
0
 def test_should_consider_passed_When_warrior_is_on_stairs(self):
     self.level.warrior = Warrior()
     self.floor.add(self.level.warrior, 0, 0, 'north')
     self.floor.place_stairs(0, 0)
     self.assertTrue(self.level.is_passed())
Esempio n. 16
0
 def test_should_return_immediately_when_passed(self):
     unit = Warrior()
     unit.turn = mock.Mock()
     self.floor.add(unit, 0, 0, 'north')
     self.level.is_passed = mock.Mock(return_value=True)
     self.level.play(2)
Esempio n. 17
0
 def setUp(self):
     super(TestWithWarrior, self).setUp()
     warrior = Warrior()
     self.floor.add(warrior, 0, 0)
     self.space = self.floor.space(0, 0)
Esempio n. 18
0
 def setUp(self):
     self.warrior = Warrior()
     self.rest = Rest(self.warrior)