Ejemplo n.º 1
0
 def test_key_integrity(self):
     fit = Fit()
     item_type = self.mktype()
     item1 = Skill(item_type.id)
     item2 = Skill(item_type.id)
     fit.skills.add(item1)
     with self.assertRaises(KeyError):
         fit.skills.remove(item2)
     # Verification
     self.assertIs(fit.skills[item_type.id], item1)
     # Cleanup
     self.assert_item_buffers_empty(item1)
     self.assert_item_buffers_empty(item2)
     self.assert_solsys_buffers_empty(fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 2
0
 def test_rah_modified_resonance_update(self):
     # Setup
     skill_attr = self.mkattr(high_is_good=False, stackable=False)
     skill_modifiers = tuple(
         self.mkmod(affectee_filter=ModAffecteeFilter.domain,
                    affectee_domain=ModDomain.ship,
                    affectee_attr_id=attr,
                    operator=ModOperator.post_mul,
                    affector_attr_id=skill_attr.id)
         for attr in (self.armor_em.id, self.armor_therm.id,
                      self.armor_kin.id, self.armor_expl.id))
     skill_effect = self.mkeffect(category_id=EffectCategoryId.passive,
                                  modifiers=skill_modifiers)
     skill_type = self.mktype(attrs={skill_attr.id: 0.5},
                              effects=[skill_effect])
     ship = Ship(self.make_ship_type((0.5, 0.65, 0.75, 0.9)).id)
     self.fit.ship = ship
     rah = ModuleLow(self.make_rah_type((0.85, 0.85, 0.85, 0.85), 6,
                                        1000).id,
                     state=State.online)
     self.fit.modules.low.equip(rah)
     skill = Skill(skill_type.id)
     # Force resonance calculation
     self.assertAlmostEqual(rah.attrs[self.armor_em.id], 0.85)
     self.assertAlmostEqual(rah.attrs[self.armor_therm.id], 0.85)
     self.assertAlmostEqual(rah.attrs[self.armor_kin.id], 0.85)
     self.assertAlmostEqual(rah.attrs[self.armor_expl.id], 0.85)
     self.assertAlmostEqual(ship.attrs[self.armor_em.id], 0.5)
     self.assertAlmostEqual(ship.attrs[self.armor_therm.id], 0.65)
     self.assertAlmostEqual(ship.attrs[self.armor_kin.id], 0.75)
     self.assertAlmostEqual(ship.attrs[self.armor_expl.id], 0.9)
     # Switch state up to enable RAH
     rah.state = State.active
     # Callbacks are installed, sim is doing its job
     self.assertAlmostEqual(rah.attrs[self.armor_em.id], 1)
     self.assertAlmostEqual(rah.attrs[self.armor_therm.id], 0.925)
     self.assertAlmostEqual(rah.attrs[self.armor_kin.id], 0.82)
     self.assertAlmostEqual(rah.attrs[self.armor_expl.id], 0.655)
     self.assertAlmostEqual(ship.attrs[self.armor_em.id], 0.5)
     self.assertAlmostEqual(ship.attrs[self.armor_therm.id], 0.60125)
     self.assertAlmostEqual(ship.attrs[self.armor_kin.id], 0.615)
     self.assertAlmostEqual(ship.attrs[self.armor_expl.id], 0.5895)
     # Action
     self.fit.skills.add(skill)
     rah.state = State.online
     # Verification
     # Despite all changes were masked by override, we should have correct
     # values after overrides are removed
     self.assertAlmostEqual(rah.attrs[self.armor_em.id], 0.425)
     self.assertAlmostEqual(rah.attrs[self.armor_therm.id], 0.425)
     self.assertAlmostEqual(rah.attrs[self.armor_kin.id], 0.425)
     self.assertAlmostEqual(rah.attrs[self.armor_expl.id], 0.425)
     self.assertAlmostEqual(ship.attrs[self.armor_em.id], 0.5)
     self.assertAlmostEqual(ship.attrs[self.armor_therm.id], 0.65)
     self.assertAlmostEqual(ship.attrs[self.armor_kin.id], 0.75)
     self.assertAlmostEqual(ship.attrs[self.armor_expl.id], 0.9)
     # Cleanup
     self.assert_solsys_buffers_empty(self.fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 3
0
 def test_skill_pass(self):
     item = Skill(self.mktype(category_id=TypeCategoryId.skill).id)
     self.fit.skills.add(item)
     # Action
     error = self.get_error(item, Restriction.item_class)
     # Verification
     self.assertIsNone(error)
     # Cleanup
     self.assert_solsys_buffers_empty(self.fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 4
0
 def test_skill_pass_loaded(self):
     item = Skill(self.mktype().id)
     self.fit.skills.add(item)
     # Action
     error = self.get_error(item, Restriction.loaded_item)
     # Verification
     self.assertIsNone(error)
     # Cleanup
     self.assert_solsys_buffers_empty(self.fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 5
0
 def test_skill_fail_not_loaded(self):
     item = Skill(self.allocate_type_id())
     self.fit.skills.add(item)
     # Action
     error = self.get_error(item, Restriction.loaded_item)
     # Verification
     self.assertIsNotNone(error)
     # Cleanup
     self.assert_solsys_buffers_empty(self.fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 6
0
 def test_fail_replacement(self):
     # Check that failed attempt to replace skill doesn't affect restriction
     item = ModuleHigh(
         self.mktype(attrs={
             AttrId.required_skill_1: 50,
             AttrId.required_skill_1_level: 3
         }).id)
     self.fit.modules.high.append(item)
     skill_type = self.mktype(type_id=50)
     self.fit.skills.add(Skill(skill_type.id, level=1))
     with self.assertRaises(ValueError):
         self.fit.skills.add(Skill(skill_type.id, level=5))
     # Action
     error = self.get_error(item, Restriction.skill_requirement)
     # Verification
     self.assertIsNotNone(error)
     self.assertCountEqual(error, ((50, 1, 3), ))
     # Cleanup
     self.assert_solsys_buffers_empty(self.fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 7
0
 def test_skill(self):
     skill = Skill(self.make_item_types())
     self.fit.skills.add(skill)
     self.assertAlmostEqual(skill.attrs[self.tgt_attr_id], 18)
     # Action
     self.fit.solar_system.source = 'src2'
     # Verification
     self.assertAlmostEqual(skill.attrs[self.tgt_attr_id], 14)
     # Cleanup
     self.assert_solsys_buffers_empty(self.fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 8
0
 def test_add_item_value_failure_existing_type_id(self):
     fit = Fit()
     item_type = self.mktype()
     item1 = Skill(item_type.id)
     item2 = Skill(item_type.id)
     fit.skills.add(item1)
     # Action
     with self.assertRaises(ValueError):
         fit.skills.add(item2)
     # Verification
     self.assertEqual(len(fit.skills), 1)
     self.assertIs(fit.skills[item_type.id], item1)
     self.assertIn(item1, fit.skills)
     self.assertIn(item_type.id, fit.skills)
     fit.skills.remove(item1)
     fit.skills.add(item2)
     # Cleanup
     self.assert_item_buffers_empty(item1)
     self.assert_item_buffers_empty(item2)
     self.assert_solsys_buffers_empty(fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 9
0
 def test_bool(self):
     fit = Fit()
     item = Skill(self.mktype().id)
     self.assertIs(bool(fit.skills), False)
     fit.skills.add(item)
     self.assertIs(bool(fit.skills), True)
     fit.skills.remove(item)
     self.assertIs(bool(fit.skills), False)
     # Cleanup
     self.assert_item_buffers_empty(item)
     self.assert_solsys_buffers_empty(fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 10
0
 def test_clear(self):
     fit = Fit()
     item1_type = self.mktype()
     item1 = Skill(item1_type.id)
     item2_type = self.mktype()
     item2 = Skill(item2_type.id)
     fit.skills.add(item1)
     fit.skills.add(item2)
     # Action
     fit.skills.clear()
     # Verification
     self.assertEqual(len(fit.skills), 0)
     self.assertNotIn(item1, fit.skills)
     self.assertNotIn(item1_type.id, fit.skills)
     self.assertNotIn(item2, fit.skills)
     self.assertNotIn(item2_type.id, fit.skills)
     # Cleanup
     self.assert_item_buffers_empty(item1)
     self.assert_item_buffers_empty(item2)
     self.assert_solsys_buffers_empty(fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 11
0
 def test_skill_fail_category_other(self):
     item = Skill(self.mktype(category_id=1008).id)
     self.fit.skills.add(item)
     # Action
     error = self.get_error(item, Restriction.item_class)
     # Verification
     self.assertIsNotNone(error)
     self.assertEqual(error.item_class, Skill)
     self.assertCountEqual(error.allowed_classes, [])
     # Cleanup
     self.assert_solsys_buffers_empty(self.fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 12
0
 def test_add_item(self):
     fit = Fit()
     item_type = self.mktype()
     item = Skill(item_type.id)
     # Action
     fit.skills.add(item)
     # Verification
     self.assertEqual(len(fit.skills), 1)
     self.assertIs(fit.skills[item_type.id], item)
     self.assertIn(item, fit.skills)
     self.assertIn(item_type.id, fit.skills)
     # Cleanup
     self.assert_item_buffers_empty(item)
     self.assert_solsys_buffers_empty(fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 13
0
 def test_pass_satisfied(self):
     # Check that error isn't raised when all skill requirements are met
     item = ModuleHigh(
         self.mktype(attrs={
             AttrId.required_skill_2: 50,
             AttrId.required_skill_2_level: 3
         }).id)
     self.fit.modules.high.append(item)
     self.fit.skills.add(Skill(self.mktype(type_id=50).id, level=3))
     # Action
     error = self.get_error(item, Restriction.skill_requirement)
     # Verification
     self.assertIsNone(error)
     # Cleanup
     self.assert_solsys_buffers_empty(self.fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 14
0
 def test_fail_skill_not_loaded(self):
     item = ModuleHigh(
         self.mktype(attrs={
             AttrId.required_skill_2: 50,
             AttrId.required_skill_2_level: 3
         }).id)
     self.fit.modules.high.append(item)
     self.fit.skills.add(Skill(self.allocate_type_id(), level=3))
     # Action
     error = self.get_error(item, Restriction.skill_requirement)
     # Verification
     self.assertIsNotNone(error)
     self.assertCountEqual(error, ((50, None, 3), ))
     # Cleanup
     self.assert_solsys_buffers_empty(self.fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 15
0
 def test_remove_item_failure(self):
     fit = Fit()
     item_type = self.mktype()
     item = Skill(item_type.id)
     # Action
     with self.assertRaises(KeyError):
         fit.skills.remove(item)
     # Verification
     self.assertEqual(len(fit.skills), 0)
     self.assertNotIn(item, fit.skills)
     self.assertNotIn(item_type.id, fit.skills)
     fit.skills.add(item)
     # Cleanup
     self.assert_item_buffers_empty(item)
     self.assert_solsys_buffers_empty(fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 16
0
 def test_delitem_item_failure(self):
     fit = Fit()
     item_type = self.mktype()
     empty_type_id = self.allocate_type_id()
     item = Skill(item_type.id)
     fit.skills.add(item)
     # Action
     with self.assertRaises(KeyError):
         del fit.skills[empty_type_id]
     # Verification
     self.assertEqual(len(fit.skills), 1)
     self.assertIn(item, fit.skills)
     self.assertIn(item_type.id, fit.skills)
     # Cleanup
     self.assert_item_buffers_empty(item)
     self.assert_solsys_buffers_empty(fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 17
0
 def test_rah_shift(self):
     # Setup
     skill_attr = self.mkattr(high_is_good=False, stackable=False)
     skill_modifier = self.mkmod(
         affectee_filter=ModAffecteeFilter.domain,
         affectee_domain=ModDomain.ship,
         affectee_attr_id=self.shift_attr.id,
         operator=ModOperator.post_mul,
         affector_attr_id=skill_attr.id)
     skill_effect = self.mkeffect(
         category_id=EffectCategoryId.passive,
         modifiers=[skill_modifier])
     skill_type = self.mktype(
         attrs={skill_attr.id: 0.1},
         effects=[skill_effect])
     ship = Ship(self.make_ship_type((0.5, 0.65, 0.75, 0.9)).id)
     self.fit.ship = ship
     rah = ModuleLow(
         self.make_rah_type((0.85, 0.85, 0.85, 0.85), 6, 1000).id,
         state=State.active)
     self.fit.modules.low.equip(rah)
     skill = Skill(skill_type.id)
     # Force resonance calculation
     self.assertAlmostEqual(rah.attrs[self.armor_em.id], 1)
     self.assertAlmostEqual(rah.attrs[self.armor_therm.id], 0.925)
     self.assertAlmostEqual(rah.attrs[self.armor_kin.id], 0.82)
     self.assertAlmostEqual(rah.attrs[self.armor_expl.id], 0.655)
     self.assertAlmostEqual(ship.attrs[self.armor_em.id], 0.5)
     self.assertAlmostEqual(ship.attrs[self.armor_therm.id], 0.60125)
     self.assertAlmostEqual(ship.attrs[self.armor_kin.id], 0.615)
     self.assertAlmostEqual(ship.attrs[self.armor_expl.id], 0.5895)
     # Action
     self.fit.skills.add(skill)
     # Verification
     self.assertAlmostEqual(rah.attrs[self.armor_em.id], 1)
     self.assertAlmostEqual(rah.attrs[self.armor_therm.id], 0.928)
     self.assertAlmostEqual(rah.attrs[self.armor_kin.id], 0.802)
     self.assertAlmostEqual(rah.attrs[self.armor_expl.id], 0.67)
     self.assertAlmostEqual(ship.attrs[self.armor_em.id], 0.5)
     self.assertAlmostEqual(ship.attrs[self.armor_therm.id], 0.6032)
     self.assertAlmostEqual(ship.attrs[self.armor_kin.id], 0.6015)
     self.assertAlmostEqual(ship.attrs[self.armor_expl.id], 0.603)
     # Cleanup
     self.assert_solsys_buffers_empty(self.fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 18
0
 def test_add_item_value_failure_has_fit(self):
     fit = Fit()
     fit_other = Fit()
     item_type = self.mktype()
     item = Skill(item_type.id)
     fit_other.skills.add(item)
     # Action
     with self.assertRaises(ValueError):
         fit.skills.add(item)
     # Verification
     self.assertEqual(len(fit.skills), 0)
     self.assertEqual(len(fit_other.skills), 1)
     self.assertIs(fit_other.skills[item_type.id], item)
     self.assertIn(item, fit_other.skills)
     # Cleanup
     self.assert_item_buffers_empty(item)
     self.assert_solsys_buffers_empty(fit.solar_system)
     self.assert_solsys_buffers_empty(fit_other.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 19
0
 def test_fail_partial(self):
     # Make sure satisfied skill requirements are not shown up in error
     item = ModuleHigh(
         self.mktype(
             attrs={
                 AttrId.required_skill_1: 48,
                 AttrId.required_skill_1_level: 1,
                 AttrId.required_skill_2: 50,
                 AttrId.required_skill_2_level: 5
             }).id)
     self.fit.modules.high.append(item)
     self.fit.skills.add(Skill(self.mktype(type_id=48).id, level=5))
     # Action
     error = self.get_error(item, Restriction.skill_requirement)
     # Verification
     self.assertIsNotNone(error)
     self.assertCountEqual(error, ((50, None, 5), ))
     # Cleanup
     self.assert_solsys_buffers_empty(self.fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 20
0
 def test_fail_multiple(self):
     # Check that multiple errors are shown as iterable
     item = ModuleHigh(
         self.mktype(
             attrs={
                 AttrId.required_skill_1: 48,
                 AttrId.required_skill_1_level: 1,
                 AttrId.required_skill_2: 50,
                 AttrId.required_skill_2_level: 5
             }).id)
     self.fit.modules.high.append(item)
     self.fit.skills.add(Skill(self.mktype(type_id=50).id, level=2))
     # Action
     error = self.get_error(item, Restriction.skill_requirement)
     # Verification
     self.assertIsNotNone(error)
     self.assertCountEqual(error, ((50, 2, 5), (48, None, 1)))
     # Cleanup
     self.assert_solsys_buffers_empty(self.fit.solar_system)
     self.assert_log_entries(0)
Ejemplo n.º 21
0
 def test_unexpected_exception_with_modification(self):
     # Setup
     skill_attr = self.mkattr(high_is_good=False, stackable=False)
     skill_modifier = self.mkmod(affectee_filter=ModAffecteeFilter.domain,
                                 affectee_domain=ModDomain.ship,
                                 affectee_attr_id=self.armor_em.id,
                                 operator=ModOperator.post_mul,
                                 affector_attr_id=skill_attr.id)
     skill_effect = self.mkeffect(category_id=EffectCategoryId.passive,
                                  modifiers=[skill_modifier])
     ship = Ship(self.make_ship_type((0.5, 0.65, 0.75, 0.9)).id)
     self.fit.ship = ship
     rah = ModuleLow(self.make_rah_type((0.85, 0.85, 0.85, 0.85), 6, 0).id,
                     state=State.active)
     self.fit.modules.low.equip(rah)
     skill = Skill(
         self.mktype(attrs={
             skill_attr.id: 0.5
         }, effects=[skill_effect]).id)
     self.fit.skills.add(skill)
     # Verification
     # Skill should change RAH unsimulated EM resonance, and ship EM
     # resonance via RAH effect
     self.assertAlmostEqual(rah.attrs[self.armor_em.id], 0.425)
     self.assertAlmostEqual(rah.attrs[self.armor_therm.id], 0.85)
     self.assertAlmostEqual(rah.attrs[self.armor_kin.id], 0.85)
     self.assertAlmostEqual(rah.attrs[self.armor_expl.id], 0.85)
     self.assertAlmostEqual(ship.attrs[self.armor_em.id], 0.2125)
     self.assertAlmostEqual(ship.attrs[self.armor_therm.id], 0.5525)
     self.assertAlmostEqual(ship.attrs[self.armor_kin.id], 0.6375)
     self.assertAlmostEqual(ship.attrs[self.armor_expl.id], 0.765)
     self.assert_log_entries(1)
     log_record = self.log[0]
     self.assertEqual(log_record.name, 'eos.sim.reactive_armor_hardener')
     self.assertEqual(log_record.levelno, logging.WARNING)
     self.assertEqual(
         log_record.msg,
         'unexpected exception, setting unsimulated resonances')
     # Cleanup
     self.assert_solsys_buffers_empty(self.fit.solar_system)