def testFail(self): # Check that error is raised when number of used # slots exceeds slot amount provided by ship fit = Fit() item = self.ch.type_(typeId=1) item.slots = {Slot.moduleHigh} holder1 = ShipItem(item) fit.items.add(holder1) holder2 = ShipItem(item) fit.items.add(holder2) ship = IndependentItem(self.ch.type_(typeId=2)) ship.attributes[Attribute.hiSlots] = 1 fit.ship = ship restrictionError1 = fit.getRestrictionError(holder1, Restriction.highSlot) self.assertIsNotNone(restrictionError1) self.assertEqual(restrictionError1.slotsMax, 1) self.assertEqual(restrictionError1.slotsUsed, 2) restrictionError2 = fit.getRestrictionError(holder2, Restriction.highSlot) self.assertIsNotNone(restrictionError2) self.assertEqual(restrictionError2.slotsMax, 1) self.assertEqual(restrictionError2.slotsUsed, 2) fit.items.remove(holder1) fit.items.remove(holder2) fit.ship = None self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testMixExcessOriginal(self): # Check that original item attributes are used fit = Fit() holder1 = ShipItem( self.ch.type_(typeId=1, groupId=61, attributes={Attribute.maxGroupFitted: 1})) holder1.attributes[Attribute.maxGroupFitted] = 2 fit.items.add(holder1) holder2 = ShipItem( self.ch.type_(typeId=2, groupId=61, attributes={Attribute.maxGroupFitted: 2})) holder2.attributes[Attribute.maxGroupFitted] = 1 fit.items.add(holder2) restrictionError1 = fit.getRestrictionError(holder1, Restriction.maxGroupFitted) self.assertIsNotNone(restrictionError1) self.assertEqual(restrictionError1.maxGroup, 1) self.assertEqual(restrictionError1.holderGroup, 61) self.assertEqual(restrictionError1.groupHolders, 2) restrictionError2 = fit.getRestrictionError(holder2, Restriction.maxGroupFitted) self.assertIsNone(restrictionError2) fit.items.remove(holder1) fit.items.remove(holder2) self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testFailExcessAll(self): # Make sure error is raised for all holders exceeding # their group restriction fit = Fit() item = self.ch.type_(typeId=1, groupId=6, attributes={Attribute.maxGroupOnline: 1}) holder1 = ShipItem(item) holder1.state = State.online fit.items.add(holder1) holder2 = ShipItem(item) holder2.state = State.online fit.items.add(holder2) restrictionError1 = fit.getRestrictionError(holder1, Restriction.maxGroupOnline) self.assertIsNotNone(restrictionError1) self.assertEqual(restrictionError1.maxGroup, 1) self.assertEqual(restrictionError1.holderGroup, 6) self.assertEqual(restrictionError1.groupHolders, 2) restrictionError2 = fit.getRestrictionError(holder2, Restriction.maxGroupOnline) self.assertIsNotNone(restrictionError2) self.assertEqual(restrictionError2.maxGroup, 1) self.assertEqual(restrictionError2.holderGroup, 6) self.assertEqual(restrictionError2.groupHolders, 2) fit.items.remove(holder1) fit.items.remove(holder2) self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testFailModified(self): # Make sure that modified number of slot output # is taken fit = Fit() item = self.ch.type_(typeId=1) item.slots = {Slot.moduleHigh} holder1 = ShipItem(item) fit.items.add(holder1) holder2 = ShipItem(item) fit.items.add(holder2) ship = IndependentItem(self.ch.type_(typeId=2, attributes={Attribute.hiSlots: 5})) ship.attributes[Attribute.hiSlots] = 1 fit.ship = ship restrictionError1 = fit.getRestrictionError(holder1, Restriction.highSlot) self.assertIsNotNone(restrictionError1) self.assertEqual(restrictionError1.slotsMax, 1) self.assertEqual(restrictionError1.slotsUsed, 2) restrictionError2 = fit.getRestrictionError(holder2, Restriction.highSlot) self.assertIsNotNone(restrictionError2) self.assertEqual(restrictionError2.slotsMax, 1) self.assertEqual(restrictionError2.slotsUsed, 2) fit.items.remove(holder1) fit.items.remove(holder2) fit.ship = None self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testMixExcessOne(self): # Make sure error is raised for just holders which excess # restriction,even if they're from the same group fit = Fit() holder1 = ShipItem( self.ch.type_(typeId=1, groupId=92, attributes={Attribute.maxGroupFitted: 1})) fit.items.add(holder1) holder2 = ShipItem( self.ch.type_(typeId=2, groupId=92, attributes={Attribute.maxGroupFitted: 2})) fit.items.add(holder2) restrictionError1 = fit.getRestrictionError(holder1, Restriction.maxGroupFitted) self.assertIsNotNone(restrictionError1) self.assertEqual(restrictionError1.maxGroup, 1) self.assertEqual(restrictionError1.holderGroup, 92) self.assertEqual(restrictionError1.groupHolders, 2) restrictionError2 = fit.getRestrictionError(holder2, Restriction.maxGroupFitted) self.assertIsNone(restrictionError2) fit.items.remove(holder1) fit.items.remove(holder2) self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testFailExcessAll(self): # Make sure error is raised for all holders exceeding # their group restriction fit = Fit() item = self.ch.type_(typeId=1, groupId=6, attributes={Attribute.maxGroupFitted: 1}) holder1 = ShipItem(item) fit.items.add(holder1) holder2 = ShipItem(item) fit.items.add(holder2) restrictionError1 = fit.getRestrictionError(holder1, Restriction.maxGroupFitted) self.assertIsNotNone(restrictionError1) self.assertEqual(restrictionError1.maxGroup, 1) self.assertEqual(restrictionError1.holderGroup, 6) self.assertEqual(restrictionError1.groupHolders, 2) restrictionError2 = fit.getRestrictionError(holder2, Restriction.maxGroupFitted) self.assertIsNotNone(restrictionError2) self.assertEqual(restrictionError2.maxGroup, 1) self.assertEqual(restrictionError2.holderGroup, 6) self.assertEqual(restrictionError2.groupHolders, 2) fit.items.remove(holder1) fit.items.remove(holder2) self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testPassState(self): # No errors should occur if holders are not online+ fit = Fit() item = self.ch.type_(typeId=1, groupId=886, attributes={Attribute.maxGroupOnline: 1}) holder1 = ShipItem(item) fit.items.add(holder1) holder2 = ShipItem(item) fit.items.add(holder2) restrictionError1 = fit.getRestrictionError(holder1, Restriction.maxGroupOnline) self.assertIsNone(restrictionError1) restrictionError2 = fit.getRestrictionError(holder2, Restriction.maxGroupOnline) self.assertIsNone(restrictionError2) fit.items.remove(holder1) fit.items.remove(holder2) self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testPassState(self): # No errors should occur if holders are not active+ fit = Fit() item = self.ch.type_(typeId=1, groupId=886, attributes={Attribute.maxGroupActive: 1}) holder1 = ShipItem(item) holder1.state = State.online fit.items.append(holder1) holder2 = ShipItem(item) holder2.state = State.online fit.items.append(holder2) restrictionError1 = fit.getRestrictionError(holder1, Restriction.maxGroupActive) self.assertIsNone(restrictionError1) restrictionError2 = fit.getRestrictionError(holder2, Restriction.maxGroupActive) self.assertIsNone(restrictionError2) fit.items.remove(holder1) fit.items.remove(holder2) self.assertBuffersEmpty(fit)
def testPassHolderNoneGroup(self): # Check that holders with None group are not affected fit = Fit() item = self.ch.type_(typeId=1, groupId=None, attributes={Attribute.maxGroupOnline: 1}) holder1 = ShipItem(item) holder1.state = State.online fit.items.append(holder1) holder2 = ShipItem(item) holder2.state = State.online fit.items.append(holder2) restrictionError1 = fit.getRestrictionError(holder1, Restriction.maxGroupOnline) self.assertIsNone(restrictionError1) restrictionError2 = fit.getRestrictionError(holder2, Restriction.maxGroupOnline) self.assertIsNone(restrictionError2) fit.items.remove(holder1) fit.items.remove(holder2) self.assertBuffersEmpty(fit)
def testPass(self): # Make sure no errors are raised when number of added # items doesn't exceed any restrictions fit = Fit() item = self.ch.type_(typeId=1, groupId=860, attributes={Attribute.maxGroupOnline: 2}) holder1 = ShipItem(item) holder1.state = State.online fit.items.append(holder1) holder2 = ShipItem(item) holder2.state = State.online fit.items.append(holder2) restrictionError1 = fit.getRestrictionError(holder1, Restriction.maxGroupOnline) self.assertIsNone(restrictionError1) restrictionError2 = fit.getRestrictionError(holder2, Restriction.maxGroupOnline) self.assertIsNone(restrictionError2) fit.items.remove(holder1) fit.items.remove(holder2) self.assertBuffersEmpty(fit)
def testPassHolderNoneGroup(self): # Check that holders with None group are not affected fit = Fit() item = self.ch.type_(typeId=1, groupId=None, attributes={Attribute.maxGroupFitted: 1}) holder1 = ShipItem(item) fit.items.add(holder1) holder2 = ShipItem(item) fit.items.add(holder2) restrictionError1 = fit.getRestrictionError(holder1, Restriction.maxGroupFitted) self.assertIsNone(restrictionError1) restrictionError2 = fit.getRestrictionError(holder2, Restriction.maxGroupFitted) self.assertIsNone(restrictionError2) fit.items.remove(holder1) fit.items.remove(holder2) self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testPassSubcapitalShipHolder(self): # Make sure no error raised when non-capital # item is added to fit fit = Fit() holder = ShipItem(self.ch.type_(typeId=1, attributes={Attribute.volume: 500})) fit.items.add(holder) restrictionError = fit.getRestrictionError(holder, Restriction.capitalItem) self.assertIsNone(restrictionError) fit.items.remove(holder) self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testMixExcessOne(self): # Make sure error is raised for just holders which excess # restriction,even if they're from the same group fit = Fit() holder1 = ShipItem(self.ch.type_(typeId=1, groupId=92, attributes={Attribute.maxGroupOnline: 1})) holder1.state = State.online fit.items.append(holder1) holder2 = ShipItem(self.ch.type_(typeId=2, groupId=92, attributes={Attribute.maxGroupOnline: 2})) holder2.state = State.online fit.items.append(holder2) restrictionError1 = fit.getRestrictionError(holder1, Restriction.maxGroupOnline) self.assertIsNotNone(restrictionError1) self.assertEqual(restrictionError1.maxGroup, 1) self.assertEqual(restrictionError1.holderGroup, 92) self.assertEqual(restrictionError1.groupHolders, 2) restrictionError2 = fit.getRestrictionError(holder2, Restriction.maxGroupOnline) self.assertIsNone(restrictionError2) fit.items.remove(holder1) fit.items.remove(holder2) self.assertBuffersEmpty(fit)
def testMixExcessOriginal(self): # Check that original item attributes are used fit = Fit() holder1 = ShipItem(self.ch.type_(typeId=1, groupId=61, attributes={Attribute.maxGroupOnline: 1})) holder1.attributes[Attribute.maxGroupOnline] = 2 holder1.state = State.online fit.items.append(holder1) holder2 = ShipItem(self.ch.type_(typeId=2, groupId=61, attributes={Attribute.maxGroupOnline: 2})) holder2.attributes[Attribute.maxGroupOnline] = 1 holder2.state = State.online fit.items.append(holder2) restrictionError1 = fit.getRestrictionError(holder1, Restriction.maxGroupOnline) self.assertIsNotNone(restrictionError1) self.assertEqual(restrictionError1.maxGroup, 1) self.assertEqual(restrictionError1.holderGroup, 61) self.assertEqual(restrictionError1.groupHolders, 2) restrictionError2 = fit.getRestrictionError(holder2, Restriction.maxGroupOnline) self.assertIsNone(restrictionError2) fit.items.remove(holder1) fit.items.remove(holder2) self.assertBuffersEmpty(fit)
def testPassNoVolume(self): # Check that items with no volume attribute are not restricted fit = Fit() holder = ShipItem(self.ch.type_(typeId=1)) fit.items.add(holder) fit.ship = IndependentItem(self.ch.type_(typeId=2)) restrictionError = fit.getRestrictionError(holder, Restriction.capitalItem) self.assertIsNone(restrictionError) fit.items.remove(holder) fit.ship = None self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testPass(self): # Make sure no errors are raised when number of added # items doesn't exceed any restrictions fit = Fit() item = self.ch.type_(typeId=1, groupId=860, attributes={Attribute.maxGroupFitted: 2}) holder1 = ShipItem(item) fit.items.add(holder1) holder2 = ShipItem(item) fit.items.add(holder2) restrictionError1 = fit.getRestrictionError(holder1, Restriction.maxGroupFitted) self.assertIsNone(restrictionError1) restrictionError2 = fit.getRestrictionError(holder2, Restriction.maxGroupFitted) self.assertIsNone(restrictionError2) fit.items.remove(holder1) fit.items.remove(holder2) self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testPassNonSlot(self): # If holders don't use slot, no error should # be raised fit = Fit() item = self.ch.type_(typeId=1) holder1 = ShipItem(item) fit.items.add(holder1) holder2 = ShipItem(item) fit.items.add(holder2) ship = IndependentItem(self.ch.type_(typeId=2)) ship.attributes[Attribute.hiSlots] = 1 fit.ship = ship restrictionError1 = fit.getRestrictionError(holder1, Restriction.highSlot) self.assertIsNone(restrictionError1) restrictionError2 = fit.getRestrictionError(holder2, Restriction.highSlot) self.assertIsNone(restrictionError2) fit.items.remove(holder1) fit.items.remove(holder2) fit.ship = None self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testFailNoShip(self): # Check that error is raised on attempt # to add capital item to fit w/o ship fit = Fit() holder = ShipItem(self.ch.type_(typeId=1, attributes={Attribute.volume: 501})) fit.items.add(holder) restrictionError = fit.getRestrictionError(holder, Restriction.capitalItem) self.assertIsNotNone(restrictionError) self.assertEqual(restrictionError.allowedVolume, 500) self.assertEqual(restrictionError.holderVolume, 501) fit.items.remove(holder) self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testPass(self): # No error is raised when slot users do not # exceed slot output fit = Fit() item = self.ch.type_(typeId=1) item.slots = {Slot.moduleHigh} holder1 = ShipItem(item) fit.items.add(holder1) holder2 = ShipItem(item) fit.items.add(holder2) ship = IndependentItem(self.ch.type_(typeId=2)) ship.attributes[Attribute.hiSlots] = 3 fit.ship = ship restrictionError1 = fit.getRestrictionError(holder1, Restriction.highSlot) self.assertIsNone(restrictionError1) restrictionError2 = fit.getRestrictionError(holder2, Restriction.highSlot) self.assertIsNone(restrictionError2) fit.items.remove(holder1) fit.items.remove(holder2) fit.ship = None self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testPassCapitalShip(self): # Check that capital holders can be added to # capital ship fit = Fit() holder = ShipItem(self.ch.type_(typeId=1, attributes={Attribute.volume: 501})) fit.items.add(holder) shipItem = self.ch.type_(typeId=2) shipItem.requiredSkills = {ConstType.capitalShips: 1} fit.ship = IndependentItem(shipItem) restrictionError = fit.getRestrictionError(holder, Restriction.capitalItem) self.assertIsNone(restrictionError) fit.items.remove(holder) fit.ship = None self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testFailNoShip(self): # Make sure that absence of ship # is considered as 0 output fit = Fit() item = self.ch.type_(typeId=1) item.slots = {Slot.moduleHigh} holder = ShipItem(item) fit.items.add(holder) restrictionError = fit.getRestrictionError(holder, Restriction.highSlot) self.assertIsNotNone(restrictionError) self.assertEqual(restrictionError.slotsMax, 0) self.assertEqual(restrictionError.slotsUsed, 1) fit.items.remove(holder) self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testPassGroupMatch(self): # When type of ship matches group-restriction attribute, # no error should be raised fit = Fit() ship = IndependentItem(self.ch.type_(typeId=554, groupId=23)) fit.ship = ship holder = ShipItem( self.ch.type_(typeId=1, attributes={Attribute.canFitShipGroup1: 23})) fit.items.add(holder) restrictionError = fit.getRestrictionError(holder, Restriction.shipTypeGroup) self.assertIsNone(restrictionError) fit.items.remove(holder) fit.ship = None self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testFailNoShip(self): # Absent ship should trigger this error too fit = Fit() holder = ShipItem( self.ch.type_(typeId=1, attributes={Attribute.canFitShipType1: 10})) fit.items.add(holder) restrictionError = fit.getRestrictionError(holder, Restriction.shipTypeGroup) self.assertIsNotNone(restrictionError) self.assertCountEqual(restrictionError.allowedTypes, (10, )) self.assertCountEqual(restrictionError.allowedGroups, ()) self.assertEqual(restrictionError.shipType, None) self.assertEqual(restrictionError.shipGroup, None) fit.items.remove(holder) self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testFailOriginalVolume(self): # Make sure original volume value is taken fit = Fit() holder = ShipItem(self.ch.type_(typeId=1, attributes={Attribute.volume: 501})) # Set volume below 500 to check that even when # modified attributes are available, raw attributes # are taken holder.attributes[Attribute.volume] = 100 fit.items.add(holder) fit.ship = IndependentItem(self.ch.type_(typeId=2)) restrictionError = fit.getRestrictionError(holder, Restriction.capitalItem) self.assertIsNotNone(restrictionError) self.assertEqual(restrictionError.allowedVolume, 500) self.assertEqual(restrictionError.holderVolume, 501) fit.items.remove(holder) fit.ship = None self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testFailShipNoAttr(self): # Make sure that absence of specifier of slot output # is considered as 0 output fit = Fit() item = self.ch.type_(typeId=1) item.slots = {Slot.moduleHigh} holder = ShipItem(item) fit.items.add(holder) ship = IndependentItem(self.ch.type_(typeId=2)) fit.ship = ship restrictionError = fit.getRestrictionError(holder, Restriction.highSlot) self.assertIsNotNone(restrictionError) self.assertEqual(restrictionError.slotsMax, 0) self.assertEqual(restrictionError.slotsUsed, 1) fit.items.remove(holder) fit.ship = None self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testFailType5(self): # Check that fifth type-restriction attribute affects # holder fit = Fit() ship = IndependentItem(self.ch.type_(typeId=772, groupId=31)) fit.ship = ship holder = ShipItem( self.ch.type_(typeId=1, attributes={Attribute.fitsToShipType: 10})) fit.items.add(holder) restrictionError = fit.getRestrictionError(holder, Restriction.shipTypeGroup) self.assertIsNotNone(restrictionError) self.assertCountEqual(restrictionError.allowedTypes, (10, )) self.assertCountEqual(restrictionError.allowedGroups, ()) self.assertEqual(restrictionError.shipType, 772) self.assertEqual(restrictionError.shipGroup, 31) fit.items.remove(holder) fit.ship = None self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testPassCombinedMatch(self): # Check that it's enough to match any condition # to be fittable fit = Fit() ship = IndependentItem(self.ch.type_(typeId=554, groupId=23)) fit.ship = ship holder = ShipItem( self.ch.type_(typeId=1, attributes={ Attribute.canFitShipType1: 1089, Attribute.canFitShipGroup1: 23 })) fit.items.add(holder) restrictionError = fit.getRestrictionError(holder, Restriction.shipTypeGroup) self.assertIsNone(restrictionError) fit.items.remove(holder) fit.ship = None self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testFailAttrOriginal(self): # Make sure original value is taken fit = Fit() ship = IndependentItem(self.ch.type_(typeId=772, groupId=31)) fit.ship = ship holder = ShipItem( self.ch.type_(typeId=1, attributes={Attribute.canFitShipType1: 10})) holder.attributes[Attribute.canFitShipType1] = 772 fit.items.add(holder) restrictionError = fit.getRestrictionError(holder, Restriction.shipTypeGroup) self.assertIsNotNone(restrictionError) self.assertCountEqual(restrictionError.allowedTypes, (10, )) self.assertCountEqual(restrictionError.allowedGroups, ()) self.assertEqual(restrictionError.shipType, 772) self.assertEqual(restrictionError.shipGroup, 31) fit.items.remove(holder) fit.ship = None self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)
def testFailCombined(self): # Check that failure is appropriately generated when # holder specifies both type and group restrictions fit = Fit() ship = IndependentItem(self.ch.type_(typeId=772, groupId=31)) fit.ship = ship holder = ShipItem( self.ch.type_(typeId=1, attributes={ Attribute.canFitShipType1: 1089, Attribute.canFitShipGroup1: 23 })) fit.items.add(holder) restrictionError = fit.getRestrictionError(holder, Restriction.shipTypeGroup) self.assertIsNotNone(restrictionError) self.assertCountEqual(restrictionError.allowedTypes, (1089, )) self.assertCountEqual(restrictionError.allowedGroups, (23, )) self.assertEqual(restrictionError.shipType, 772) self.assertEqual(restrictionError.shipGroup, 31) fit.items.remove(holder) fit.ship = None self.assertEqual(len(self.log), 0) self.assertRestrictionBuffersEmpty(fit)