本文整理汇总了Python中pyamf.ClassAlias类的典型用法代码示例。如果您正苦于以下问题:Python ClassAlias类的具体用法?Python ClassAlias怎么用?Python ClassAlias使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClassAlias类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_readonly
def test_readonly(self):
x = ClassAlias(Spam, readonly_attrs=['foo', 'bar'], defer=True)
self.assertEqual(x.readonly_attrs, ['foo', 'bar'])
x.compile()
self.assertEqual(x.readonly_attrs, ['bar', 'foo'])
示例2: test_synonym_attrs
def test_synonym_attrs(self):
x = ClassAlias(Spam, synonym_attrs={'foo': 'bar'}, defer=True)
self.assertEquals(x.synonym_attrs, {'foo': 'bar'})
x.compile()
self.assertEquals(x.synonym_attrs, {'foo': 'bar'})
示例3: test_static
def test_static(self):
x = ClassAlias(Spam, static_attrs=['foo', 'bar'], defer=True)
self.assertEqual(x.static_attrs, ['foo', 'bar'])
x.compile()
self.assertEqual(x.static_attrs, ['foo', 'bar'])
示例4: test_exclude
def test_exclude(self):
x = ClassAlias(Spam, exclude_attrs=['foo', 'bar'], defer=True)
self.assertEqual(x.exclude_attrs, ['foo', 'bar'])
x.compile()
self.assertEqual(x.exclude_attrs, ['bar', 'foo'])
示例5: test_anonymous
def test_anonymous(self):
x = ClassAlias(Spam, None)
x.compile()
self.assertTrue(x.anonymous)
self.assertTrue(x._compiled)
self.assertEqual(x.klass, Spam)
self.assertEqual(x.alias, '')
示例6: test_compiled
def test_compiled(self):
x = ClassAlias(Spam, defer=True)
self.assertFalse(x._compiled)
x._compiled = True
o = x.static_properties = object()
x.compile()
self.assertTrue(o is x.static_properties)
示例7: test_sealed_external
def test_sealed_external(self):
class A(object):
__slots__ = ('foo',)
class __amf__:
external = True
def __readamf__(self, foo):
pass
def __writeamf__(self, foo):
pass
x = ClassAlias(A)
x.compile()
self.assertTrue(x.sealed)
示例8: test_classic
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'})
示例9: ApplyAttributesTestCase
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'})
示例10: setUp
def setUp(self):
self.alias = ClassAlias(Spam, 'foo', defer=True)
self.obj = Spam()
示例11: GetDecodableAttributesTestCase
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']
#.........这里部分代码省略.........
示例12: GetEncodableAttributesTestCase
class GetEncodableAttributesTestCase(unittest.TestCase):
"""
Tests for L{ClassAlias.getEncodableAttributes}
"""
def setUp(self):
self.alias = ClassAlias(Spam, 'foo', defer=True)
self.obj = Spam()
def test_empty(self):
attrs = self.alias.getEncodableAttributes(self.obj)
self.assertEqual(attrs, {})
def test_static(self):
self.alias.static_attrs = ['foo', 'bar']
self.alias.compile()
self.obj.foo = 'bar'
# leave self.obj.bar
self.assertFalse(hasattr(self.obj, 'bar'))
attrs = self.alias.getEncodableAttributes(self.obj)
self.assertEqual(attrs, {'foo': 'bar', 'bar': pyamf.Undefined})
def test_not_dynamic(self):
self.alias.compile()
self.alias.dynamic = False
self.assertEqual(self.alias.getEncodableAttributes(self.obj), {})
def test_dynamic(self):
self.alias.compile()
self.assertEqual(self.alias.encodable_properties, None)
self.obj.foo = 'bar'
self.obj.bar = 'foo'
attrs = self.alias.getEncodableAttributes(self.obj)
self.assertEqual(attrs, {'foo': 'bar', 'bar': 'foo'})
def test_proxy(self):
from pyamf import flex
c = pyamf.get_encoder(pyamf.AMF3)
self.alias.proxy_attrs = ('foo', 'bar')
self.alias.compile()
self.assertEqual(self.alias.proxy_attrs, ['bar', 'foo'])
self.obj.foo = ['bar', 'baz']
self.obj.bar = {'foo': 'gak'}
attrs = self.alias.getEncodableAttributes(self.obj, c)
k = attrs.keys()
k.sort()
self.assertEqual(k, ['bar', 'foo'])
self.assertTrue(isinstance(attrs['foo'], flex.ArrayCollection))
self.assertEqual(attrs['foo'], ['bar', 'baz'])
self.assertTrue(isinstance(attrs['bar'], flex.ObjectProxy))
self.assertEqual(attrs['bar']._amf_object, {'foo': 'gak'})
def test_synonym(self):
self.alias.synonym_attrs = {'foo': 'bar'}
self.alias.compile()
self.assertFalse(self.alias.shortcut_encode)
self.assertFalse(self.alias.shortcut_decode)
self.obj.foo = 'bar'
self.obj.spam = 'eggs'
ret = self.alias.getEncodableAttributes(self.obj)
self.assertEquals(ret, {'bar': 'bar', 'spam': 'eggs'})
示例13: test_createInstance
def test_createInstance(self):
x = ClassAlias(Spam, 'org.example.spam.Spam')
y = x.createInstance()
self.assertTrue(isinstance(y, Spam))
示例14: setUp
def setUp(self):
self.alias = ClassAlias(Spam, 'foo')
self.obj = Spam()
示例15: GetEncodableAttributesTestCase
class GetEncodableAttributesTestCase(unittest.TestCase):
"""
Tests for L{ClassAlias.getEncodableAttributes}
"""
def setUp(self):
self.alias = ClassAlias(Spam, 'foo', defer=True)
self.obj = Spam()
def test_empty(self):
sa, da = self.alias.getEncodableAttributes(self.obj)
self.assertEquals(sa, da, None)
def test_static(self):
self.alias.static_attrs = ['foo', 'bar']
self.alias.compile()
self.obj.foo = 'bar'
# leave self.obj.bar
self.assertFalse(hasattr(self.obj, 'bar'))
sa, da = self.alias.getEncodableAttributes(self.obj)
self.assertEquals(sa, {'foo': 'bar', 'bar': pyamf.Undefined})
self.assertEquals(da, None)
def test_not_dynamic(self):
self.alias.compile()
self.alias.dynamic = False
self.assertEquals(self.alias.getEncodableAttributes(self.obj), (None, None))
def test_dynamic(self):
self.alias.compile()
self.assertEquals(self.alias.encodable_properties, None)
self.obj.foo = 'bar'
self.obj.bar = 'foo'
sa, da = self.alias.getEncodableAttributes(self.obj)
self.assertEquals(sa, None)
self.assertEquals(da, {'foo': 'bar', 'bar': 'foo'})
def test_proxy(self):
from pyamf import flex
self.alias.amf3 = True
self.alias.proxy_attrs = ('foo', 'bar')
self.alias.compile()
self.assertEquals(self.alias.proxy_attrs, ['bar', 'foo'])
self.obj.foo = ['bar', 'baz']
self.obj.bar = {'foo': 'gak'}
sa, da = self.alias.getEncodableAttributes(self.obj)
self.assertEquals(sa, None)
self.assertEquals(da.keys(), ['foo', 'bar'])
self.assertTrue(isinstance(da['foo'], flex.ArrayCollection))
self.assertEquals(da['foo'], ['bar', 'baz'])
self.assertTrue(isinstance(da['bar'], flex.ObjectProxy))
self.assertEquals(da['bar']._amf_object, {'foo': 'gak'})