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


Python interface.Attribute方法代码示例

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


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

示例1: test_asStructuredText_with_attribute_no_docstring

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test_asStructuredText_with_attribute_no_docstring(self):
        from zope.interface import Attribute
        from zope.interface import Interface
        EXPECTED = '\n\n'.join([
            "IHasAttribute",
            " This interface has an attribute.",
            " Attributes:",
            "  an_attribute -- no documentation",
            " Methods:",
            ""
        ])
        class IHasAttribute(Interface):
            """ This interface has an attribute.
            """
            an_attribute = Attribute('an_attribute')

        self.assertEqual(self._callFUT(IHasAttribute), EXPECTED) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_document.py

示例2: test_asStructuredText_with_attribute_with_docstring

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test_asStructuredText_with_attribute_with_docstring(self):
        from zope.interface import Attribute
        from zope.interface import Interface
        EXPECTED = '\n\n'.join([
            "IHasAttribute",
            " This interface has an attribute.",
            " Attributes:",
            "  an_attribute -- This attribute is documented.",
            " Methods:",
            ""
        ])
        class IHasAttribute(Interface):
            """ This interface has an attribute.
            """
            an_attribute = Attribute('an_attribute',
                                     'This attribute is documented.')

        self.assertEqual(self._callFUT(IHasAttribute), EXPECTED) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_document.py

示例3: test_asReStructuredText_with_attribute_no_docstring

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test_asReStructuredText_with_attribute_no_docstring(self):
        from zope.interface import Attribute
        from zope.interface import Interface
        EXPECTED = '\n\n'.join([
            "``IHasAttribute``",
            " This interface has an attribute.",
            " Attributes:",
            "  ``an_attribute`` -- no documentation",
            " Methods:",
            ""
        ])
        class IHasAttribute(Interface):
            """ This interface has an attribute.
            """
            an_attribute = Attribute('an_attribute')

        self.assertEqual(self._callFUT(IHasAttribute), EXPECTED) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_document.py

示例4: test_asReStructuredText_with_attribute_with_docstring

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test_asReStructuredText_with_attribute_with_docstring(self):
        from zope.interface import Attribute
        from zope.interface import Interface
        EXPECTED = '\n\n'.join([
            "``IHasAttribute``",
            " This interface has an attribute.",
            " Attributes:",
            "  ``an_attribute`` -- This attribute is documented.",
            " Methods:",
            ""
        ])
        class IHasAttribute(Interface):
            """ This interface has an attribute.
            """
            an_attribute = Attribute('an_attribute',
                                     'This attribute is documented.')

        self.assertEqual(self._callFUT(IHasAttribute), EXPECTED) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_document.py

示例5: test___iter__

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test___iter__(self):
        from zope.interface.interface import Attribute
        from zope.interface.interface import fromFunction
        def _bar():
            """DOCSTRING"""
        def _foo():
            """DOCSTRING"""
        BASE_ATTRS = {'foo': Attribute('Foo', ''),
                      'bar': fromFunction(_bar),
                     }
        DERIVED_ATTRS = {'foo': fromFunction(_foo),
                         'baz': Attribute('Baz', ''),
                        }
        base = self._makeOne('IBase', attrs=BASE_ATTRS)
        derived = self._makeOne('IDerived', bases=(base,), attrs=DERIVED_ATTRS)
        self.assertEqual(sorted(derived), ['bar', 'baz', 'foo']) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_interface.py

示例6: test_namesAndDescriptions_w_all_True_simple

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test_namesAndDescriptions_w_all_True_simple(self):
        from zope.interface.interface import Attribute
        from zope.interface.interface import fromFunction
        def _bar():
            """DOCSTRING"""
        BASE_ATTRS = {'foo': Attribute('Foo', ''),
                      'bar': fromFunction(_bar),
                     }
        DERIVED_ATTRS = {'baz': Attribute('Baz', ''),
                        }
        base = self._makeOne('IBase', attrs=BASE_ATTRS)
        derived = self._makeOne('IDerived', bases=(base,), attrs=DERIVED_ATTRS)
        self.assertEqual(sorted(derived.namesAndDescriptions(all=True)),
                        [('bar', BASE_ATTRS['bar']),
                         ('baz', DERIVED_ATTRS['baz']),
                         ('foo', BASE_ATTRS['foo']),
                        ]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_interface.py

示例7: test_namesAndDescriptions_w_all_True_bases_w_same_names

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test_namesAndDescriptions_w_all_True_bases_w_same_names(self):
        from zope.interface.interface import Attribute
        from zope.interface.interface import fromFunction
        def _bar():
            """DOCSTRING"""
        def _foo():
            """DOCSTRING"""
        BASE_ATTRS = {'foo': Attribute('Foo', ''),
                      'bar': fromFunction(_bar),
                     }
        DERIVED_ATTRS = {'foo': fromFunction(_foo),
                         'baz': Attribute('Baz', ''),
                        }
        base = self._makeOne('IBase', attrs=BASE_ATTRS)
        derived = self._makeOne('IDerived', bases=(base,), attrs=DERIVED_ATTRS)
        self.assertEqual(sorted(derived.namesAndDescriptions(all=True)),
                        [('bar', BASE_ATTRS['bar']),
                         ('baz', DERIVED_ATTRS['baz']),
                         ('foo', DERIVED_ATTRS['foo']),
                        ]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_interface.py

示例8: test_direct_hit_local_miss_bases

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test_direct_hit_local_miss_bases(self):
        from zope.interface.interface import Attribute
        from zope.interface.interface import fromFunction
        def _bar():
            """DOCSTRING"""
        def _foo():
            """DOCSTRING"""
        BASE_ATTRS = {'foo': Attribute('Foo', ''),
                      'bar': fromFunction(_bar),
                     }
        DERIVED_ATTRS = {'foo': fromFunction(_foo),
                         'baz': Attribute('Baz', ''),
                        }
        base = self._makeOne('IBase', attrs=BASE_ATTRS)
        derived = self._makeOne('IDerived', bases=(base,), attrs=DERIVED_ATTRS)
        self.assertEqual(derived.direct('foo'), DERIVED_ATTRS['foo'])
        self.assertEqual(derived.direct('baz'), DERIVED_ATTRS['baz'])
        self.assertEqual(derived.direct('bar'), None) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_interface.py

示例9: test_verifyObject

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test_verifyObject(self):
        from zope.interface import Attribute
        from zope.interface import Interface
        from zope.interface.verify import verifyObject
        

        class ICheckMe(Interface):
            attr = Attribute(u'My attr')

            def method():
                pass

        class CheckMe(object):
            __implemented__ = ICheckMe
            attr = 'value'

            def method(self):
                pass

        check_me = CheckMe()

        self.assertTrue(verifyObject(ICheckMe, check_me)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_interface.py

示例10: test_names_derived

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test_names_derived(self):
        from zope.interface import Attribute
        from zope.interface import Interface
        

        class IBase(Interface):
            attr = Attribute(u'My attr')

            def method():
                pass

        class IDerived(IBase):
            attr2 = Attribute(u'My attr2')

            def method():
                pass

            def method2():
                pass

        self.assertEqual(sorted(IDerived.names()),
                         ['attr2', 'method', 'method2'])
        self.assertEqual(sorted(IDerived.names(all=True)),
                         ['attr', 'attr2', 'method', 'method2']) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:test_interface.py

示例11: test_namesAndDescriptions_simple

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test_namesAndDescriptions_simple(self):
        from zope.interface import Attribute
        from zope.interface.interface import Method
        from zope.interface import Interface
        

        class ISimple(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        name_values = sorted(ISimple.namesAndDescriptions())

        self.assertEqual(len(name_values), 2)
        self.assertEqual(name_values[0][0], 'attr')
        self.assertTrue(isinstance(name_values[0][1], Attribute))
        self.assertEqual(name_values[0][1].__name__, 'attr')
        self.assertEqual(name_values[0][1].__doc__, 'My attr')
        self.assertEqual(name_values[1][0], 'method')
        self.assertTrue(isinstance(name_values[1][1], Method))
        self.assertEqual(name_values[1][1].__name__, 'method')
        self.assertEqual(name_values[1][1].__doc__, 'My method') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_interface.py

示例12: test___getitem__simple

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test___getitem__simple(self):
        from zope.interface import Attribute
        from zope.interface.interface import Method
        from zope.interface import Interface
        

        class ISimple(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        a_desc = ISimple['attr']
        self.assertTrue(isinstance(a_desc, Attribute))
        self.assertEqual(a_desc.__name__, 'attr')
        self.assertEqual(a_desc.__doc__, 'My attr')

        m_desc = ISimple['method']
        self.assertTrue(isinstance(m_desc, Method))
        self.assertEqual(m_desc.__name__, 'method')
        self.assertEqual(m_desc.__doc__, 'My method') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_interface.py

示例13: test___contains__derived

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test___contains__derived(self):
        from zope.interface import Attribute
        from zope.interface import Interface
        

        class IBase(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        class IDerived(IBase):
            attr2 = Attribute(u'My attr2')

            def method():
                "My method, overridden"

            def method2():
                "My method2"

        self.assertTrue('attr' in IDerived)
        self.assertTrue('method' in IDerived)
        self.assertTrue('attr2' in IDerived)
        self.assertTrue('method2' in IDerived) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:test_interface.py

示例14: test___iter__derived

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test___iter__derived(self):
        from zope.interface import Attribute
        from zope.interface import Interface
        

        class IBase(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        class IDerived(IBase):
            attr2 = Attribute(u'My attr2')

            def method():
                "My method, overridden"

            def method2():
                "My method2"

        self.assertEqual(sorted(list(IDerived)),
                         ['attr', 'attr2', 'method', 'method2']) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_interface.py

示例15: test_description_cache_management

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import Attribute [as 别名]
def test_description_cache_management(self):
        # See https://bugs.launchpad.net/zope.interface/+bug/185974
        # There was a bug where the cache used by Specification.get() was not
        # cleared when the bases were changed.
        from zope.interface import Interface
        from zope.interface import Attribute

        class I1(Interface):
            a = Attribute('a')

        class I2(I1):
            pass

        class I3(I2):
            pass

        self.assertTrue(I3.get('a') is I1.get('a'))

        I2.__bases__ = (Interface,)
        self.assertTrue(I3.get('a') is None) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_interface.py


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