def test_detached_holder_to_holder(self): fit = self.make_fit() holder1 = Mock(_fit=None, state=State.offline, spec_set=Ship(1)) holder2 = Mock(_fit=None, state=State.active, spec_set=Ship(1)) fit.ship = holder1 st_cleans_before = len(fit.stats._clear_volatile_attrs.mock_calls) holder1_cleans_before = len(holder1._clear_volatile_attrs.mock_calls) holder2_cleans_before = len(holder2._clear_volatile_attrs.mock_calls) # Action fit.ship = holder2 # Checks self.assertEqual(len(fit.lt), 0) self.assertEqual(len(fit.rt), 0) self.assertEqual(len(fit.st), 0) self.assertIs(fit.ship, holder2) self.assertIsNone(holder1._fit) self.assertIs(holder2._fit, fit) st_cleans_after = len(fit.stats._clear_volatile_attrs.mock_calls) holder1_cleans_after = len(holder1._clear_volatile_attrs.mock_calls) holder2_cleans_after = len(holder2._clear_volatile_attrs.mock_calls) self.assertEqual(st_cleans_after - st_cleans_before, 0) self.assertEqual(holder1_cleans_after - holder1_cleans_before, 0) self.assertEqual(holder2_cleans_after - holder2_cleans_before, 0) # Misc fit.ship = None self.assert_fit_buffers_empty(fit)
def test_attached_holder_to_holder_value_failure(self): source = Mock(spec_set=Source) fit = self.make_fit(source=source) fit_other = self.make_fit(source=source) holder1 = Mock(_fit=None, state=State.offline, spec_set=Ship(1)) holder2 = Mock(_fit=None, state=State.online, spec_set=Ship(1)) fit.ship = holder1 fit_other.ship = holder2 st_cleans_before = len(fit.stats._clear_volatile_attrs.mock_calls) holder1_cleans_before = len(holder1._clear_volatile_attrs.mock_calls) holder2_cleans_before = len(holder2._clear_volatile_attrs.mock_calls) st_other_cleans_before = len( fit_other.stats._clear_volatile_attrs.mock_calls) # Action self.assertRaises(ValueError, fit.__setattr__, 'ship', holder2) # Checks self.assertEqual(len(fit.lt), 1) self.assertIn(holder1, fit.lt) self.assertEqual(fit.lt[holder1], {State.offline}) self.assertEqual(len(fit.rt), 1) self.assertIn(holder1, fit.rt) self.assertEqual(fit.rt[holder1], {State.offline}) self.assertEqual(len(fit.st), 1) self.assertIn(holder1, fit.st) self.assertEqual(fit.st[holder1], {State.offline}) self.assertEqual(len(fit_other.lt), 1) self.assertIn(holder2, fit_other.lt) self.assertEqual(fit_other.lt[holder2], {State.offline, State.online}) self.assertEqual(len(fit_other.rt), 1) self.assertIn(holder2, fit_other.rt) self.assertEqual(fit_other.rt[holder2], {State.offline, State.online}) self.assertEqual(len(fit_other.st), 1) self.assertIn(holder2, fit_other.st) self.assertEqual(fit_other.st[holder2], {State.offline, State.online}) self.assertIs(fit.ship, holder1) self.assertIs(fit_other.ship, holder2) self.assertIs(holder1._fit, fit) self.assertIs(holder2._fit, fit_other) st_cleans_after = len(fit.stats._clear_volatile_attrs.mock_calls) holder1_cleans_after = len(holder1._clear_volatile_attrs.mock_calls) holder2_cleans_after = len(holder2._clear_volatile_attrs.mock_calls) st_other_cleans_after = len( fit_other.stats._clear_volatile_attrs.mock_calls) self.assertEqual(st_cleans_after - st_cleans_before, 1) self.assertEqual(holder1_cleans_after - holder1_cleans_before, 1) self.assertEqual(holder2_cleans_after - holder2_cleans_before, 0) self.assertEqual(st_other_cleans_after - st_other_cleans_before, 0) # Misc fit.ship = None fit_other.ship = None self.assert_fit_buffers_empty(fit) self.assert_fit_buffers_empty(fit_other)
def test_fail_original_volume(self): # Make sure original volume value is taken item = self.ch.type_(type_id=1, attributes={Attribute.volume: 501}) holder = Mock(state=State.offline, item=item, _domain=Domain.ship, spec_set=ModuleHigh(1)) # Set volume below 500 to check that even when # modified attributes are available, raw attributes # are taken holder.attributes = {Attribute.volume: 100} 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)) self.set_ship(ship_holder) restriction_error = self.get_restriction_error( holder, Restriction.capital_item) self.assertIsNotNone(restriction_error) self.assertEqual(restriction_error.max_allowed_volume, 500) self.assertEqual(restriction_error.holder_volume, 501) self.untrack_holder(holder) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_restriction_buffers_empty()
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()
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()
def test_fail_type3(self): # Check that third type-restriction attribute affects # holder ship_item = self.ch.type_(type_id=772, group=31) ship_holder = Mock(state=State.offline, item=ship_item, _domain=None, spec_set=Ship(1)) self.set_ship(ship_holder) item = self.ch.type_(type_id=1, attributes={Attribute.can_fit_ship_type_3: 10}) holder = Mock(state=State.offline, item=item, _domain=Domain.ship, spec_set=ModuleHigh(1)) self.track_holder(holder) restriction_error = self.get_restriction_error( holder, Restriction.ship_type_group) self.assertIsNotNone(restriction_error) self.assertCountEqual(restriction_error.allowed_types, (10, )) self.assertCountEqual(restriction_error.allowed_groups, ()) self.assertEqual(restriction_error.ship_type, 772) self.assertEqual(restriction_error.ship_group, 31) self.untrack_holder(holder) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_restriction_buffers_empty()
def test_fail_attr_original(self): # Make sure original value is taken ship_item = self.ch.type_(type_id=772, group=31) ship_holder = Mock(state=State.offline, item=ship_item, _domain=None, spec_set=Ship(1)) self.set_ship(ship_holder) item = self.ch.type_(type_id=1, attributes={Attribute.can_fit_ship_type_1: 10}) holder = Mock(state=State.offline, item=item, _domain=Domain.ship, spec_set=ModuleHigh(1)) holder.attributes = {Attribute.can_fit_ship_type_1: 772} self.track_holder(holder) restriction_error = self.get_restriction_error( holder, Restriction.ship_type_group) self.assertIsNotNone(restriction_error) self.assertCountEqual(restriction_error.allowed_types, (10, )) self.assertCountEqual(restriction_error.allowed_groups, ()) self.assertEqual(restriction_error.ship_type, 772) self.assertEqual(restriction_error.ship_group, 31) self.untrack_holder(holder) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_restriction_buffers_empty()
def test_fail_group_multiple_different(self): ship_item = self.ch.type_(type_id=772, group=31) ship_holder = Mock(state=State.offline, item=ship_item, _domain=None, spec_set=Ship(1)) self.set_ship(ship_holder) item = self.ch.type_(type_id=1, attributes={ Attribute.can_fit_ship_group_1: 38, Attribute.can_fit_ship_group_2: 83 }) holder = Mock(state=State.offline, item=item, _domain=Domain.ship, spec_set=ModuleHigh(1)) self.track_holder(holder) restriction_error = self.get_restriction_error( holder, Restriction.ship_type_group) self.assertIsNotNone(restriction_error) self.assertCountEqual(restriction_error.allowed_types, ()) self.assertCountEqual(restriction_error.allowed_groups, (38, 83)) self.assertEqual(restriction_error.ship_type, 772) self.assertEqual(restriction_error.ship_group, 31) self.untrack_holder(holder) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_restriction_buffers_empty()
def test_fail_mismatch_combined(self): # Check that error is returned on attempt # to add drone from group mismatching to # both restriction attributes item = self.ch.type_(type_id=1, group=803) holder = Mock(state=State.offline, item=item, _domain=Domain.space, spec_set=Drone(1)) self.track_holder(holder) ship_item = self.ch.type_(type_id=2, attributes={ Attribute.allowed_drone_group_1: 48, Attribute.allowed_drone_group_2: 106 }) 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.drone_group) self.assertIsNotNone(restriction_error) self.assertCountEqual(restriction_error.allowed_groups, (48, 106)) self.assertEqual(restriction_error.holder_group, 803) self.untrack_holder(holder) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_restriction_buffers_empty()
def test_pass_match_combination(self): # Check that no error raised when drone of group # matching to any of two restriction attributes # is added item = self.ch.type_(type_id=1, group=53) holder = Mock(state=State.offline, item=item, _domain=Domain.space, spec_set=Drone(1)) self.track_holder(holder) ship_item = self.ch.type_(type_id=2, attributes={ Attribute.allowed_drone_group_1: 907, Attribute.allowed_drone_group_2: 53 }) 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.drone_group) self.assertIsNone(restriction_error) self.untrack_holder(holder) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_restriction_buffers_empty()
def test_fail_drone_none(self): # Check that drone from None group is subject # to restriction item = self.ch.type_(type_id=1, group=None) holder = Mock(state=State.offline, item=item, _domain=Domain.space, spec_set=Drone(1)) self.track_holder(holder) ship_item = self.ch.type_( type_id=2, attributes={Attribute.allowed_drone_group_1: 1896}) 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.drone_group) self.assertIsNotNone(restriction_error) self.assertCountEqual(restriction_error.allowed_groups, (1896, )) self.assertEqual(restriction_error.holder_group, None) self.untrack_holder(holder) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_restriction_buffers_empty()
def test_fail_mismatch_original(self): # Check that error is returned on attempt # to add drone from group mismatching to # original restriction attribute, but matching # to modified restriction attribute. Effectively # we check that original attribute value is taken item = self.ch.type_(type_id=1, group=37) holder = Mock(state=State.offline, item=item, _domain=Domain.space, spec_set=Drone(1)) self.track_holder(holder) ship_item = self.ch.type_( type_id=2, attributes={Attribute.allowed_drone_group_1: 59}) ship_holder = Mock(state=State.offline, item=ship_item, _domain=None, spec_set=Ship(1)) ship_holder.attributes = {Attribute.allowed_drone_group_1: 37} self.set_ship(ship_holder) restriction_error = self.get_restriction_error(holder, Restriction.drone_group) self.assertIsNotNone(restriction_error) self.assertCountEqual(restriction_error.allowed_groups, (59, )) self.assertEqual(restriction_error.holder_group, 37) self.untrack_holder(holder) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_restriction_buffers_empty()
def test_volatility(self): ship_item = self.ch.type_(type_id=1, attributes={Attribute.drone_bandwidth: 10}) ship_holder = Mock(state=State.offline, item=ship_item, _domain=None, spec_set=Ship(1)) ship_holder.attributes = {Attribute.drone_bandwidth: 50} self.set_ship(ship_holder) item = self.ch.type_(type_id=2, attributes={Attribute.drone_bandwidth_used: 0}) holder1 = Mock(state=State.online, item=item, _domain=Domain.space, spec_set=Drone(1)) holder1.attributes = {Attribute.drone_bandwidth_used: 50} self.track_holder(holder1) holder2 = Mock(state=State.online, item=item, _domain=Domain.space, spec_set=Drone(1)) holder2.attributes = {Attribute.drone_bandwidth_used: 30} self.track_holder(holder2) self.assertEqual(self.st.drone_bandwidth.used, 80) self.assertEqual(self.st.drone_bandwidth.output, 50) holder1.attributes[Attribute.drone_bandwidth_used] = 10 ship_holder.attributes[Attribute.drone_bandwidth] = 60 self.st._clear_volatile_attrs() self.assertEqual(self.st.drone_bandwidth.used, 40) self.assertEqual(self.st.drone_bandwidth.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()
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()
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()
def test_detached_holder_to_holder_type_failure(self): fit = self.make_fit() holder1 = Mock(_fit=None, state=State.online, spec_set=Ship(1)) holder2 = Mock(_fit=None, state=State.overload, spec_set=OtherCachingHolder(1)) fit.ship = holder1 st_cleans_before = len(fit.stats._clear_volatile_attrs.mock_calls) holder1_cleans_before = len(holder1._clear_volatile_attrs.mock_calls) holder2_cleans_before = len(holder2._clear_volatile_attrs.mock_calls) # Action self.assertRaises(TypeError, fit.__setattr__, 'ship', holder2) # Checks self.assertEqual(len(fit.lt), 0) self.assertEqual(len(fit.rt), 0) self.assertEqual(len(fit.st), 0) self.assertIs(fit.ship, holder1) self.assertIs(holder1._fit, fit) self.assertIsNone(holder2._fit) st_cleans_after = len(fit.stats._clear_volatile_attrs.mock_calls) holder1_cleans_after = len(holder1._clear_volatile_attrs.mock_calls) holder2_cleans_after = len(holder2._clear_volatile_attrs.mock_calls) self.assertEqual(st_cleans_after - st_cleans_before, 0) self.assertEqual(holder1_cleans_after - holder1_cleans_before, 0) self.assertEqual(holder2_cleans_after - holder2_cleans_before, 0) # Misc fit.ship = None self.assert_fit_buffers_empty(fit)
def test_attached_none_to_holder(self): source = Mock(spec_set=Source) fit = self.make_fit(source=source) holder = Mock(_fit=None, state=State.online, spec_set=Ship(1)) st_cleans_before = len(fit.stats._clear_volatile_attrs.mock_calls) holder_cleans_before = len(holder._clear_volatile_attrs.mock_calls) # Action fit.ship = holder # Checks self.assertEqual(len(fit.lt), 1) self.assertIn(holder, fit.lt) self.assertEqual(fit.lt[holder], {State.offline, State.online}) self.assertEqual(len(fit.rt), 1) self.assertIn(holder, fit.rt) self.assertEqual(fit.rt[holder], {State.offline, State.online}) self.assertEqual(len(fit.st), 1) self.assertIn(holder, fit.st) self.assertEqual(fit.st[holder], {State.offline, State.online}) self.assertIs(fit.ship, holder) self.assertIs(holder._fit, fit) st_cleans_after = len(fit.stats._clear_volatile_attrs.mock_calls) holder_cleans_after = len(holder._clear_volatile_attrs.mock_calls) self.assertEqual(st_cleans_after - st_cleans_before, 1) self.assertEqual(holder_cleans_after - holder_cleans_before, 1) # Misc fit.ship = None self.assert_fit_buffers_empty(fit)
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=ModuleHigh(1)) holder2 = Mock(state=State.offline, item=item, _domain=Domain.ship, spec_set=ModuleHigh(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()
def test_detached_none_to_holder_value_failure(self): fit = self.make_fit() fit_other = self.make_fit() holder = Mock(_fit=None, state=State.active, spec_set=Ship(1)) fit_other.ship = holder st_cleans_before = len(fit.stats._clear_volatile_attrs.mock_calls) holder_cleans_before = len(holder._clear_volatile_attrs.mock_calls) st_other_cleans_before = len( fit_other.stats._clear_volatile_attrs.mock_calls) # Action self.assertRaises(ValueError, fit.__setattr__, 'ship', holder) # Checks self.assertEqual(len(fit.lt), 0) self.assertEqual(len(fit.rt), 0) self.assertEqual(len(fit.st), 0) self.assertEqual(len(fit_other.lt), 0) self.assertEqual(len(fit_other.rt), 0) self.assertEqual(len(fit_other.st), 0) self.assertIsNone(fit.ship) self.assertIs(fit_other.ship, holder) self.assertIs(holder._fit, fit_other) st_cleans_after = len(fit.stats._clear_volatile_attrs.mock_calls) holder_cleans_after = len(holder._clear_volatile_attrs.mock_calls) st_other_cleans_after = len( fit_other.stats._clear_volatile_attrs.mock_calls) self.assertEqual(st_cleans_after - st_cleans_before, 0) self.assertEqual(holder_cleans_after - holder_cleans_before, 0) self.assertEqual(st_other_cleans_after - st_other_cleans_before, 0) # Misc fit_other.ship = None self.assert_fit_buffers_empty(fit) self.assert_fit_buffers_empty(fit_other)
def test_relay(self): # Check that stat tracker relays ehp stats properly 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.get_ehp.return_value = Mock(hull=20, armor=30, shield=40, total=60) self.set_ship(ship_holder) damage_profile = Mock() ehp_calls_before = len(ship_holder.get_ehp.mock_calls) ehp_stats = self.st.get_ehp(damage_profile) ehp_calls_after = len(ship_holder.get_ehp.mock_calls) self.assertEqual(ehp_calls_after - ehp_calls_before, 1) self.assertEqual(ship_holder.get_ehp.mock_calls[-1], call.get_ehp(damage_profile)) self.assertEqual(ehp_stats.hull, 20) self.assertEqual(ehp_stats.armor, 30) self.assertEqual(ehp_stats.shield, 40) self.assertEqual(ehp_stats.total, 60) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_stat_buffers_empty()
def test_fail_combined(self): # Check that failure is appropriately generated when # holder specifies both type and group restrictions ship_item = self.ch.type_(type_id=772, group=31) ship_holder = Mock(state=State.offline, item=ship_item, _domain=None, spec_set=Ship(1)) self.set_ship(ship_holder) item = self.ch.type_(type_id=1, attributes={ Attribute.can_fit_ship_type_1: 1089, Attribute.can_fit_ship_group_1: 23 }) holder = Mock(state=State.offline, item=item, _domain=Domain.ship, spec_set=ModuleHigh(1)) self.track_holder(holder) restriction_error = self.get_restriction_error( holder, Restriction.ship_type_group) self.assertIsNotNone(restriction_error) self.assertCountEqual(restriction_error.allowed_types, (1089, )) self.assertCountEqual(restriction_error.allowed_groups, (23, )) self.assertEqual(restriction_error.ship_type, 772) self.assertEqual(restriction_error.ship_group, 31) self.untrack_holder(holder) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_restriction_buffers_empty()
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)) self.set_ship(ship_holder) ship_holder.worst_case_ehp = Mock(hull=50, armor=60, shield=70, total=80) self.assertEqual(self.st.worst_case_ehp.hull, 50) self.assertEqual(self.st.worst_case_ehp.armor, 60) self.assertEqual(self.st.worst_case_ehp.shield, 70) self.assertEqual(self.st.worst_case_ehp.total, 80) ship_holder.worst_case_ehp = Mock(hull=150, armor=160, shield=170, total=180) self.st._clear_volatile_attrs() self.assertEqual(self.st.worst_case_ehp.hull, 150) self.assertEqual(self.st.worst_case_ehp.armor, 160) self.assertEqual(self.st.worst_case_ehp.shield, 170) self.assertEqual(self.st.worst_case_ehp.total, 180) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_stat_buffers_empty()
def test_pass_combined_group_atch(self): # Check that it's enough to match group condition # to be fittable, even if both conditions are specified ship_item = self.ch.type_(type_id=554, group=23) ship_holder = Mock(state=State.offline, item=ship_item, _domain=None, spec_set=Ship(1)) self.set_ship(ship_holder) item = self.ch.type_(type_id=1, attributes={ Attribute.can_fit_ship_type_1: 1089, Attribute.can_fit_ship_group_1: 23 }) holder = Mock(state=State.offline, item=item, _domain=Domain.ship, spec_set=ModuleHigh(1)) self.track_holder(holder) restriction_error = self.get_restriction_error( holder, Restriction.ship_type_group) self.assertIsNone(restriction_error) self.untrack_holder(holder) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_restriction_buffers_empty()
def test_cache(self): ship_item = self.ch.type_(type_id=1, attributes={Attribute.drone_capacity: 10}) ship_holder = Mock(state=State.offline, item=ship_item, _domain=None, spec_set=Ship(1)) ship_holder.attributes = {Attribute.drone_capacity: 50} self.set_ship(ship_holder) item = self.ch.type_(type_id=2, attributes={Attribute.volume: 0}) holder1 = Mock(state=State.offline, item=item, _domain=Domain.space, spec_set=Drone(1)) holder1.attributes = {Attribute.volume: 50} self.fit.drones.add(holder1) self.track_holder(holder1) holder2 = Mock(state=State.offline, item=item, _domain=Domain.space, spec_set=Drone(1)) holder2.attributes = {Attribute.volume: 30} self.fit.drones.add(holder2) self.track_holder(holder2) self.assertEqual(self.st.dronebay.used, 80) self.assertEqual(self.st.dronebay.output, 50) holder1.attributes[Attribute.volume] = 10 ship_holder.attributes[Attribute.drone_capacity] = 60 self.assertEqual(self.st.dronebay.used, 80) self.assertEqual(self.st.dronebay.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()
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()
def test_fail_subcapital_ship(self): # Check that error is raised on attempt # to add capital item to fit with subcapital # ship item = self.ch.type_(type_id=1, attributes={Attribute.volume: 501}) holder = Mock(state=State.offline, item=item, _domain=Domain.ship, spec_set=ModuleHigh(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)) self.set_ship(ship_holder) restriction_error = self.get_restriction_error( holder, Restriction.capital_item) self.assertIsNotNone(restriction_error) self.assertEqual(restriction_error.max_allowed_volume, 500) self.assertEqual(restriction_error.holder_volume, 501) self.untrack_holder(holder) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_restriction_buffers_empty()
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()
def test_output_no_attr(self): # None for slot amount when no attribute on ship 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 = {} self.set_ship(ship_holder) self.assertIsNone(self.st.subsystem_slots.total) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_stat_buffers_empty()
def test_output(self): # Check that modified attribute of ship is used ship_item = self.ch.type_(type_id=1, attributes={Attribute.subsystem_slot: 2}) 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) self.assertEqual(self.st.subsystem_slots.total, 6) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_stat_buffers_empty()
def test_output(self): # Check that modified attribute of ship is used 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) self.assertEqual(self.st.calibration.output, 50) self.set_ship(None) self.assertEqual(len(self.log), 0) self.assert_stat_buffers_empty()