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)
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"])
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)
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, ''' --- |@ >| --- ''')
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())
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"])
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')
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))
def setUp(self): self.warrior = Warrior()
def setUp(self): self.warrior = Warrior() self.rescue = Rescue(self.warrior)
def setUp(self): self.warrior = Warrior() self.health = Health(self.warrior)
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)
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())
def setUp(self): super(TestWithWarrior, self).setUp() warrior = Warrior() self.floor.add(warrior, 0, 0) self.space = self.floor.space(0, 0)
def setUp(self): self.warrior = Warrior() self.rest = Rest(self.warrior)