本文整理汇总了Python中vehicle.Vehicle.detach方法的典型用法代码示例。如果您正苦于以下问题:Python Vehicle.detach方法的具体用法?Python Vehicle.detach怎么用?Python Vehicle.detach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vehicle.Vehicle
的用法示例。
在下文中一共展示了Vehicle.detach方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BaseVehicleTests
# 需要导入模块: from vehicle import Vehicle [as 别名]
# 或者: from vehicle.Vehicle import detach [as 别名]
class BaseVehicleTests(unittest.TestCase):
def setUp(self):
self.sprites = tmx.layers.SpriteLayer()
self.items = tmx.layers.SpriteLayer()
self.v = Vehicle((10, 10), self.items, self.sprites)
self.n = NormalVehicle((10, 10), self.items, self.sprites)
self.component = VehicleComponent('motions')
def test_defaults(self):
self.assertIsInstance(self.vehicle.DEFAULTS, dict)
def test_component_could_be_attach(self):
self.assertIsNone(self.v._slots['motions'].get(0, None))
self.v.attach(VehicleComponent('motions'), 0)
self.assertIsNotNone(self.v._slots['motions'].get(0, None))
def test_try_to_attach_on_existing_slot(self):
attached_component = self.v.attach(self.component, 0)
second_component = VehicleComponent('motions')
self.v.attach(second_component, 0)
self.assertIs(self.v._slots[self.component.group][0], attached_component)
self.assertIsNot(self.v._slots['motions'][0], second_component)
def test_try_to_attach_on_existing_slot_using_overwrite(self):
attached_component = self.v.attach(self.component, 0)
second_component = VehicleComponent('motions')
self.v.attach(second_component, 0, overwrite=True)
self.assertIsNot(self.v._slots[self.component.group][0], attached_component)
self.assertIs(self.v._slots['motions'][0], second_component)
def test_detach(self):
self.v.attach(self.component, 0)
self.v.detach(self.component, 0)
self.assertIsNone(self.v._slots['motions'].get(0, None))
def test_recalculation(self):
self.assertEqual(self.v.weight, 0)
self.v.attach(self.component, 0)
self.assertGreater(self.v.weight, 0)
def test_component_detach(self):
self.vehicle.attach(self.component, 'front')
self.assertEqual(len(self.vehicle._slots[self.component.group]), 1)
self.vehicle.detach(self.component, 'front')
self.assertEqual(len(self.vehicle._slots[self.component.group]), 0)