class applyEffect(unittest.TestCase): """ Test cases of applyEffect """ def setUp(self): """ Build the Pkmn, Abilities and Effect for the test """ self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.userAbility = Ability(None) self.targetAbility = Ability(None) self.user.setAbility(self.userAbility) self.target.setAbility(self.targetAbility) self.delegate = SwapAbilityDelegate() def swapped(self): """ Test that the abilities are swapped """ self.delegate.applyEffect(self.user, self.target, None) assert self.user.getAbility() is self.targetAbility, "User should have target's ability" assert self.target.getAbility() is self.userAbility, "Target should have user's ability" def message(self): """ Test message is returned correctly """ messages = self.delegate.applyEffect(self.user, self.target, None) assert messages == [SwapAbilityDelegate.message % (self.user.getHeader(), self.target.getHeader())], "Should have the Effect's message"
class perform(unittest.TestCase): """ Test cases of perform """ def setUp(self): """ Build the Step for the test """ self.attack = Attack() self.step = HandleContactStep(self.attack) self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.user.getAbility().onContact = self.onContact self.target.getAbility().onContact = self.onContact self.hitPkmn = None self.calledOnContact = 0 self.messages = ["My Test Message"] def makesContact(self): """ Test that when the attack makes contact the targets contact effect is used """ self.attack.makes_contact = True messages = self.step.perform(self.user, self.target, None) self.assertIs(self.target, self.hitPkmn, "Should have called onContact for the Target Pkmn") self.assertEquals(1, self.calledOnContact, "Should have called onContact only once") self.assertEquals(self.messages, messages, "Should receive messages from the onContact") def doesNotMakeContact(self): """ Test that when the attack does not make contact nothing happens """ self.attack.makes_contact = False messages = self.step.perform(self.user, self.target, None) self.assertEquals(0, self.calledOnContact, "Should not have called onContact") self.assertEquals([], messages, "Should receive no messages") def onContact(self, pkmnHit, pkmnWhoAttacked): self.hitPkmn = pkmnHit self.calledOnContact += 1 return self.messages
class perform(unittest.TestCase): """ Test cases of perform """ def setUp(self): """ Build the Step for the test """ self.attack = Attack() self.originalPowerPointsValue = 10 self.attack.currPowerPoints = self.originalPowerPointsValue self.step = RemovePPStep(self.attack) self.target = BuildPokemonBattleWrapper() self.target.getAbility().powerPointsPressure = self.powerPointsPressure self.pressure = 2 self.usedAbility = False def standard(self): """ Test that the PP is decreased under normal circumstances """ ppValue = 10 self.attack.currPowerPoints = ppValue self.step.perform(None, self.target, None) self.assertTrue(self.usedAbility, "PP Pressure should have been determined by the Target's Pressure") self.assertEquals(ppValue-self.pressure, self.attack.currPowerPoints, "PP should have been reduced by the Target's Pressure") def hitSelf(self): """ Test that the PP is decreased under normal circumstances """ self.attack.hitDelegate = HitSelfDelegate() ppValue = 10 self.attack.currPowerPoints = ppValue self.step.perform(None, self.target, None) self.assertFalse(self.usedAbility, "PP Pressure should not have been determined by the Target's Pressure") self.assertEquals(ppValue-1, self.attack.currPowerPoints, 'PP should have been reduced by 1') def zero(self): """ Test that the PP is not decreased when already at zero """ ppValue = 0 self.attack.currPowerPoints = ppValue self.step.perform(None, self.target, None) self.assertEquals(0, self.attack.currPowerPoints, 'PP should stay at 0') def powerPointsPressure(self): """ Return the power Point Pressure """ self.usedAbility = True return self.pressure