示例#1
0
 def testOther(self):
     tgtAttr = self.ch.attribute(attributeId=1)
     srcAttr = self.ch.attribute(attributeId=2)
     modifier = Modifier()
     modifier.state = State.offline
     modifier.context = Context.local
     modifier.sourceAttributeId = srcAttr.id
     modifier.operator = Operator.postPercent
     modifier.targetAttributeId = tgtAttr.id
     modifier.location = Location.other
     modifier.filterType = None
     modifier.filterValue = None
     effect = self.ch.effect(effectId=1, categoryId=EffectCategory.passive)
     effect.modifiers = (modifier,)
     influenceSource = ItemWithOther(self.ch.type_(typeId=1, effects=(effect,), attributes={srcAttr.id: 20}))
     self.fit.items.add(influenceSource)
     item = self.ch.type_(typeId=2, attributes={tgtAttr.id: 100})
     influenceTarget1 = ItemWithOther(item)
     influenceSource.makeOtherLink(influenceTarget1)
     self.fit.items.add(influenceTarget1)
     self.assertNotAlmostEqual(influenceTarget1.attributes[tgtAttr.id], 100)
     self.fit.items.remove(influenceTarget1)
     influenceSource.breakOtherLink(influenceTarget1)
     influenceTarget2 = ItemWithOther(item)
     influenceSource.makeOtherLink(influenceTarget2)
     self.fit.items.add(influenceTarget2)
     self.assertNotAlmostEqual(influenceTarget2.attributes[tgtAttr.id], 100)
     self.fit.items.remove(influenceTarget2)
     influenceSource.breakOtherLink(influenceTarget2)
     self.fit.items.remove(influenceSource)
     self.assertEqual(len(self.log), 0)
     self.assertLinkBuffersEmpty(self.fit)
示例#2
0
文件: testOther.py 项目: bastianh/Eos
class TestLocationDirectOther(AttrCalcTestCase):
    """Test location.other for direct modifications"""

    def setUp(self):
        AttrCalcTestCase.setUp(self)
        self.tgtAttr = self.ch.attribute(attributeId=1)
        srcAttr = self.ch.attribute(attributeId=2)
        modifier = Modifier()
        modifier.state = State.offline
        modifier.context = Context.local
        modifier.sourceAttributeId = srcAttr.id
        modifier.operator = Operator.postPercent
        modifier.targetAttributeId = self.tgtAttr.id
        modifier.location = Location.other
        modifier.filterType = None
        modifier.filterValue = None
        effect = self.ch.effect(effectId=1, categoryId=EffectCategory.passive)
        effect.modifiers = (modifier,)
        # We added target attribute to influence source for testSelf;
        # currently, eos cannot calculate attributes which are originally
        # missing on item
        self.influenceSource = ItemWithOther(self.ch.type_(typeId=1, effects=(effect,), attributes={self.tgtAttr.id: 100, srcAttr.id: 20}))
        self.fit.items.add(self.influenceSource)

    def testOtherLocation(self):
        influenceTarget = ItemWithOther(self.ch.type_(typeId=2, attributes={self.tgtAttr.id: 100}))
        self.influenceSource.makeOtherLink(influenceTarget)
        self.fit.items.add(influenceTarget)
        self.assertNotAlmostEqual(influenceTarget.attributes[self.tgtAttr.id], 100)
        self.fit.items.remove(self.influenceSource)
        self.influenceSource.breakOtherLink(influenceTarget)
        self.assertAlmostEqual(influenceTarget.attributes[self.tgtAttr.id], 100)
        self.fit.items.remove(influenceTarget)
        self.assertEqual(len(self.log), 0)
        self.assertBuffersEmpty(self.fit)

    def testSelf(self):
        # Check that source holder isn't modified
        influenceTarget = ItemWithOther(self.ch.type_(typeId=2, attributes={self.tgtAttr.id: 100}))
        self.influenceSource.makeOtherLink(influenceTarget)
        self.fit.items.add(influenceTarget)
        self.assertAlmostEqual(self.influenceSource.attributes[self.tgtAttr.id], 100)
        self.fit.items.remove(influenceTarget)
        self.influenceSource.breakOtherLink(influenceTarget)
        self.fit.items.remove(self.influenceSource)
        self.assertEqual(len(self.log), 0)
        self.assertBuffersEmpty(self.fit)

    def testOtherHolder(self):
        # Here we check some "random" holder, w/o linking holders
        influenceTarget = IndependentItem(self.ch.type_(typeId=2, attributes={self.tgtAttr.id: 100}))
        self.fit.items.add(influenceTarget)
        self.assertAlmostEqual(influenceTarget.attributes[self.tgtAttr.id], 100)
        self.fit.items.remove(self.influenceSource)
        self.fit.items.remove(influenceTarget)
        self.assertEqual(len(self.log), 0)
        self.assertBuffersEmpty(self.fit)
示例#3
0
class TestLocationDirectOther(AttrCalcTestCase):
    """Test location.other for direct modifications"""
    def setUp(self):
        AttrCalcTestCase.setUp(self)
        self.tgtAttr = self.ch.attribute(attributeId=1)
        srcAttr = self.ch.attribute(attributeId=2)
        modifier = Modifier()
        modifier.state = State.offline
        modifier.context = Context.local
        modifier.sourceAttributeId = srcAttr.id
        modifier.operator = Operator.postPercent
        modifier.targetAttributeId = self.tgtAttr.id
        modifier.location = Location.other
        modifier.filterType = None
        modifier.filterValue = None
        effect = self.ch.effect(effectId=1, categoryId=EffectCategory.passive)
        effect.modifiers = (modifier, )
        # We added target attribute to influence source for testSelf;
        # currently, eos cannot calculate attributes which are originally
        # missing on item
        self.influenceSource = ItemWithOther(
            self.ch.type_(typeId=1,
                          effects=(effect, ),
                          attributes={
                              self.tgtAttr.id: 100,
                              srcAttr.id: 20
                          }))
        self.fit.items.add(self.influenceSource)

    def testOtherLocation(self):
        influenceTarget = ItemWithOther(
            self.ch.type_(typeId=2, attributes={self.tgtAttr.id: 100}))
        self.influenceSource.makeOtherLink(influenceTarget)
        self.fit.items.add(influenceTarget)
        self.assertNotAlmostEqual(influenceTarget.attributes[self.tgtAttr.id],
                                  100)
        self.fit.items.remove(self.influenceSource)
        self.influenceSource.breakOtherLink(influenceTarget)
        self.assertAlmostEqual(influenceTarget.attributes[self.tgtAttr.id],
                               100)
        self.fit.items.remove(influenceTarget)
        self.assertEqual(len(self.log), 0)
        self.assertLinkBuffersEmpty(self.fit)

    def testSelf(self):
        # Check that source holder isn't modified
        influenceTarget = ItemWithOther(
            self.ch.type_(typeId=2, attributes={self.tgtAttr.id: 100}))
        self.influenceSource.makeOtherLink(influenceTarget)
        self.fit.items.add(influenceTarget)
        self.assertAlmostEqual(
            self.influenceSource.attributes[self.tgtAttr.id], 100)
        self.fit.items.remove(influenceTarget)
        self.influenceSource.breakOtherLink(influenceTarget)
        self.fit.items.remove(self.influenceSource)
        self.assertEqual(len(self.log), 0)
        self.assertLinkBuffersEmpty(self.fit)

    def testOtherHolder(self):
        # Here we check some "random" holder, w/o linking holders
        influenceTarget = IndependentItem(
            self.ch.type_(typeId=2, attributes={self.tgtAttr.id: 100}))
        self.fit.items.add(influenceTarget)
        self.assertAlmostEqual(influenceTarget.attributes[self.tgtAttr.id],
                               100)
        self.fit.items.remove(self.influenceSource)
        self.fit.items.remove(influenceTarget)
        self.assertEqual(len(self.log), 0)
        self.assertLinkBuffersEmpty(self.fit)