def testBuildSuccess(self): eTgtLoc = self.ch.expression(expressionId=1, operandId=24, value="Target") eTgtSrq = self.ch.expression(expressionId=2, operandId=29, expressionTypeId=3300) eTgtAttr1 = self.ch.expression(expressionId=3, operandId=22, expressionAttributeId=54) eTgtAttr2 = self.ch.expression(expressionId=4, operandId=22, expressionAttributeId=158) eTgtAttr3 = self.ch.expression(expressionId=5, operandId=22, expressionAttributeId=160) eOptr = self.ch.expression(expressionId=6, operandId=21, value="PostPercent") eSrcAttr1 = self.ch.expression(expressionId=7, operandId=22, expressionAttributeId=351) eSrcAttr2 = self.ch.expression(expressionId=8, operandId=22, expressionAttributeId=349) eSrcAttr3 = self.ch.expression(expressionId=9, operandId=22, expressionAttributeId=767) eTgtItms = self.ch.expression(expressionId=10, operandId=49, arg1Id=eTgtLoc.id, arg2Id=eTgtSrq.id) eTgtSpec1 = self.ch.expression(expressionId=11, operandId=12, arg1Id=eTgtItms.id, arg2Id=eTgtAttr1.id) eTgtSpec2 = self.ch.expression(expressionId=12, operandId=12, arg1Id=eTgtItms.id, arg2Id=eTgtAttr2.id) eTgtSpec3 = self.ch.expression(expressionId=13, operandId=12, arg1Id=eTgtItms.id, arg2Id=eTgtAttr3.id) eOptrTgt1 = self.ch.expression(expressionId=14, operandId=31, arg1Id=eOptr.id, arg2Id=eTgtSpec1.id) eOptrTgt2 = self.ch.expression(expressionId=15, operandId=31, arg1Id=eOptr.id, arg2Id=eTgtSpec2.id) eOptrTgt3 = self.ch.expression(expressionId=16, operandId=31, arg1Id=eOptr.id, arg2Id=eTgtSpec3.id) eAddMod1 = self.ch.expression(expressionId=17, operandId=9, arg1Id=eOptrTgt1.id, arg2Id=eSrcAttr1.id) eAddMod2 = self.ch.expression(expressionId=18, operandId=9, arg1Id=eOptrTgt2.id, arg2Id=eSrcAttr2.id) eAddMod3 = self.ch.expression(expressionId=19, operandId=9, arg1Id=eOptrTgt3.id, arg2Id=eSrcAttr3.id) eRmMod1 = self.ch.expression(expressionId=20, operandId=61, arg1Id=eOptrTgt1.id, arg2Id=eSrcAttr1.id) eRmMod2 = self.ch.expression(expressionId=21, operandId=61, arg1Id=eOptrTgt2.id, arg2Id=eSrcAttr2.id) eRmMod3 = self.ch.expression(expressionId=22, operandId=61, arg1Id=eOptrTgt3.id, arg2Id=eSrcAttr3.id) eAddSplice1 = self.ch.expression(expressionId=23, operandId=17, arg1Id=eAddMod1.id, arg2Id=eAddMod3.id) eAddSplice2 = self.ch.expression(expressionId=24, operandId=17, arg1Id=eAddMod2.id, arg2Id=eAddSplice1.id) eRmSplice1 = self.ch.expression(expressionId=25, operandId=17, arg1Id=eRmMod1.id, arg2Id=eRmMod3.id) eRmSplice2 = self.ch.expression(expressionId=26, operandId=17, arg1Id=eRmMod2.id, arg2Id=eRmSplice1.id) effect = self.ch.effect(categoryId=0, preExpressionId=eAddSplice2.id, postExpressionId=eRmSplice2.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.okFull) self.assertEqual(len(modifiers), 3)
def testBuildSuccess(self): ePreStub = self.ch.expression(expressionId=1, operandId=23, value="True") ePostStub = self.ch.expression(expressionId=2, operandId=27, value="0") effect = self.ch.effect(categoryId=0, preExpressionId=ePreStub.id, postExpressionId=ePostStub.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.okFull) self.assertEqual(len(modifiers), 0)
def testEffCategoryTarget(self): effect = self.ch.effect(categoryId=2, preExpressionId=self.eAddMod.id, postExpressionId=self.eRmMod.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.okFull) self.assertEqual(len(modifiers), 1) modifier = modifiers[0] self.assertEqual(modifier.state, State.active) self.assertEqual(modifier.context, Context.projected)
def testEffCategoryOverload(self): effect = self.ch.effect(categoryId=5, preExpressionId=self.eAddMod.id, postExpressionId=self.eRmMod.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.okFull) self.assertEqual(len(modifiers), 1) modifier = modifiers[0] self.assertEqual(modifier.state, State.overload) self.assertEqual(modifier.context, Context.local)
def testDataDirect(self): # Check reaction to expression data fetch errors effect = self.ch.effect(effectId=900, categoryId=0, preExpressionId=902, postExpressionId=28) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.error) self.assertEqual(len(modifiers), 0) self.assertEqual(len(self.log), 1) logRecord = self.log[0] self.assertEqual(logRecord.name, "eos_test.modifierBuilder") self.assertEqual(logRecord.levelno, Logger.ERROR) self.assertEqual(logRecord.msg, "failed to parse expressions of effect 900: unable to fetch expression 902")
def testBoolStub(self): ePreStub = self.ch.expression(expressionId=1, operandId=27, value="0") ePost = self.ch.expression(expressionId=2, operandId=23, value="False") effect = self.ch.effect(effectId=92, categoryId=0, preExpressionId=ePreStub.id, postExpressionId=ePost.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.error) self.assertEqual(len(modifiers), 0) self.assertEqual(len(self.log), 1) logRecord = self.log[0] self.assertEqual(logRecord.name, "eos_test.modifierBuilder") self.assertEqual(logRecord.levelno, Logger.WARNING) self.assertEqual(logRecord.msg, "failed to parse expressions of effect 92: boolean stub with unexpected value False")
def testGeneric(self): ePreStub = self.ch.expression(expressionId=1, operandId=27, value="1") ePost = self.ch.expression(expressionId=2, operandId=1009) effect = self.ch.effect(effectId=568, categoryId=0, preExpressionId=ePreStub.id, postExpressionId=ePost.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.error) self.assertEqual(len(modifiers), 0) self.assertEqual(len(self.log), 1) logRecord = self.log[0] self.assertEqual(logRecord.name, "eos_test.modifierBuilder") self.assertEqual(logRecord.levelno, Logger.WARNING) self.assertEqual(logRecord.msg, "failed to parse expressions of effect 568: unknown generic operand 1009")
def testDataIndirect(self): # Check reaction to expression data fetch errors, # if they occur not for root expression splice = self.ch.expression(expressionId=1, operandId=17, arg1Id=37, arg2Id=105) effect = self.ch.effect(effectId=900, categoryId=0, preExpressionId=splice.id, postExpressionId=splice.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.error) self.assertEqual(len(modifiers), 0) self.assertEqual(len(self.log), 1) logRecord = self.log[0] self.assertEqual(logRecord.name, "eos_test.modifierBuilder") self.assertEqual(logRecord.levelno, Logger.ERROR) self.assertEqual(logRecord.msg, "failed to parse expressions of effect 900: unable to fetch expression 37")
def testGenericBuildSuccess(self): effect = self.ch.effect(categoryId=0, preExpressionId=self.eAddMod.id, postExpressionId=self.eRmMod.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.okFull) self.assertEqual(len(modifiers), 1) modifier = modifiers[0] self.assertEqual(modifier.context, Context.local) self.assertEqual(modifier.sourceAttributeId, 1503) self.assertEqual(modifier.operator, Operator.postPercent) self.assertEqual(modifier.targetAttributeId, 1211) self.assertEqual(modifier.location, Location.ship) self.assertEqual(modifier.filterType, FilterType.all_) self.assertIsNone(modifier.filterValue)
def testGenericBuildSuccess(self): effect = self.ch.effect(categoryId=0, preExpressionId=self.eAddMod.id, postExpressionId=self.eRmMod.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.okFull) self.assertEqual(len(modifiers), 1) modifier = modifiers[0] self.assertEqual(modifier.context, Context.gang) self.assertEqual(modifier.sourceAttributeId, 848) self.assertEqual(modifier.operator, Operator.postMul) self.assertEqual(modifier.targetAttributeId, 654) self.assertEqual(modifier.location, Location.space) self.assertEqual(modifier.filterType, FilterType.skill) self.assertEqual(modifier.filterValue, 3326)
def getModifiers(self, logger): """ Get modifiers of effect. Positional arguments: logger -- instance of logger to use for error reporting Return value: Set with Modifier objects generated by effect """ if self._modifiers is None: self._modifiers, self.modifierStatus = ModifierBuilder.build(self, logger) return self._modifiers
def testUnknown(self): # Check reaction to any errors of action builder, # which are not specifically processed by it ePreStub = self.ch.expression(expressionId=1, operandId=27, value="0") ePost = self.ch.expression(expressionId=2, operandId=23, value="Garbage") effect = self.ch.effect(effectId=66, categoryId=0, preExpressionId=ePreStub.id, postExpressionId=ePost.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.error) self.assertEqual(len(modifiers), 0) self.assertEqual(len(self.log), 1) logRecord = self.log[0] self.assertEqual(logRecord.name, "eos_test.modifierBuilder") self.assertEqual(logRecord.levelno, Logger.ERROR) self.assertEqual(logRecord.msg, "failed to parse expressions of effect 66 due to unknown reason")
def testBuildSuccess(self): eTgtOwn = self.ch.expression(expressionId=1, operandId=24, value="Char") eSelf = self.ch.expression(expressionId=2, operandId=24, value="Self") eSelfType = self.ch.expression(expressionId=3, operandId=36, arg1Id=eSelf.id) eTgtAttr = self.ch.expression(expressionId=4, operandId=22, expressionAttributeId=64) eOptr = self.ch.expression(expressionId=5, operandId=21, value="PostPercent") eSrcAttr = self.ch.expression(expressionId=6, operandId=22, expressionAttributeId=292) eTgtItms = self.ch.expression(expressionId=7, operandId=49, arg1Id=eTgtOwn.id, arg2Id=eSelfType.id) eTgtSpec = self.ch.expression(expressionId=8, operandId=12, arg1Id=eTgtItms.id, arg2Id=eTgtAttr.id) eOptrTgt = self.ch.expression(expressionId=9, operandId=31, arg1Id=eOptr.id, arg2Id=eTgtSpec.id) eAddMod = self.ch.expression(expressionId=10, operandId=11, arg1Id=eOptrTgt.id, arg2Id=eSrcAttr.id) eRmMod = self.ch.expression(expressionId=11, operandId=62, arg1Id=eOptrTgt.id, arg2Id=eSrcAttr.id) effect = self.ch.effect(categoryId=0, preExpressionId=eAddMod.id, postExpressionId=eRmMod.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.okFull) self.assertEqual(len(modifiers), 1) modifier = modifiers[0] self.assertEqual(modifier.filterType, FilterType.skill) self.assertEqual(modifier.filterValue, InvType.self_)
def testUnusedActions(self): # To produce unused actions, we're passing just tree # which describes action which applies something, and # stub instead of action undoing it eTgt = self.ch.expression(expressionId=1, operandId=24, value="Ship") eTgtAttr = self.ch.expression(expressionId=2, operandId=22, expressionAttributeId=9) eOptr = self.ch.expression(expressionId=3, operandId=21, value="PostPercent") eSrcAttr = self.ch.expression(expressionId=4, operandId=22, expressionAttributeId=327) eTgtSpec = self.ch.expression(expressionId=5, operandId=12, arg1Id=eTgt.id, arg2Id=eTgtAttr.id) eOptrTgt = self.ch.expression(expressionId=6, operandId=31, arg1Id=eOptr.id, arg2Id=eTgtSpec.id) eAddMod = self.ch.expression(expressionId=7, operandId=6, arg1Id=eOptrTgt.id, arg2Id=eSrcAttr.id) ePostStub = self.ch.expression(expressionId=8, operandId=27, value="1") effect = self.ch.effect(effectId=799, categoryId=0, preExpressionId=eAddMod.id, postExpressionId=ePostStub.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.okPartial) self.assertEqual(len(modifiers), 0) self.assertEqual(len(self.log), 1) logRecord = self.log[0] self.assertEqual(logRecord.name, "eos_test.modifierBuilder") self.assertEqual(logRecord.levelno, Logger.WARNING) self.assertEqual(logRecord.msg, "unused actions left after generating modifiers for effect 799")
def testValidation(self): # To make invalid action, we've just took location # and group- filtered expression tree and replaced its # actual top-level operands with operand describing # direct modification eTgtLoc = self.ch.expression(expressionId=1, operandId=24, value="Ship") eTgtGrp = self.ch.expression(expressionId=2, operandId=26, expressionGroupId=46) eTgtAttr = self.ch.expression(expressionId=3, operandId=22, expressionAttributeId=6) eOptr = self.ch.expression(expressionId=4, operandId=21, value="PostPercent") eSrcAttr = self.ch.expression(expressionId=5, operandId=22, expressionAttributeId=1576) eTgtItms = self.ch.expression(expressionId=6, operandId=48, arg1Id=eTgtLoc.id, arg2Id=eTgtGrp.id) eTgtSpec = self.ch.expression(expressionId=7, operandId=12, arg1Id=eTgtItms.id, arg2Id=eTgtAttr.id) eOptrTgt = self.ch.expression(expressionId=8, operandId=31, arg1Id=eOptr.id, arg2Id=eTgtSpec.id) eAddMod = self.ch.expression(expressionId=9, operandId=6, arg1Id=eOptrTgt.id, arg2Id=eSrcAttr.id) eRmMod = self.ch.expression(expressionId=10, operandId=58, arg1Id=eOptrTgt.id, arg2Id=eSrcAttr.id) effect = self.ch.effect(effectId=20807, categoryId=0, preExpressionId=eAddMod.id, postExpressionId=eRmMod.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.error) self.assertEqual(len(modifiers), 0) self.assertEqual(len(self.log), 1) logRecord = self.log[0] self.assertEqual(logRecord.name, "eos_test.modifierBuilder") self.assertEqual(logRecord.levelno, Logger.WARNING) self.assertEqual(logRecord.msg, "failed to parse expressions of effect 20807: failed to validate action")
def testFofLaunch(self): disabledPre = self.ch.expression(expressionId=1, operandId=47) effect = self.ch.effect(categoryId=0, preExpressionId=disabledPre.id, postExpressionId=self.stub.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.okPartial) self.assertEqual(len(modifiers), 0)
def testEffCategoryArea(self): effect = self.ch.effect(categoryId=3, preExpressionId=self.eAddMod.id, postExpressionId=self.eRmMod.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.error) self.assertEqual(len(modifiers), 0)
def testPost(self): eRmMod = self.ch.expression(expressionId=8, operandId=58, arg1Id=self.eOptrTgt.id, arg2Id=self.eSrcAttr.id) effect = self.ch.effect(categoryId=0, preExpressionId=self.stub.id, postExpressionId=eRmMod.id) modifiers, status = ModifierBuilder.build(effect, Logger()) self.assertEqual(status, EffectBuildStatus.okPartial) self.assertEqual(len(modifiers), 0)