示例#1
0
 def test_setattr_member_entity(self):
     from grease.entity import EntityComponentAccessor
     from grease import Entity
     world = TestWorld()
     entity = Entity(world)
     data = TestData(foo=5)
     accessor = EntityComponentAccessor({entity: data}, entity)
     self.assertEqual(data.foo, 5)
     accessor.foo = 66
     self.assertEqual(data.foo, 66)
     accessor.bar = '!!'
     self.assertEqual(data.bar, '!!')
示例#2
0
 def test_setattr_member_entity(self):
     from grease.entity import EntityComponentAccessor
     from grease import Entity
     world = TestWorld()
     entity = Entity(world)
     data = TestData(foo=5)
     accessor = EntityComponentAccessor({entity: data}, entity)
     self.assertEqual(data.foo, 5)
     accessor.foo = 66
     self.assertEqual(data.foo, 66)
     accessor.bar = '!!'
     self.assertEqual(data.bar, '!!')
示例#3
0
 def test_setattr_nonmember_entity(self):
     from grease.entity import EntityComponentAccessor
     from grease import Entity
     world = TestWorld()
     entity = Entity(world)
     component = TestComponent()
     accessor = EntityComponentAccessor(component, entity)
     self.assertRaises(AttributeError, getattr, entity, 'baz')
     self.assertTrue(entity not in component)
     accessor.baz = 1000
     self.assertTrue(entity in component)
     self.assertEqual(accessor.baz, 1000)
     self.assertEqual(component[entity].baz, 1000)
示例#4
0
 def test_setattr_nonmember_entity(self):
     from grease.entity import EntityComponentAccessor
     from grease import Entity
     world = TestWorld()
     entity = Entity(world)
     component = TestComponent()
     accessor = EntityComponentAccessor(component, entity)
     self.assertRaises(AttributeError, getattr, entity, 'baz')
     self.assertTrue(entity not in component)
     accessor.baz = 1000
     self.assertTrue(entity in component)
     self.assertEqual(accessor.baz, 1000)
     self.assertEqual(component[entity].baz, 1000)
示例#5
0
    def test_getattr(self):
        from grease.entity import EntityComponentAccessor
        from grease import Entity
        world = TestWorld()
        entity = Entity(world)
        component = {entity: TestData(foo=5)}
        accessor = EntityComponentAccessor(component, entity)
        self.assertEqual(accessor.foo, 5)
        self.assertRaises(AttributeError, getattr, accessor, 'bar')

        entity2 = Entity(world)
        accessor = EntityComponentAccessor(component, entity2)
        self.assertRaises(AttributeError, getattr, accessor, 'foo')
        self.assertRaises(AttributeError, getattr, accessor, 'bar')
示例#6
0
 def test_truthiness(self):
     from grease.entity import EntityComponentAccessor
     from grease import Entity
     world = TestWorld()
     entity = Entity(world)
     component = TestComponent()
     accessor = EntityComponentAccessor(component, entity)
     self.assertFalse(accessor)
     component[entity] = 456
     self.assertTrue(accessor)