本文整理汇总了Python中pyamf.ClassAlias.applyAttributes方法的典型用法代码示例。如果您正苦于以下问题:Python ClassAlias.applyAttributes方法的具体用法?Python ClassAlias.applyAttributes怎么用?Python ClassAlias.applyAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyamf.ClassAlias
的用法示例。
在下文中一共展示了ClassAlias.applyAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ApplyAttributesTestCase
# 需要导入模块: from pyamf import ClassAlias [as 别名]
# 或者: from pyamf.ClassAlias import applyAttributes [as 别名]
class ApplyAttributesTestCase(unittest.TestCase):
"""
Tests for L{ClassAlias.applyAttributes}
"""
def setUp(self):
self.alias = ClassAlias(Spam, 'foo', defer=True)
self.obj = Spam()
def test_object(self):
class Foo(object):
pass
attrs = {'foo': 'spam', 'bar': 'eggs'}
self.obj = Foo()
self.alias = ClassAlias(Foo, 'foo', defer=True)
self.assertEqual(self.obj.__dict__, {})
self.alias.applyAttributes(self.obj, attrs)
self.assertEqual(self.obj.__dict__, {'foo': 'spam', 'bar': 'eggs'})
def test_classic(self):
class Foo:
pass
attrs = {'foo': 'spam', 'bar': 'eggs'}
self.obj = Foo()
self.alias = ClassAlias(Foo, 'foo', defer=True)
self.assertEqual(self.obj.__dict__, {})
self.alias.applyAttributes(self.obj, attrs)
self.assertEqual(self.obj.__dict__, {'foo': 'spam', 'bar': 'eggs'})
def test_readonly(self):
self.alias.readonly_attrs = ['foo', 'bar']
attrs = {'foo': 'spam', 'bar': 'eggs'}
self.assertEqual(self.obj.__dict__, {})
self.alias.applyAttributes(self.obj, attrs)
self.assertEqual(self.obj.__dict__, {})
def test_exclude(self):
self.alias.exclude_attrs = ['foo', 'bar']
attrs = {'foo': 'spam', 'bar': 'eggs'}
self.assertEqual(self.obj.__dict__, {})
self.alias.applyAttributes(self.obj, attrs)
self.assertEqual(self.obj.__dict__, {})
def test_not_dynamic(self):
self.alias.static_properties = None
self.alias.dynamic = False
attrs = {'foo': 'spam', 'bar': 'eggs'}
self.assertEqual(self.obj.__dict__, {})
self.alias.applyAttributes(self.obj, attrs)
self.assertEqual(self.obj.__dict__, {})
def test_dict(self):
attrs = {'foo': 'spam', 'bar': 'eggs'}
self.obj = Spam()
self.assertEqual(self.obj.__dict__, {})
self.alias.applyAttributes(self.obj, attrs)
self.assertEqual(self.obj.__dict__, {'foo': 'spam', 'bar': 'eggs'})
示例2: GetDecodableAttributesTestCase
# 需要导入模块: from pyamf import ClassAlias [as 别名]
# 或者: from pyamf.ClassAlias import applyAttributes [as 别名]
class GetDecodableAttributesTestCase(unittest.TestCase):
"""
Tests for L{ClassAlias.getDecodableAttributes}
"""
def setUp(self):
self.alias = ClassAlias(Spam, 'foo', defer=True)
self.obj = Spam()
def test_compile(self):
self.assertFalse(self.alias._compiled)
self.alias.applyAttributes(self.obj, {})
self.assertTrue(self.alias._compiled)
def test_missing_static_property(self):
self.alias.static_attrs = ['foo', 'bar']
self.alias.compile()
attrs = {'foo': None} # missing bar key ..
self.assertRaises(AttributeError, self.alias.getDecodableAttributes,
self.obj, attrs)
def test_no_static(self):
self.alias.compile()
attrs = {'foo': None, 'bar': [1, 2, 3]}
ret = self.alias.getDecodableAttributes(self.obj, attrs)
self.assertEqual(ret, {'foo': None, 'bar': [1, 2, 3]})
def test_readonly(self):
self.alias.compile()
self.alias.readonly_attrs = ['bar']
attrs = {'foo': None, 'bar': [1, 2, 3]}
ret = self.alias.getDecodableAttributes(self.obj, attrs)
self.assertEqual(ret, {'foo': None})
def test_not_dynamic(self):
self.alias.compile()
self.alias.decodable_properties = set(['bar'])
self.alias.dynamic = False
attrs = {'foo': None, 'bar': [1, 2, 3]}
ret = self.alias.getDecodableAttributes(self.obj, attrs)
self.assertEqual(ret, {'bar': [1, 2, 3]})
def test_dynamic(self):
self.alias.compile()
self.alias.static_properties = ['bar']
self.alias.dynamic = True
attrs = {'foo': None, 'bar': [1, 2, 3]}
ret = self.alias.getDecodableAttributes(self.obj, attrs)
self.assertEqual(ret, {'foo': None, 'bar': [1, 2, 3]})
def test_complex(self):
self.alias.compile()
self.alias.static_properties = ['foo', 'bar']
self.alias.exclude_attrs = ['baz', 'gak']
self.alias.readonly_attrs = ['spam', 'eggs']
attrs = {
'foo': 'foo',
'bar': 'bar',
'baz': 'baz',
'gak': 'gak',
'spam': 'spam',
'eggs': 'eggs',
'dyn1': 'dyn1',
'dyn2': 'dyn2'
}
ret = self.alias.getDecodableAttributes(self.obj, attrs)
self.assertEquals(ret, {
'foo': 'foo',
'bar': 'bar',
'dyn2': 'dyn2',
'dyn1': 'dyn1'
})
def test_complex_not_dynamic(self):
self.alias.compile()
self.alias.decodable_properties = ['foo', 'bar']
#.........这里部分代码省略.........