Exemplo n.º 1
0
 def test_fail_excess_multiple(self):
     # Check that error works for multiple holders
     item = self.ch.type_(type_id=1)
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Rig(1))
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Rig(1))
     self.fit.rigs.add(holder1)
     self.fit.rigs.add(holder2)
     self.track_holder(holder1)
     self.track_holder(holder2)
     self.fit.stats.rig_slots.used = 2
     self.fit.stats.rig_slots.total = 1
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.rig_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.rig_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()
Exemplo n.º 2
0
 def test_fail_excess_multiple(self):
     # When multiple consumers require less than calibration output
     # alone, but in sum want more than total output, it should
     # be erroneous situation
     item = self.ch.type_(type_id=1, attributes={Attribute.upgrade_cost: 0})
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Rig(1))
     holder1.attributes = {Attribute.upgrade_cost: 25}
     self.track_holder(holder1)
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Rig(1))
     holder2.attributes = {Attribute.upgrade_cost: 20}
     self.track_holder(holder2)
     self.fit.stats.calibration.used = 45
     self.fit.stats.calibration.output = 40
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.calibration)
     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.calibration)
     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()
Exemplo n.º 3
0
 def test_mix_usage_zero(self):
     # If some holder has zero usage and calibration error is
     # still raised, check it's not raised for holder with
     # zero usage
     item = self.ch.type_(type_id=1, attributes={Attribute.upgrade_cost: 0})
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Rig(1))
     holder1.attributes = {Attribute.upgrade_cost: 100}
     self.track_holder(holder1)
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Rig(1))
     holder2.attributes = {Attribute.upgrade_cost: 0}
     self.track_holder(holder2)
     self.fit.stats.calibration.used = 100
     self.fit.stats.calibration.output = 50
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.calibration)
     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.calibration)
     self.assertIsNone(restriction_error2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 4
0
 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.upgrade_cost: 0})
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Rig(1))
     holder1.attributes = {Attribute.upgrade_cost: 25}
     self.track_holder(holder1)
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Rig(1))
     holder2.attributes = {Attribute.upgrade_cost: 20}
     self.track_holder(holder2)
     self.fit.stats.calibration.used = 45
     self.fit.stats.calibration.output = 50
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.calibration)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.calibration)
     self.assertIsNone(restriction_error2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 5
0
 def test_pass_greater(self):
     item = self.ch.type_(type_id=1)
     holder1 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Rig(1))
     holder2 = Mock(state=State.offline,
                    item=item,
                    _domain=Domain.ship,
                    spec_set=Rig(1))
     self.fit.rigs.add(holder1)
     self.fit.rigs.add(holder2)
     self.track_holder(holder1)
     self.track_holder(holder2)
     self.fit.stats.rig_slots.used = 2
     self.fit.stats.rig_slots.total = 5
     restriction_error1 = self.get_restriction_error(
         holder1, Restriction.rig_slot)
     self.assertIsNone(restriction_error1)
     restriction_error2 = self.get_restriction_error(
         holder2, Restriction.rig_slot)
     self.assertIsNone(restriction_error2)
     self.untrack_holder(holder1)
     self.untrack_holder(holder2)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 6
0
 def test_fail_mismatch(self):
     # Error should be raised when mismatching rig size
     # is added to ship
     item = self.ch.type_(type_id=1, attributes={Attribute.rig_size: 10})
     holder = Mock(state=State.offline,
                   item=item,
                   _domain=Domain.ship,
                   spec_set=Rig(1))
     self.track_holder(holder)
     ship_item = self.ch.type_(type_id=2,
                               attributes={Attribute.rig_size: 6})
     ship_holder = Mock(state=State.offline,
                        item=ship_item,
                        _domain=None,
                        spec_set=Ship(1))
     self.set_ship(ship_holder)
     restriction_error = self.get_restriction_error(holder,
                                                    Restriction.rig_size)
     self.assertIsNotNone(restriction_error)
     self.assertEqual(restriction_error.allowed_size, 6)
     self.assertEqual(restriction_error.holder_size, 10)
     self.untrack_holder(holder)
     self.set_ship(None)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 7
0
 def test_fail_original(self):
     # Original value must be taken
     item = self.ch.type_(type_id=1, attributes={Attribute.rig_size: 10})
     holder = Mock(state=State.offline,
                   item=item,
                   _domain=Domain.ship,
                   spec_set=Rig(1))
     holder.attributes = {Attribute.rig_size: 5}
     self.track_holder(holder)
     ship_item = self.ch.type_(type_id=2,
                               attributes={Attribute.rig_size: 6})
     ship_holder = Mock(state=State.offline,
                        item=ship_item,
                        _domain=None,
                        spec_set=Ship(1))
     ship_holder.attributes = {Attribute.rig_size: 5}
     self.set_ship(ship_holder)
     restriction_error = self.get_restriction_error(holder,
                                                    Restriction.rig_size)
     self.assertIsNotNone(restriction_error)
     self.assertEqual(restriction_error.allowed_size, 6)
     self.assertEqual(restriction_error.holder_size, 10)
     self.untrack_holder(holder)
     self.set_ship(None)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 8
0
 def test_pass_exception_rig(self):
     # Check that skillreqs on rigs are not checked
     item = self.ch.type_(type_id=1)
     item.required_skills = {50: 3}
     holder = Mock(state=State.offline,
                   item=item,
                   _domain=Domain.ship,
                   spec_set=Rig(1))
     self.track_holder(holder)
     restriction_error = self.get_restriction_error(
         holder, Restriction.skill_requirement)
     self.assertIsNone(restriction_error)
     self.untrack_holder(holder)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 9
0
 def test_pass_no_ship(self):
     # When no ship is assigned, no restriction
     # should be applied to ships
     item = self.ch.type_(type_id=1, attributes={Attribute.rig_size: 10})
     holder = Mock(state=State.offline,
                   item=item,
                   _domain=Domain.ship,
                   spec_set=Rig(1))
     self.track_holder(holder)
     restriction_error = self.get_restriction_error(holder,
                                                    Restriction.rig_size)
     self.assertIsNone(restriction_error)
     self.untrack_holder(holder)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 10
0
 def test_pass_other_container(self):
     item = self.ch.type_(type_id=1)
     holder = Mock(state=State.offline,
                   item=item,
                   _domain=Domain.ship,
                   spec_set=Rig(1))
     self.fit.subsystems.add(holder)
     self.track_holder(holder)
     self.fit.stats.rig_slots.used = 1
     self.fit.stats.rig_slots.total = 0
     restriction_error = self.get_restriction_error(holder,
                                                    Restriction.rig_slot)
     self.assertIsNone(restriction_error)
     self.untrack_holder(holder)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 11
0
 def test_pass_no_original_attr(self):
     # When added holder's item doesn't have original attribute,
     # holder shouldn't be tracked by register, and thus, no
     # errors should be raised
     item = self.ch.type_(type_id=1)
     holder = Mock(state=State.offline,
                   item=item,
                   _domain=Domain.ship,
                   spec_set=Rig(1))
     holder.attributes = {Attribute.upgrade_cost: 100}
     self.track_holder(holder)
     self.fit.stats.calibration.used = 100
     self.fit.stats.calibration.output = 50
     restriction_error = self.get_restriction_error(holder,
                                                    Restriction.calibration)
     self.assertIsNone(restriction_error)
     self.untrack_holder(holder)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 12
0
 def test_fail_excess_signle_undefined_output(self):
     # When stats module does not specify total slot amount,
     # make sure it's assumed to be 0
     item = self.ch.type_(type_id=1)
     holder = Mock(state=State.offline,
                   item=item,
                   _domain=Domain.ship,
                   spec_set=Rig(1))
     self.fit.rigs.add(holder)
     self.track_holder(holder)
     self.fit.stats.rig_slots.used = 1
     self.fit.stats.rig_slots.total = None
     restriction_error = self.get_restriction_error(holder,
                                                    Restriction.rig_slot)
     self.assertIsNotNone(restriction_error)
     self.assertEqual(restriction_error.slots_max_allowed, 0)
     self.assertEqual(restriction_error.slots_used, 1)
     self.untrack_holder(holder)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 13
0
 def test_fail_excess_signle(self):
     # Check that error is raised when number of used
     # slots exceeds slot amount provided by ship
     item = self.ch.type_(type_id=1)
     holder = Mock(state=State.offline,
                   item=item,
                   _domain=Domain.ship,
                   spec_set=Rig(1))
     self.fit.rigs.add(holder)
     self.track_holder(holder)
     self.fit.stats.rig_slots.used = 1
     self.fit.stats.rig_slots.total = 0
     restriction_error = self.get_restriction_error(holder,
                                                    Restriction.rig_slot)
     self.assertIsNotNone(restriction_error)
     self.assertEqual(restriction_error.slots_max_allowed, 0)
     self.assertEqual(restriction_error.slots_used, 1)
     self.untrack_holder(holder)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 14
0
 def test_fail_excess_single_undefined_output(self):
     # When stats module does not specify output, make sure
     # it's assumed to be 0
     item = self.ch.type_(type_id=1, attributes={Attribute.upgrade_cost: 0})
     holder = Mock(state=State.offline,
                   item=item,
                   _domain=Domain.ship,
                   spec_set=Rig(1))
     holder.attributes = {Attribute.upgrade_cost: 5}
     self.track_holder(holder)
     self.fit.stats.calibration.used = 5
     self.fit.stats.calibration.output = None
     restriction_error = self.get_restriction_error(holder,
                                                    Restriction.calibration)
     self.assertIsNotNone(restriction_error)
     self.assertEqual(restriction_error.output, 0)
     self.assertEqual(restriction_error.total_use, 5)
     self.assertEqual(restriction_error.holder_use, 5)
     self.untrack_holder(holder)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 15
0
 def test_fail_excess_single(self):
     # When ship provides calibration output, but single consumer
     # demands for more, error should be raised
     item = self.ch.type_(type_id=1, attributes={Attribute.upgrade_cost: 0})
     holder = Mock(state=State.offline,
                   item=item,
                   _domain=Domain.ship,
                   spec_set=Rig(1))
     holder.attributes = {Attribute.upgrade_cost: 50}
     self.track_holder(holder)
     self.fit.stats.calibration.used = 50
     self.fit.stats.calibration.output = 40
     restriction_error = self.get_restriction_error(holder,
                                                    Restriction.calibration)
     self.assertIsNotNone(restriction_error)
     self.assertEqual(restriction_error.output, 40)
     self.assertEqual(restriction_error.total_use, 50)
     self.assertEqual(restriction_error.holder_use, 50)
     self.untrack_holder(holder)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 16
0
 def test_fail_excess_modified(self):
     # Make sure modified calibration values are taken
     item = self.ch.type_(type_id=1,
                          attributes={Attribute.upgrade_cost: 40})
     holder = Mock(state=State.offline,
                   item=item,
                   _domain=Domain.ship,
                   spec_set=Rig(1))
     holder.attributes = {Attribute.upgrade_cost: 100}
     self.track_holder(holder)
     self.fit.stats.calibration.used = 100
     self.fit.stats.calibration.output = 50
     restriction_error = self.get_restriction_error(holder,
                                                    Restriction.calibration)
     self.assertIsNotNone(restriction_error)
     self.assertEqual(restriction_error.output, 50)
     self.assertEqual(restriction_error.total_use, 100)
     self.assertEqual(restriction_error.holder_use, 100)
     self.untrack_holder(holder)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()
Exemplo n.º 17
0
 def test_pass_ship_no_attr(self):
     # If ship doesn't have rig size attribute,
     # no restriction is applied onto rigs
     item = self.ch.type_(type_id=1, attributes={Attribute.rig_size: 10})
     holder = Mock(state=State.offline,
                   item=item,
                   _domain=Domain.ship,
                   spec_set=Rig(1))
     self.track_holder(holder)
     ship_item = self.ch.type_(type_id=2)
     ship_holder = Mock(state=State.offline,
                        item=ship_item,
                        _domain=None,
                        spec_set=Ship(1))
     ship_holder.attributes = {}
     self.set_ship(ship_holder)
     restriction_error = self.get_restriction_error(holder,
                                                    Restriction.rig_size)
     self.assertIsNone(restriction_error)
     self.untrack_holder(holder)
     self.set_ship(None)
     self.assertEqual(len(self.log), 0)
     self.assert_restriction_buffers_empty()