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


Python ClassAlias.getDecodableAttributes方法代码示例

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


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

示例1: GetDecodableAttributesTestCase

# 需要导入模块: from pyamf import ClassAlias [as 别名]
# 或者: from pyamf.ClassAlias import getDecodableAttributes [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']
#.........这里部分代码省略.........
开发者ID:notnola,项目名称:pinychat,代码行数:103,代码来源:test_alias.py


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