示例#1
0
文件: test_cpu.py 项目: Ebag333/eos
 def test_fail_excess_multiple(self):
     # When multiple consumers require less than cpu output
     # alone, but in sum want more than total output, it should
     # be erroneous situation
     item = self.ch.type_(type_id=1, attributes={Attribute.cpu: 0})
     holder1 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder1.attributes = {Attribute.cpu: 25}
     self.track_holder(holder1)
     holder2 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2.attributes = {Attribute.cpu: 20}
     self.track_holder(holder2)
     self.fit.stats.cpu.used = 45
     self.fit.stats.cpu.output = 40
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.cpu)
     self.assertIsNotNone(restriction_error1)
     self.assertEqual(restriction_error1.output, 40)
     self.assertEqual(restriction_error1.total_use, 45)
     self.assertEqual(restriction_error1.holder_use, 25)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.cpu)
     self.assertIsNotNone(restriction_error2)
     self.assertEqual(restriction_error2.output, 40)
     self.assertEqual(restriction_error2.total_use, 45)
     self.assertEqual(restriction_error2.holder_use, 20)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#2
0
 def test_cache(self):
     ship_item = self.ch.type_(type_id=1)
     ship_holder = Mock(state=State.offline,
                        item=ship_item,
                        _domain=None,
                        spec_set=Ship(1))
     ship_holder.attributes = {Attribute.subsystem_slot: 6}
     self.set_ship(ship_holder)
     item = self.ch.type_(type_id=2, attributes={})
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.fit.subsystems.add(holder1)
     self.fit.subsystems.add(holder2)
     self.assertEqual(self.st.subsystem_slots.used, 2)
     self.assertEqual(self.st.subsystem_slots.total, 6)
     ship_holder.attributes[Attribute.subsystem_slot] = 4
     self.fit.subsystems.remove(holder1)
     self.assertEqual(self.st.subsystem_slots.used, 2)
     self.assertEqual(self.st.subsystem_slots.total, 6)
     self.set_ship(None)
     self.assertEqual(len(self.log), 0)
     self.assert_stat_buffers_empty()
示例#3
0
 def setUp(self):
     super().setUp()
     self.holder = Module(type_id=None)
     self.holder.attributes = {}
     self.charge = Charge(type_id=None)
     self.charge.attributes = {}
     self.holder.charge = self.charge
示例#4
0
 def test_multiple(self):
     item = self.ch.type_(type_id=1, attributes={})
     holder1 = Mock(state=State.active, item=item, spec=Module(1))
     holder2 = Mock(state=State.active, item=item, spec=Module(1))
     self.track_holder(holder1)
     self.track_holder(holder2)
     holder1_volley = Mock(em=1.2,
                           thermal=2.3,
                           kinetic=3.4,
                           explosive=4.5,
                           total=5.6)
     holder2_volley = Mock(em=0,
                           thermal=4,
                           kinetic=2,
                           explosive=7.1,
                           total=99)
     holder1.get_nominal_volley.return_value = holder1_volley
     holder2.get_nominal_volley.return_value = holder2_volley
     stats_volley = self.st.get_nominal_volley()
     self.assertAlmostEqual(stats_volley.em, 1.2)
     self.assertAlmostEqual(stats_volley.thermal, 6.3)
     self.assertAlmostEqual(stats_volley.kinetic, 5.4)
     self.assertAlmostEqual(stats_volley.explosive, 11.6)
     self.assertAlmostEqual(stats_volley.total, 24.5)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_stat_buffers_empty()
示例#5
0
文件: test_cpu.py 项目: Ebag333/eos
 def test_mix_usage_zero(self):
     # If some holder has zero usage and cpu error is
     # still raised, check it's not raised for holder with
     # zero usage
     item = self.ch.type_(type_id=1, attributes={Attribute.cpu: 0})
     holder1 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder1.attributes = {Attribute.cpu: 100}
     self.track_holder(holder1)
     holder2 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2.attributes = {Attribute.cpu: 0}
     self.track_holder(holder2)
     self.fit.stats.cpu.used = 100
     self.fit.stats.cpu.output = 50
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.cpu)
     self.assertIsNotNone(restriction_error1)
     self.assertEqual(restriction_error1.output, 50)
     self.assertEqual(restriction_error1.total_use, 100)
     self.assertEqual(restriction_error1.holder_use, 100)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.cpu)
     self.assertIsNone(restriction_error2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#6
0
 def test_pass_state(self):
     # No errors should occur if holders are not active+
     item = self.ch.type_(type_id=1,
                          group=886,
                          attributes={Attribute.max_group_online: 1})
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder1)
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder2)
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.max_group_online)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.max_group_online)
     self.assertIsNone(restriction_error2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#7
0
 def test_mix_excess_one(self):
     # Make sure error is raised for just holders which excess
     # restriction, even if both are from the same group
     item1 = self.ch.type_(type_id=1,
                           group=92,
                           attributes={Attribute.max_group_online: 1})
     holder1 = Mock(state=State.online,
                    item=item1,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder1)
     item2 = self.ch.type_(type_id=2,
                           group=92,
                           attributes={Attribute.max_group_online: 2})
     holder2 = Mock(state=State.online,
                    item=item2,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder2)
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.max_group_online)
     self.assertIsNotNone(restriction_error1)
     self.assertEqual(restriction_error1.max_group, 1)
     self.assertEqual(restriction_error1.holder_group, 92)
     self.assertEqual(restriction_error1.group_holders, 2)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.max_group_online)
     self.assertIsNone(restriction_error2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#8
0
 def testAttachedFitAddChargedModule(self):
     eos = Mock(spec_set=())
     fit = self._makeFit(eos=eos)
     module = Module(1, state=State.active, charge=None)
     charge = Charge(2)
     module.charge = charge
     self.expectModuleChargeLink = True
     # Action
     fit.ordered.append(module)
     # Checks
     self.assertEqual(len(fit.lt), 2)
     self.assertIn(module, fit.lt)
     self.assertEqual(fit.lt[module], {State.offline, State.online, State.active})
     self.assertIn(charge, fit.lt)
     self.assertEqual(fit.lt[charge], {State.offline})
     self.assertEqual(len(fit.rt), 2)
     self.assertIn(module, fit.rt)
     self.assertEqual(fit.rt[module], {State.offline, State.online, State.active})
     self.assertIn(charge, fit.rt)
     self.assertEqual(fit.rt[charge], {State.offline})
     self.assertEqual(len(fit.ordered), 1)
     self.assertIs(fit.ordered[0], module)
     self.assertIs(module.charge, charge)
     self.assertIs(module._other, charge)
     self.assertIs(charge.container, module)
     self.assertIs(charge._other, module)
     self.assertIs(module._fit, fit)
     self.assertIs(charge._fit, fit)
     # Misc
     self.expectModuleChargeLink = None
     fit.ordered.remove(module)
     self.assertFitBuffersEmpty(fit)
示例#9
0
 def testDetachedModuleNoneToNone(self):
     module = Module(1, state=State.active, charge=None)
     # Action
     module.charge = None
     # Checks
     self.assertIsNone(module.charge)
     self.assertIsNone(module._other)
示例#10
0
 def test_mix_excess_original(self):
     # Check that original item attributes are used
     item1 = self.ch.type_(type_id=1,
                           group=61,
                           attributes={Attribute.max_group_online: 1})
     holder1 = Mock(state=State.online,
                    item=item1,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder1.attributes = {Attribute.max_group_online: 2}
     self.track_holder(holder1)
     item2 = self.ch.type_(type_id=2,
                           group=61,
                           attributes={Attribute.max_group_online: 2})
     holder2 = Mock(state=State.online,
                    item=item2,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2.attributes = {Attribute.max_group_online: 1}
     self.track_holder(holder2)
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.max_group_online)
     self.assertIsNotNone(restriction_error1)
     self.assertEqual(restriction_error1.max_group, 1)
     self.assertEqual(restriction_error1.holder_group, 61)
     self.assertEqual(restriction_error1.group_holders, 2)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.max_group_online)
     self.assertIsNone(restriction_error2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#11
0
 def test_filter_mixed(self):
     item = self.ch.type_(type_id=1, attributes={})
     holder1 = Mock(state=State.active, item=item, spec=Module(1))
     holder2 = Mock(state=State.active, item=item, spec=Module(1))
     self.track_holder(holder1)
     self.track_holder(holder2)
     holder1_dps = Mock(em=1.2,
                        thermal=2.3,
                        kinetic=3.4,
                        explosive=4.5,
                        total=5.6)
     holder2_dps = Mock(em=0, thermal=4, kinetic=2, explosive=7.1, total=99)
     holder1.get_nominal_dps.return_value = holder1_dps
     holder2.get_nominal_dps.return_value = holder2_dps
     stats_dps = self.st.get_nominal_dps(
         holder_filter=lambda h: h is holder2)
     self.assertAlmostEqual(stats_dps.em, 0)
     self.assertAlmostEqual(stats_dps.thermal, 4)
     self.assertAlmostEqual(stats_dps.kinetic, 2)
     self.assertAlmostEqual(stats_dps.explosive, 7.1)
     self.assertAlmostEqual(stats_dps.total, 13.1)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_stat_buffers_empty()
示例#12
0
 def test_cache(self):
     ship_item = self.ch.type_(type_id=1,
                               attributes={Attribute.power_output: 10})
     ship_holder = Mock(state=State.offline,
                        item=ship_item,
                        _domain=None,
                        spec_set=Ship(1))
     ship_holder.attributes = {Attribute.power_output: 50}
     self.set_ship(ship_holder)
     item = self.ch.type_(type_id=2, attributes={Attribute.power: 0})
     holder1 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder1.attributes = {Attribute.power: 50}
     self.track_holder(holder1)
     holder2 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2.attributes = {Attribute.power: 30}
     self.track_holder(holder2)
     self.assertEqual(self.st.powergrid.used, 80)
     self.assertEqual(self.st.powergrid.output, 50)
     holder1.attributes[Attribute.power] = 10
     ship_holder.attributes[Attribute.power_output] = 60
     self.assertEqual(self.st.powergrid.used, 80)
     self.assertEqual(self.st.powergrid.output, 50)
     self.set_ship(None)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_stat_buffers_empty()
示例#13
0
 def test_volatility(self):
     ship_item = self.ch.type_(type_id=1,
                               attributes={Attribute.upgrade_capacity: 10})
     ship_holder = Mock(state=State.offline,
                        item=ship_item,
                        _domain=None,
                        spec_set=Ship(1))
     ship_holder.attributes = {Attribute.upgrade_capacity: 50}
     self.set_ship(ship_holder)
     item = self.ch.type_(type_id=2, attributes={Attribute.upgrade_cost: 0})
     holder1 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder1.attributes = {Attribute.upgrade_cost: 50}
     self.track_holder(holder1)
     holder2 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2.attributes = {Attribute.upgrade_cost: 30}
     self.track_holder(holder2)
     self.assertEqual(self.st.calibration.used, 80)
     self.assertEqual(self.st.calibration.output, 50)
     holder1.attributes[Attribute.upgrade_cost] = 10
     ship_holder.attributes[Attribute.upgrade_capacity] = 60
     self.st._clear_volatile_attrs()
     self.assertEqual(self.st.calibration.used, 40)
     self.assertEqual(self.st.calibration.output, 60)
     self.set_ship(None)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_stat_buffers_empty()
示例#14
0
文件: test_cpu.py 项目: Ebag333/eos
 def test_pass(self):
     # When total consumption is less than output,
     # no errors should be raised
     item = self.ch.type_(type_id=1, attributes={Attribute.cpu: 0})
     holder1 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder1.attributes = {Attribute.cpu: 25}
     self.track_holder(holder1)
     holder2 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2.attributes = {Attribute.cpu: 20}
     self.track_holder(holder2)
     self.fit.stats.cpu.used = 45
     self.fit.stats.cpu.output = 50
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.cpu)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.cpu)
     self.assertIsNone(restriction_error2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#15
0
 def test_pass_greater(self):
     item = self.ch.type_(type_id=1)
     item.slots = {Slot.turret}
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder1)
     self.track_holder(holder2)
     self.fit.stats.turret_slots.used = 2
     self.fit.stats.turret_slots.total = 5
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.turret_slot)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.turret_slot)
     self.assertIsNone(restriction_error2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#16
0
 def test_fail_excess_multiple_with_nones(self):
     # Make sure Nones are processed properly
     item = self.ch.type_(type_id=1)
     holder1 = Mock(state=State.offline, item=item, _domain=Domain.ship, spec_set=Module(1))
     holder2 = Mock(state=State.offline, item=item, _domain=Domain.ship, spec_set=Module(1))
     holder3 = Mock(state=State.offline, item=item, _domain=Domain.ship, spec_set=Module(1))
     self.fit.modules.med.append(None)
     self.fit.modules.med.append(holder1)
     self.fit.modules.med.append(None)
     self.fit.modules.med.append(None)
     self.fit.modules.med.append(holder2)
     self.fit.modules.med.append(None)
     self.fit.modules.med.append(holder3)
     self.fit.stats.med_slots.used = 7
     self.fit.stats.med_slots.total = 3
     restriction_error1 = self.get_restriction_error(holder1, Restriction.medium_slot)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(holder2, Restriction.medium_slot)
     self.assertIsNotNone(restriction_error2)
     self.assertEqual(restriction_error2.slots_max_allowed, 3)
     self.assertEqual(restriction_error2.slots_used, 7)
     restriction_error3 = self.get_restriction_error(holder2, Restriction.medium_slot)
     self.assertIsNotNone(restriction_error3)
     self.assertEqual(restriction_error3.slots_max_allowed, 3)
     self.assertEqual(restriction_error3.slots_used, 7)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#17
0
 def test_fail_excess_multiple(self):
     # Check that error works for multiple holders
     item = self.ch.type_(type_id=1)
     item.slots = {Slot.turret}
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder1)
     self.track_holder(holder2)
     self.fit.stats.turret_slots.used = 2
     self.fit.stats.turret_slots.total = 1
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.turret_slot)
     self.assertIsNotNone(restriction_error1)
     self.assertEqual(restriction_error1.slots_max_allowed, 1)
     self.assertEqual(restriction_error1.slots_used, 2)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.turret_slot)
     self.assertIsNotNone(restriction_error2)
     self.assertEqual(restriction_error2.slots_max_allowed, 1)
     self.assertEqual(restriction_error2.slots_used, 2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#18
0
 def testDetachedFitChargeToBoundCharge(self):
     fit = self._makeFit()
     fitOther = self._makeFit()
     module = Module(1, state=State.active, charge=None)
     charge1 = Charge(2)
     charge2 = Charge(3)
     fit.ordered.append(module)
     fitOther.ordered.append(charge2)
     module.charge = charge1
     # Action
     self.assertRaises(ValueError, module.__setattr__, 'charge', charge2)
     # Checks
     self.assertEqual(len(fit.lt), 0)
     self.assertEqual(len(fit.rt), 0)
     self.assertEqual(len(fitOther.lt), 0)
     self.assertEqual(len(fitOther.rt), 0)
     self.assertIs(module.charge, charge1)
     self.assertIs(module._other, charge1)
     self.assertIs(charge1.container, module)
     self.assertIs(charge1._other, module)
     self.assertIsNone(charge2.container)
     self.assertIsNone(charge2._other)
     self.assertIs(module._fit, fit)
     self.assertIs(charge1._fit, fit)
     self.assertIs(charge2._fit, fitOther)
     # Misc
     fit.ordered.remove(module)
     fitOther.ordered.remove(charge2)
     self.assertFitBuffersEmpty(fit)
     self.assertFitBuffersEmpty(fitOther)
示例#19
0
 def test_pass(self):
     # Make sure no errors are raised when number of added
     # items doesn't exceed any restrictions
     item = self.ch.type_(type_id=1,
                          group=860,
                          attributes={Attribute.max_group_online: 2})
     holder1 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder1)
     holder2 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder2)
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.max_group_online)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.max_group_online)
     self.assertIsNone(restriction_error2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#20
0
 def test_volatility(self):
     ship_item = self.ch.type_(type_id=1)
     ship_holder = Mock(state=State.offline,
                        item=ship_item,
                        _domain=None,
                        spec_set=Ship(1))
     ship_holder.attributes = {Attribute.launcher_slots_left: 6}
     self.set_ship(ship_holder)
     item = self.ch.type_(type_id=2, attributes={})
     item.slots = {Slot.launcher}
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder1)
     self.track_holder(holder2)
     self.assertEqual(self.st.launcher_slots.used, 2)
     self.assertEqual(self.st.launcher_slots.total, 6)
     ship_holder.attributes[Attribute.launcher_slots_left] = 4
     self.untrack_holder(holder1)
     self.st._clear_volatile_attrs()
     self.assertEqual(self.st.launcher_slots.used, 1)
     self.assertEqual(self.st.launcher_slots.total, 4)
     self.set_ship(None)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_stat_buffers_empty()
示例#21
0
 def test_pass_holder_none_group(self):
     # Check that holders with None group are not affected
     item = self.ch.type_(type_id=1,
                          group=None,
                          attributes={Attribute.max_group_online: 1})
     holder1 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder1)
     holder2 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder2)
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.max_group_online)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.max_group_online)
     self.assertIsNone(restriction_error2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#22
0
 def test_pass_holder_non_ship(self):
     # Holders not belonging to ship shouldn't be affected
     item = self.ch.type_(type_id=1,
                          group=12,
                          attributes={Attribute.max_group_online: 1})
     holder1 = Mock(state=State.online,
                    item=item,
                    _domain=None,
                    spec_set=Module(1))
     self.track_holder(holder1)
     holder2 = Mock(state=State.online,
                    item=item,
                    _domain=None,
                    spec_set=Module(1))
     self.track_holder(holder2)
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.max_group_online)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.max_group_online)
     self.assertIsNone(restriction_error2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#23
0
 def test_fail_excess_all(self):
     # Make sure error is raised for all holders exceeding
     # their group restriction
     item = self.ch.type_(type_id=1,
                          group=6,
                          attributes={Attribute.max_group_online: 1})
     holder1 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder1)
     holder2 = Mock(state=State.online,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder2)
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.max_group_online)
     self.assertIsNotNone(restriction_error1)
     self.assertEqual(restriction_error1.max_group, 1)
     self.assertEqual(restriction_error1.holder_group, 6)
     self.assertEqual(restriction_error1.group_holders, 2)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.max_group_online)
     self.assertIsNotNone(restriction_error2)
     self.assertEqual(restriction_error2.max_group, 1)
     self.assertEqual(restriction_error2.holder_group, 6)
     self.assertEqual(restriction_error2.group_holders, 2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#24
0
 def test_fail_other_holder_class(self):
     # Make sure holders of all classes are affected
     item = self.ch.type_(type_id=1,
                          attributes={Attribute.subsystem_slot: 120})
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.track_holder(holder1)
     self.track_holder(holder2)
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.subsystem_index)
     self.assertIsNotNone(restriction_error1)
     self.assertEqual(restriction_error1.holder_slot_index, 120)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.subsystem_index)
     self.assertIsNotNone(restriction_error2)
     self.assertEqual(restriction_error2.holder_slot_index, 120)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#25
0
文件: test_med.py 项目: Ebag333/eos
 def test_volatility(self):
     ship_item = self.ch.type_(type_id=1)
     ship_holder = Mock(state=State.offline,
                        item=ship_item,
                        _domain=None,
                        spec_set=Ship(1))
     ship_holder.attributes = {Attribute.med_slots: 6}
     self.set_ship(ship_holder)
     item = self.ch.type_(type_id=2, attributes={})
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.fit.modules.med.append(holder1)
     self.fit.modules.med.append(holder2)
     self.assertEqual(self.st.med_slots.used, 2)
     self.assertEqual(self.st.med_slots.total, 6)
     ship_holder.attributes[Attribute.med_slots] = 4
     self.fit.modules.med.remove(holder1)
     self.st._clear_volatile_attrs()
     self.assertEqual(self.st.med_slots.used, 1)
     self.assertEqual(self.st.med_slots.total, 4)
     self.set_ship(None)
     self.assertEqual(len(self.log), 0)
     self.assert_stat_buffers_empty()
示例#26
0
 def test_none_and_data(self):
     # As container for damage dealers is not ordered,
     # this test may be unreliable (even if there's issue,
     # it won't fail each run)
     item = self.ch.type_(type_id=1, attributes={})
     holder1 = Mock(state=State.active, item=item, spec=Module(1))
     holder2 = Mock(state=State.active, item=item, spec=Module(1))
     self.track_holder(holder1)
     self.track_holder(holder2)
     holder1_dps = Mock(em=1.2,
                        thermal=2.3,
                        kinetic=3.4,
                        explosive=4.5,
                        total=5.6)
     holder2_dps = Mock(em=None,
                        thermal=None,
                        kinetic=None,
                        explosive=None,
                        total=None)
     holder1.get_nominal_dps.return_value = holder1_dps
     holder2.get_nominal_dps.return_value = holder2_dps
     stats_dps = self.st.get_nominal_dps()
     self.assertAlmostEqual(stats_dps.em, 1.2)
     self.assertAlmostEqual(stats_dps.thermal, 2.3)
     self.assertAlmostEqual(stats_dps.kinetic, 3.4)
     self.assertAlmostEqual(stats_dps.explosive, 4.5)
     self.assertAlmostEqual(stats_dps.total, 11.4)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_stat_buffers_empty()
示例#27
0
 def test_fail_excess_multiple(self):
     # Check that error works for multiple holders, and raised
     # only for those which lie out of bounds
     item = self.ch.type_(type_id=1)
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.fit.modules.low.append(holder1)
     self.fit.modules.low.append(holder2)
     self.fit.stats.low_slots.used = 2
     self.fit.stats.low_slots.total = 1
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.low_slot)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.low_slot)
     self.assertIsNotNone(restriction_error2)
     self.assertEqual(restriction_error2.slots_max_allowed, 1)
     self.assertEqual(restriction_error2.slots_used, 2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#28
0
 def testDetachedModuleNoneToFreeCharge(self):
     module = Module(1, state=State.active, charge=None)
     charge = Charge(2)
     # Action
     module.charge = charge
     # Checks
     self.assertIs(module.charge, charge)
     self.assertIs(module._other, charge)
     self.assertIs(charge.container, module)
     self.assertIs(charge._other, module)
示例#29
0
文件: test_cpu.py 项目: Ebag333/eos
 def test_use_negative(self):
     item = self.ch.type_(type_id=1, attributes={Attribute.cpu: 0})
     holder1 = Mock(state=State.online, item=item, _domain=Domain.ship, spec_set=Module(1))
     holder1.attributes = {Attribute.cpu: 50}
     self.track_holder(holder1)
     holder2 = Mock(state=State.online, item=item, _domain=Domain.ship, spec_set=Module(1))
     holder2.attributes = {Attribute.cpu: -30}
     self.track_holder(holder2)
     self.assertEqual(self.st.cpu.used, 20)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_stat_buffers_empty()
示例#30
0
 def testDetachedModuleChargeToNone(self):
     module = Module(1, state=State.active, charge=None)
     charge = Charge(2)
     module.charge = charge
     # Action
     module.charge = None
     # Checks
     self.assertIsNone(module.charge)
     self.assertIsNone(module._other)
     self.assertIsNone(charge.container)
     self.assertIsNone(charge._other)
     self.assertIsNone(module._fit)
     self.assertIsNone(charge._fit)
示例#31
0
 def test_pass_equal(self):
     item = self.ch.type_(type_id=1)
     holder1 = Mock(state=State.offline, item=item, _domain=Domain.ship, spec_set=Module(1))
     holder2 = Mock(state=State.offline, item=item, _domain=Domain.ship, spec_set=Module(1))
     self.fit.modules.med.append(holder1)
     self.fit.modules.med.append(holder2)
     self.fit.stats.med_slots.used = 2
     self.fit.stats.med_slots.total = 2
     restriction_error1 = self.get_restriction_error(holder1, Restriction.medium_slot)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(holder2, Restriction.medium_slot)
     self.assertIsNone(restriction_error2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#32
0
 def test_use_multiple(self):
     item = self.ch.type_(type_id=1, attributes={})
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Module(1))
     self.fit.subsystems.add(holder1)
     self.fit.subsystems.add(holder2)
     self.assertEqual(self.st.subsystem_slots.used, 2)
     self.assertEqual(len(self.log), 0)
     self.assert_stat_buffers_empty()
示例#33
0
 def testDetachedFitNoneToNone(self):
     fit = self._makeFit()
     module = Module(1, state=State.active, charge=None)
     fit.ordered.append(module)
     # Action
     module.charge = None
     # Checks
     self.assertEqual(len(fit.lt), 0)
     self.assertEqual(len(fit.rt), 0)
     self.assertIsNone(module.charge)
     self.assertIsNone(module._other)
     self.assertIs(module._fit, fit)
     # Misc
     fit.ordered.remove(module)
     self.assertFitBuffersEmpty(fit)
示例#34
0
 def test_pass_original_attribs(self):
     # Make sure original item attributes are used
     charge_item = self.ch.type_(type_id=1,
                                 attributes={Attribute.charge_size: 2})
     charge_holder = Mock(state=State.offline,
                          item=charge_item,
                          _domain=None,
                          spec_set=Charge(1))
     charge_holder.attributes = {Attribute.charge_size: 1}
     container_item = self.ch.type_(type_id=2,
                                    attributes={Attribute.charge_size: 2})
     container_holder = Mock(state=State.offline,
                             item=container_item,
                             _domain=Domain.ship,
                             spec_set=Module(1))
     container_holder.attributes = {Attribute.charge_size: 3}
     container_holder.charge = charge_holder
     charge_holder.container = container_holder
     self.track_holder(container_holder)
     self.track_holder(charge_holder)
     restriction_error1 = self.get_restriction_error(
         container_holder, Restriction.charge_size)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(
         charge_holder, Restriction.charge_size)
     self.assertIsNone(restriction_error2)
     self.untrack_holder(container_holder)
     self.untrack_holder(charge_holder)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#35
0
 def test_fail_charge_no_attrib(self):
     charge_item = self.ch.type_(type_id=1, attributes={})
     charge_holder = Mock(state=State.offline,
                          item=charge_item,
                          _domain=None,
                          spec_set=Charge(1))
     container_item = self.ch.type_(type_id=2,
                                    attributes={Attribute.charge_size: 3})
     container_holder = Mock(state=State.offline,
                             item=container_item,
                             _domain=Domain.ship,
                             spec_set=Module(1))
     container_holder.charge = charge_holder
     charge_holder.container = container_holder
     self.track_holder(container_holder)
     self.track_holder(charge_holder)
     restriction_error1 = self.get_restriction_error(
         container_holder, Restriction.charge_size)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(
         charge_holder, Restriction.charge_size)
     self.assertIsNotNone(restriction_error2)
     self.assertEqual(restriction_error2.allowed_size, 3)
     self.assertEqual(restriction_error2.holder_size, None)
     self.untrack_holder(container_holder)
     self.untrack_holder(charge_holder)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#36
0
 def test_fail_group3(self):
     charge_item = self.ch.type_(type_id=1, group=1008)
     charge_holder = Mock(state=State.offline,
                          item=charge_item,
                          _domain=None,
                          spec_set=Charge(1))
     container_item = self.ch.type_(
         type_id=2, attributes={Attribute.charge_group_3: 3})
     container_holder = Mock(state=State.offline,
                             item=container_item,
                             _domain=Domain.ship,
                             spec_set=Module(1))
     container_holder.charge = charge_holder
     charge_holder.container = container_holder
     self.track_holder(container_holder)
     self.track_holder(charge_holder)
     restriction_error1 = self.get_restriction_error(
         container_holder, Restriction.charge_group)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(
         charge_holder, Restriction.charge_group)
     self.assertIsNotNone(restriction_error2)
     self.assertEqual(len(restriction_error2.allowed_groups), 1)
     self.assertIn(3, restriction_error2.allowed_groups)
     self.assertEqual(restriction_error2.holder_group, 1008)
     self.untrack_holder(container_holder)
     self.untrack_holder(charge_holder)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
示例#37
0
 def testDetachedModuleChargeToFreeCharge(self):
     module = Module(1, state=State.active, charge=None)
     charge1 = Charge(2)
     charge2 = Charge(3)
     module.charge = charge1
     # Action
     module.charge = charge2
     # Checks
     self.assertIs(module.charge, charge2)
     self.assertIs(module._other, charge2)
     self.assertIsNone(charge1.container)
     self.assertIsNone(charge1._other)
     self.assertIs(charge2.container, module)
     self.assertIs(charge2._other, module)
     self.assertIsNone(module._fit)
     self.assertIsNone(charge1._fit)
     self.assertIsNone(charge2._fit)
示例#38
0
 def testAttachedFitChargeToBoundCharge(self):
     eos = Mock(spec_set=())
     fit = self._makeFit(eos=eos)
     fitOther = self._makeFit(eos=eos)
     module = Module(1, state=State.active, charge=None)
     charge1 = Charge(2)
     charge2 = Charge(3)
     fit.ordered.append(module)
     fitOther.ordered.append(charge2)
     module.charge = charge1
     self.expectModuleChargeLink = True
     # Action
     self.assertRaises(ValueError, module.__setattr__, 'charge', charge2)
     # Checks
     self.assertEqual(len(fit.lt), 2)
     self.assertIn(module, fit.lt)
     self.assertEqual(fit.lt[module], {State.offline, State.online, State.active})
     self.assertIn(charge1, fit.lt)
     self.assertEqual(fit.lt[charge1], {State.offline})
     self.assertEqual(len(fit.rt), 2)
     self.assertIn(module, fit.rt)
     self.assertEqual(fit.rt[module], {State.offline, State.online, State.active})
     self.assertIn(charge1, fit.rt)
     self.assertEqual(fit.rt[charge1], {State.offline})
     self.assertEqual(len(fitOther.lt), 1)
     self.assertIn(charge2, fitOther.lt)
     self.assertEqual(fitOther.lt[charge2], {State.offline})
     self.assertEqual(len(fitOther.rt), 1)
     self.assertIn(charge2, fitOther.rt)
     self.assertEqual(fitOther.rt[charge2], {State.offline})
     self.assertIs(module.charge, charge1)
     self.assertIs(module._other, charge1)
     self.assertIs(charge1.container, module)
     self.assertIs(charge1._other, module)
     self.assertIsNone(charge2.container)
     self.assertIsNone(charge2._other)
     self.assertIs(module._fit, fit)
     self.assertIs(charge1._fit, fit)
     self.assertIs(charge2._fit, fitOther)
     # Misc
     self.expectModuleChargeLink = None
     fit.ordered.remove(module)
     fitOther.ordered.remove(charge2)
     self.assertFitBuffersEmpty(fit)
     self.assertFitBuffersEmpty(fitOther)
示例#39
0
 def testDetachedFitAddRemovedModule(self):
     fit = self._makeFit()
     module = Module(1, state=State.active, charge=None)
     charge = Charge(2)
     module.charge = charge
     fit.ordered.append(module)
     # Action
     fit.ordered.remove(module)
     # Checks
     self.assertEqual(len(fit.lt), 0)
     self.assertEqual(len(fit.rt), 0)
     self.assertEqual(len(fit.ordered), 0)
     self.assertIs(module.charge, charge)
     self.assertIs(module._other, charge)
     self.assertIs(charge.container, module)
     self.assertIs(charge._other, module)
     self.assertIsNone(module._fit)
     self.assertIsNone(charge._fit)
     # Misc
     self.assertFitBuffersEmpty(fit)
示例#40
0
 def testAttachedFitNoneToNone(self):
     eos = Mock(spec_set=())
     fit = self._makeFit(eos=eos)
     module = Module(1, state=State.active, charge=None)
     fit.ordered.append(module)
     # Action
     module.charge = None
     # Checks
     self.assertEqual(len(fit.lt), 1)
     self.assertIn(module, fit.lt)
     self.assertEqual(fit.lt[module], {State.offline, State.online, State.active})
     self.assertEqual(len(fit.rt), 1)
     self.assertIn(module, fit.rt)
     self.assertEqual(fit.rt[module], {State.offline, State.online, State.active})
     self.assertIsNone(module.charge)
     self.assertIsNone(module._other)
     self.assertIs(module._fit, fit)
     # Misc
     fit.ordered.remove(module)
     self.assertFitBuffersEmpty(fit)
示例#41
0
 def testAttachedFitAddRemovedModule(self):
     eos = Mock(spec_set=())
     fit = self._makeFit(eos=eos)
     module = Module(1, state=State.active, charge=None)
     charge = Charge(2)
     module.charge = charge
     fit.ordered.append(module)
     self.expectModuleChargeLink = True
     # Action
     fit.ordered.remove(module)
     # Checks
     self.assertEqual(len(fit.lt), 0)
     self.assertEqual(len(fit.rt), 0)
     self.assertEqual(len(fit.ordered), 0)
     self.assertIs(module.charge, charge)
     self.assertIs(module._other, charge)
     self.assertIs(charge.container, module)
     self.assertIs(charge._other, module)
     self.assertIsNone(module._fit)
     self.assertIsNone(charge._fit)
     # Misc
     self.assertFitBuffersEmpty(fit)
示例#42
0
 def testDetachedFitChargeToFreeCharge(self):
     fit = self._makeFit()
     module = Module(1, state=State.active, charge=None)
     charge1 = Charge(2)
     charge2 = Charge(3)
     fit.ordered.append(module)
     module.charge = charge1
     # Action
     module.charge = charge2
     # Checks
     self.assertEqual(len(fit.lt), 0)
     self.assertEqual(len(fit.rt), 0)
     self.assertIs(module.charge, charge2)
     self.assertIs(module._other, charge2)
     self.assertIsNone(charge1.container)
     self.assertIsNone(charge1._other)
     self.assertIs(charge2.container, module)
     self.assertIs(charge2._other, module)
     self.assertIs(module._fit, fit)
     self.assertIsNone(charge1._fit)
     self.assertIs(charge2._fit, fit)
     # Misc
     fit.ordered.remove(module)
     self.assertFitBuffersEmpty(fit)