Esempio n. 1
0
 def test_attached_holder_to_holder_type_failure(self):
     source = Mock(spec_set=Source)
     fit = 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=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), 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.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)
Esempio n. 2
0
 def test_detached_holder_onto_none_type_failure(self):
     fit = self.make_fit()
     holder1 = Mock(_fit=None,
                    state=State.online,
                    spec_set=CachingHolder(1))
     holder2 = Mock(_fit=None,
                    state=State.online,
                    spec_set=OtherCachingHolder(1))
     fit.container.insert(1, 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.container.place, 0, holder2)
     # Checks
     self.assertEqual(len(fit.lt), 0)
     self.assertEqual(len(fit.rt), 0)
     self.assertEqual(len(fit.st), 0)
     self.assertIs(len(fit.container), 2)
     self.assertIsNone(fit.container[0])
     self.assertIs(fit.container[1], 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.container.remove(holder1)
     self.assert_object_buffers_empty(fit.container)
Esempio n. 3
0
 def test_attached_holder_inside_type_failure(self):
     source = Mock(spec_set=Source)
     fit = self.make_fit(source=source)
     holder1 = Mock(_fit=None,
                    state=State.active,
                    spec_set=CachingHolder(1))
     holder2 = Mock(_fit=None,
                    state=State.online,
                    spec_set=CachingHolder(1))
     holder3 = Mock(_fit=None,
                    state=State.offline,
                    spec_set=OtherCachingHolder(1))
     fit.container.append(holder1)
     fit.container.append(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)
     holder3_cleans_before = len(holder3._clear_volatile_attrs.mock_calls)
     # Action
     self.assertRaises(TypeError, fit.container.insert, 1, holder3)
     # Checks
     self.assertEqual(len(fit.lt), 2)
     self.assertIn(holder1, fit.lt)
     self.assertEqual(fit.lt[holder1],
                      {State.offline, State.online, State.active})
     self.assertIn(holder2, fit.lt)
     self.assertEqual(fit.lt[holder2], {State.offline, State.online})
     self.assertEqual(len(fit.rt), 2)
     self.assertIn(holder1, fit.rt)
     self.assertEqual(fit.rt[holder1],
                      {State.offline, State.online, State.active})
     self.assertIn(holder2, fit.rt)
     self.assertEqual(fit.rt[holder2], {State.offline, State.online})
     self.assertEqual(len(fit.st), 2)
     self.assertIn(holder1, fit.st)
     self.assertEqual(fit.st[holder1],
                      {State.offline, State.online, State.active})
     self.assertIn(holder2, fit.st)
     self.assertEqual(fit.st[holder2], {State.offline, State.online})
     self.assertIs(len(fit.container), 2)
     self.assertIs(fit.container[0], holder1)
     self.assertIs(fit.container[1], holder2)
     self.assertIs(holder1._fit, fit)
     self.assertIs(holder2._fit, fit)
     self.assertIsNone(holder3._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)
     holder3_cleans_after = len(holder3._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)
     self.assertEqual(holder3_cleans_after - holder3_cleans_before, 0)
     # Misc
     fit.container.remove(holder1)
     fit.container.remove(holder2)
     self.assert_object_buffers_empty(fit.container)
Esempio n. 4
0
 def test_detached_holder_to_empty_type_failure(self):
     fit = self.make_fit()
     holder = Mock(_fit=None, state=State.offline, spec_set=OtherCachingHolder(1))
     st_cleans_before = len(fit.stats._clear_volatile_attrs.mock_calls)
     holder_cleans_before = len(holder._clear_volatile_attrs.mock_calls)
     # Action
     self.assertRaises(TypeError, fit.container.equip, holder)
     # Checks
     self.assertEqual(len(fit.lt), 0)
     self.assertEqual(len(fit.rt), 0)
     self.assertEqual(len(fit.st), 0)
     self.assertIs(len(fit.container), 0)
     self.assertIsNone(holder._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, 0)
     self.assertEqual(holder_cleans_after - holder_cleans_before, 0)
     # Misc
     self.assert_object_buffers_empty(fit.container)
Esempio n. 5
0
 def test_attached_none_to_holder_type_failure(self):
     source = Mock(spec_set=Source)
     fit = self.make_fit(source=source)
     holder = Mock(_fit=None,
                   state=State.offline,
                   spec_set=OtherCachingHolder(1))
     st_cleans_before = len(fit.stats._clear_volatile_attrs.mock_calls)
     holder_cleans_before = len(holder._clear_volatile_attrs.mock_calls)
     # Action
     self.assertRaises(TypeError, fit.__setattr__, 'ship', holder)
     # Checks
     self.assertEqual(len(fit.lt), 0)
     self.assertEqual(len(fit.rt), 0)
     self.assertEqual(len(fit.st), 0)
     self.assertIsNone(fit.ship)
     self.assertIsNone(holder._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, 0)
     self.assertEqual(holder_cleans_after - holder_cleans_before, 0)
     # Misc
     self.assert_fit_buffers_empty(fit)