class checkFlinch(unittest.TestCase): """ Test cases of checkFlinch """ def setUp(self): """ Build the Pkmn and Precondition Checker for the test """ self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.environment = BattleEnvironment() attack = AttackFactory.getAttackAsNew("TACKLE") self.preconditionChecker = PreconditionChecker(self.user, self.target, self.environment, attack) def flinching(self): """ Test that check flinch returns correctly when the user has is flinching """ self.user.flinching = True stop, messages = self.preconditionChecker.checkFlinch() message = [self.user.getHeader() + " flinched."] assert stop, "Should stop if the user flinches" assert messages == message, "Should have flinching message" def notFlinching(self): """ Test that check flinch returns correctly when the user is not flinching """ self.user.flinching = False stop, messages = self.preconditionChecker.checkLock() assert not stop, "Should not stop if the user isn't flinching" assert messages == [], "Should not receive any messages"
class checkFaint(unittest.TestCase): """ Test cases of checkFaint """ def setUp(self): """ Build the Pkmn, Lock, and Precondition Checker for the test """ self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.environment = BattleEnvironment() self.actionLock = BuildActionLock(user = self.user) self.attack = AttackFactory.getAttackAsNew("TACKLE") self.preconditionChecker = PreconditionChecker(self.user, self.target, self.environment, self.attack) def fainted(self): """ Test that check faint returns correctly when the user has fainted """ self.user.faint() stop, messages = self.preconditionChecker.checkFaint() assert stop, "Should stop if the user is fainted" assert messages == [], "Should receive the messages for the actual attack" def notFainted(self): """ Test that check faint returns correctly when the user has not fainted """ stop, messages = self.preconditionChecker.checkFaint() assert not stop, "Should not stop if the user is using its lock" assert messages == [], "Should not receive any messages"
class checkCharging(unittest.TestCase): """ Test cases of checkCharging """ def setUp(self): """ Build the Pkmn and Precondition Checker for the test """ self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.environment = BattleEnvironment() self.attack = AttackFactory.getAttackAsNew("DIG") self.preconditionChecker = PreconditionChecker(self.user, self.target, self.environment, self.attack) attack2 = AttackFactory.getAttackAsNew("TACKLE") self.preconditionChecker2 = PreconditionChecker(self.user, self.target, self.environment, attack2) def charging(self): """ Test that check charging returns correctly when the user is charging """ stop, messages = self.preconditionChecker.checkCharging() message = [self.user.getHeader() + self.attack.effectDelegates[0].message] assert stop, "Should stop if the user is charging" assert messages == message, "Should have charging message" def notCharging(self): """ Test that check charging returns correctly when the user is not charging """ stop, messages = self.preconditionChecker2.checkCharging() assert not stop, "Should not stop if the user isn't charging" assert messages == [], "Should not receive any messages"
def setUp(self): """ Build the Pkmn and Precondition Checker for the test """ self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.environment = BattleEnvironment() attack = AttackFactory.getAttackAsNew("TACKLE") self.preconditionChecker = PreconditionChecker(self.user, self.target, self.environment, attack)
def perform(self, user, target, environment, PreconditionChecker=PreconditionChecker): """ Perform this step """ preconditionChecker = PreconditionChecker(user, target, environment, self.parent) self.stop, messages = preconditionChecker.checkPreConditions() return messages
class checkLock(unittest.TestCase): """ Test cases of checkLock """ def setUp(self): """ Build the Pkmn, Lock, and Precondition Checker for the test """ self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.environment = BattleEnvironment() self.actionLock = BuildActionLock(user = self.user) self.attack = AttackFactory.getAttackAsNew("TACKLE") self.preconditionChecker = PreconditionChecker(self.user, self.target, self.environment, self.attack) def hasLock(self): """ Test that check lock returns correctly when the user has a lock """ self.user.actionLock = self.actionLock stop, messages = self.preconditionChecker.checkLock() message = "{0} USED {1}".format(self.user.getHeader(), self.actionLock.action.attack.name) assert stop, "Should stop if the user has a lock" assert len(messages) > 0, "Should receive the messages for the actual attack" assert messages[0] == message, "Should use the actionLock attack" def usingLock(self): """ Test that check lock returns correctly when the user is using its lock attack """ self.preconditionChecker.attack = self.actionLock.action.attack self.user.actionLock = self.actionLock stop, messages = self.preconditionChecker.checkLock() message = "{0} USED {1}".format(self.user.getHeader(), self.actionLock.action.attack.name) assert not stop, "Should not stop if the user is using its lock" assert messages == [], "Should not receive any messages" def noLock(self): """ Test that check lock returns correctly when the user has no lock """ self.user.actionLock = None stop, messages = self.preconditionChecker.checkLock() assert not stop, "Should not stop if the user has no lock" assert messages == [], "Should not receive any messages"
class checkEncore(unittest.TestCase): """ Test cases of checkEncore """ def setUp(self): """ Build the Pkmn and Precondition Checker for the test """ self.user = BuildPokemonBattleWrapper() self.target = BuildPokemonBattleWrapper() self.environment = BattleEnvironment() self.attack = AttackFactory.getAttackAsNew("DIG") self.preconditionChecker = PreconditionChecker(self.user, self.target, self.environment, self.attack) attack2 = AttackFactory.getAttackAsNew("TACKLE") self.preconditionChecker2 = PreconditionChecker(self.user, self.target, self.environment, attack2) def encore(self): """ Test that check encore returns correctly when the user has an encore """ encoreCount = 1 self.user.encore = encoreCount stop, messages = self.preconditionChecker.checkEncore() message = [self.user.getHeader() + self.attack.effectDelegates[0].message] assert self.user.encore == encoreCount-1, "Encore should be decremented" assert not stop, "Should never stop if have an encore" assert messages == [], "Should not receive any messages" def noEncore(self): """ Test that check encore returns correctly when the user has no encore """ encoreCount = 0 self.user.encore = encoreCount stop, messages = self.preconditionChecker2.checkEncore() assert self.user.encore == encoreCount, "Encore should not decrement when there is no encore" assert not stop, "Should never stop if have an encore" assert messages == [], "Should not receive any messages"