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 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"