当前位置: 首页>>代码示例>>Python>>正文


Python Vehicle.attach方法代码示例

本文整理汇总了Python中vehicle.Vehicle.attach方法的典型用法代码示例。如果您正苦于以下问题:Python Vehicle.attach方法的具体用法?Python Vehicle.attach怎么用?Python Vehicle.attach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vehicle.Vehicle的用法示例。


在下文中一共展示了Vehicle.attach方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BaseVehicleTests

# 需要导入模块: from vehicle import Vehicle [as 别名]
# 或者: from vehicle.Vehicle import attach [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)
开发者ID:gogoantov,项目名称:asuras,代码行数:48,代码来源:vehicle.py


注:本文中的vehicle.Vehicle.attach方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。