def setUp(self): """ Builds the delegate and pkmn for use in the tests """ self.pkmn = BuildPokemonBattleWrapper() self.status = "PAR" attack = Attack() attack.type = "" self.delegate = ApplyStatusDelegate(attack, self.status, 1)
def setUp(self): """ Build the Attack for the test """ self.attack = Attack() self.messages = ["My Test Messages"] self.attack.preconditionsStep = MockStep(self.messages) self.attack.announcementStep = MockStep(self.messages) self.attack.removePPStep = MockStep(self.messages) self.attack.hitStep = MockStep(self.messages) self.attack.damageStep = MockStep(self.messages) self.attack.effectsStep = MockStep(self.messages) self.attack.handleContactStep = MockStep(self.messages) self.attack.handleMissEffectsStep = MockStep(self.messages)
def loadFromPokemonFile(file): """ Load an attack as saved within a Pokemon instance in a file """ attack = Attack() attackdex = AttackFactory.getAttackdexTree() attack.name = file.readline().strip() temp = "" while (temp.find(attack.name) == -1): """ Read the file until you find the species we need """ temp = attackdex.readline().strip() attack.type = attackdex.readline().strip() #Load delegates attack.hitDelegate = HitDelegateFactory.loadFromAttackDex(attackdex, attack) attack.damageDelegate = DamageDelegateFactory.loadFromAttackDex(attackdex, attack) attack.effectDelegate = EffectDelegateFactory.loadFromAttackDex(attackdex) # Get currPP and PP from file values = file.readline().strip().split(" ") attack.powerPoints = int(values[0]) attack.currPowerPoints = int(values[1]) attackdex.close() return attack
def setUp(self): """ Build the Step for the test """ self.attack = Attack() self.attack.name = "Test Attack" self.step = AnnouncementStep(self.attack) self.header = "Header" self.calledGetHeader = False
def setUp(self): """ Build the Step for the test """ self.attack = Attack() self.attack.damageDelegate = self self.step = DamageStep(self.attack) self.messages = ["My Test Messages"] self.calledDoDamage = False
def setUp(self): """ Build the Step for the test """ self.attack = Attack() self.attack.hitDelegate = self self.step = HitStep(self.attack) self.messages = ["My Test Messages"] self.calledHit = False
def setUp(self): """ Build the Step for the test """ self.attack = Attack() self.step = PreconditionStep(self.attack) self.preconditionMessages = ["My Precondition Messages"] self.attackMessages = ["My Attack Messages"] self.calledCheckPreConditions = False
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
class isStatus(unittest.TestCase): """ Test cases of isStatus """ def setUp(self): """ Build the Attack and Damage Delegate for the test """ self.attack = Attack() self.nullDamageDelegate = NullDamageDelegate() self.normalDamageDelegate = DamageDelegate(None, None, None) def hasNullDamageDelegate(self): """ Test that when the damage delegate is the null damage delegate the attack is a status attack """ self.attack.damageDelegate = self.nullDamageDelegate isStausAttack = self.attack.isStatus() self.assertTrue(isStausAttack, "The Attack should be a status attack") def hasNormalDamageDelegate(self): """ Test that when the damage delegate is normal the attack is not a status attack """ self.attack.damageDelegate = self.normalDamageDelegate isStausAttack = self.attack.isStatus() self.assertFalse(isStausAttack, "The Attack should not be a status attack")
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 buildAttackFromXML(tree): """ Build an Attack from XML tree """ attack = Attack() attack.name = tree.find(Tags.nameTag).text attack.type = tree.find(Tags.typeTag).text attack.makes_contact = Tags.contactAttribute in tree.attrib # Delegates for delegateCategory in AttackFactory.factories.keys(): delegate = AttackFactory.getDelegate(tree, delegateCategory, attack) attack.addDelegate(delegateCategory, delegate) effects = tree.find(Tags.effectDelegatesTag) if effects is not None: for effect in effects.getchildren(): delegate = EffectDelegateFactory.loadFromXML(effect, attack) attack.addDelegate(Tags.effectDelegateTag, delegate) return attack
def buildAttackFromDB(cursor, name): """ Build an Attack from a Database connection """ attack = Attack() cursor.execute("SELECT Type.name from Attack, Type where Attack.name = ? and Attack.type_id = Type.id", (name,)) type = cursor.fetchone()[0] attack.name = name attack.type = type # Delegates for delegateCategory in AttackFactory.factories.keys(): delegate = AttackFactory.getDelegateDB(cursor, delegateCategory, attack) attack.addDelegate(delegateCategory, delegate) attack.effectDelegates = EffectDelegateFactory.loadAllEffectsFromDB(cursor, attack) return attack
def getConfusionAttack(): """ Builds and returns the DamageDelegate used for Confusion """ attack = Attack() attack.type = "" return DamageDelegate(attack, 40, 1)
def setUp(self): """ Build the Attack and Damage Delegate for the test """ self.attack = Attack() self.nullDamageDelegate = NullDamageDelegate() self.normalDamageDelegate = DamageDelegate(None, None, None)
class use(unittest.TestCase): """ Test cases of use """ def setUp(self): """ Build the Attack for the test """ self.attack = Attack() self.messages = ["My Test Messages"] self.attack.preconditionsStep = MockStep(self.messages) self.attack.announcementStep = MockStep(self.messages) self.attack.removePPStep = MockStep(self.messages) self.attack.hitStep = MockStep(self.messages) self.attack.damageStep = MockStep(self.messages) self.attack.effectsStep = MockStep(self.messages) self.attack.handleContactStep = MockStep(self.messages) self.attack.handleMissEffectsStep = MockStep(self.messages) def preconditions_Failing(self): """ Test that failing precodnitions prevents the attack from being done """ self.attack.preconditionsStep.passed = False messages = self.attack.use(None, None, None) self.assertTrue(self.attack.preconditionsStep.performed, "Should have performed the Precondition Step") self.assertFalse(self.attack.announcementStep.performed, "Should not have performed the Announcement Step") self.assertFalse(self.attack.removePPStep.performed, "Should not have performed the Remove PP Step") self.assertFalse(self.attack.hitStep.performed, "Should not have performed the Hit Step") self.assertFalse(self.attack.damageStep.performed, "Should not have performed the Damage Step") self.assertFalse(self.attack.effectsStep.performed, "Should not have performed the Effects Step") self.assertFalse(self.attack.handleContactStep.performed, "Should not have performed the Handle Contact Step") self.assertFalse(self.attack.handleMissEffectsStep.performed, "Should not have performed the Hanlde Miss Effects Step") self.assertEquals(self.messages, messages, 'Should have messages for each performed step') def hit_Succeeded(self): """ Test that passing precodnitions allows the attack to be used """ self.attack.preconditionsStep.passed = True self.attack.hitStep.hit = True messages = self.attack.use(None, None, None) self.assertTrue(self.attack.preconditionsStep.performed, "Should have performed the Precondition Step") self.assertTrue(self.attack.announcementStep.performed, "Should have performed the Announcement Step") self.assertTrue(self.attack.removePPStep.performed, "Should have performed the Remove PP Step") self.assertTrue(self.attack.hitStep.performed, "Should have performed the Hit Step") self.assertTrue(self.attack.damageStep.performed, "Should have performed the Damage Step") self.assertTrue(self.attack.effectsStep.performed, "Should have performed the Effects Step") self.assertTrue(self.attack.handleContactStep.performed, "Should have performed the Handle Contact Step") self.assertFalse(self.attack.handleMissEffectsStep.performed, "Should not have performed the Hanlde Miss Effects Step") self.assertEquals(self.messages*7, messages, 'Should have messages for each performed step') def hit_Missed(self): """ Test that messages from the attack are returned """ self.attack.preconditionsStep.passed = True self.attack.hitStep.hit = False messages = self.attack.use(None, None, None) self.assertTrue(self.attack.preconditionsStep.performed, "Should have performed the Precondition Step") self.assertTrue(self.attack.announcementStep.performed, "Should have performed the Announcement Step") self.assertTrue(self.attack.removePPStep.performed, "Should have performed the Remove PP Step") self.assertTrue(self.attack.hitStep.performed, "Should have performed the Hit Step") self.assertFalse(self.attack.damageStep.performed, "Should not have performed the Damage Step") self.assertFalse(self.attack.effectsStep.performed, "Should not have performed the Effects Step") self.assertFalse(self.attack.handleContactStep.performed, "Should not have performed the Handle Contact Step") self.assertTrue(self.attack.handleMissEffectsStep.performed, "Should have performed the Hanlde Miss Effects Step") self.assertEquals(self.messages*5, messages, 'Should have messages for each performed step')
class use(unittest.TestCase): """ Test cases of use """ def setUp(self): """ Build the Attack for the test """ self.attack = Attack() self.messages = ["My Test Messages"] self.attack.preconditionsStep = MockStep(self.messages) self.attack.announcementStep = MockStep(self.messages) self.attack.removePPStep = MockStep(self.messages) self.attack.hitStep = MockStep(self.messages) self.attack.damageStep = MockStep(self.messages) self.attack.effectsStep = MockStep(self.messages) self.attack.handleContactStep = MockStep(self.messages) self.attack.handleMissEffectsStep = MockStep(self.messages) def preconditions_Failing(self): """ Test that failing precodnitions prevents the attack from being done """ self.attack.preconditionsStep.passed = False messages = self.attack.use(None, None, None) self.assertTrue(self.attack.preconditionsStep.performed, "Should have performed the Precondition Step") self.assertFalse(self.attack.announcementStep.performed, "Should not have performed the Announcement Step") self.assertFalse(self.attack.removePPStep.performed, "Should not have performed the Remove PP Step") self.assertFalse(self.attack.hitStep.performed, "Should not have performed the Hit Step") self.assertFalse(self.attack.damageStep.performed, "Should not have performed the Damage Step") self.assertFalse(self.attack.effectsStep.performed, "Should not have performed the Effects Step") self.assertFalse(self.attack.handleContactStep.performed, "Should not have performed the Handle Contact Step") self.assertFalse( self.attack.handleMissEffectsStep.performed, "Should not have performed the Hanlde Miss Effects Step") self.assertEquals(self.messages, messages, 'Should have messages for each performed step') def hit_Succeeded(self): """ Test that passing precodnitions allows the attack to be used """ self.attack.preconditionsStep.passed = True self.attack.hitStep.hit = True messages = self.attack.use(None, None, None) self.assertTrue(self.attack.preconditionsStep.performed, "Should have performed the Precondition Step") self.assertTrue(self.attack.announcementStep.performed, "Should have performed the Announcement Step") self.assertTrue(self.attack.removePPStep.performed, "Should have performed the Remove PP Step") self.assertTrue(self.attack.hitStep.performed, "Should have performed the Hit Step") self.assertTrue(self.attack.damageStep.performed, "Should have performed the Damage Step") self.assertTrue(self.attack.effectsStep.performed, "Should have performed the Effects Step") self.assertTrue(self.attack.handleContactStep.performed, "Should have performed the Handle Contact Step") self.assertFalse( self.attack.handleMissEffectsStep.performed, "Should not have performed the Hanlde Miss Effects Step") self.assertEquals(self.messages * 7, messages, 'Should have messages for each performed step') def hit_Missed(self): """ Test that messages from the attack are returned """ self.attack.preconditionsStep.passed = True self.attack.hitStep.hit = False messages = self.attack.use(None, None, None) self.assertTrue(self.attack.preconditionsStep.performed, "Should have performed the Precondition Step") self.assertTrue(self.attack.announcementStep.performed, "Should have performed the Announcement Step") self.assertTrue(self.attack.removePPStep.performed, "Should have performed the Remove PP Step") self.assertTrue(self.attack.hitStep.performed, "Should have performed the Hit Step") self.assertFalse(self.attack.damageStep.performed, "Should not have performed the Damage Step") self.assertFalse(self.attack.effectsStep.performed, "Should not have performed the Effects Step") self.assertFalse(self.attack.handleContactStep.performed, "Should not have performed the Handle Contact Step") self.assertTrue(self.attack.handleMissEffectsStep.performed, "Should have performed the Hanlde Miss Effects Step") self.assertEquals(self.messages * 5, messages, 'Should have messages for each performed step')
def setUp(self): """ Build the Attack and Damage Delegate """ attack = Attack() attack.type ="FIRE" self.delegate = DamageDelegate(attack, 0, 1)
def setUp(self): """ Build side for use in test cases """ self.pkmn = BuildPokemonBattleWrapper() self.parent = Attack() self.parent.type = "NORMAL"