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


Python Components.unregisterSubscriptionAdapter方法代码示例

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


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

示例1: TestSubscriber

# 需要导入模块: from zope.interface.registry import Components [as 别名]
# 或者: from zope.interface.registry.Components import unregisterSubscriptionAdapter [as 别名]
class TestSubscriber(unittest.TestCase):

    def setUp(self):
        self.components = Components('comps')

    def test_register_subscriber(self):
        self.components.registerSubscriptionAdapter(A1_2)
        self.components.registerSubscriptionAdapter(A1_12, provided=IA2)
        self.components.registerSubscriptionAdapter(
            A, [I1], IA2, info='a sample comment')
        subscribers = self.components.subscribers((U1(1),), IA2)
        self.assertEqual(len(subscribers), 3)
        self.assertEqual(repr(subscribers[0]), 'A1_2(U1(1))')
        self.assertEqual(repr(subscribers[1]), 'A1_12(U1(1))')
        self.assertEqual(repr(subscribers[2]), 'A(U1(1),)') 

    def test_register_noncompliant_subscriber(self):
        self.assertRaises(TypeError,
                          self.components.registerSubscriptionAdapter, A1_12)
        self.assertRaises(TypeError,
                          self.components.registerSubscriptionAdapter, A)
        self.assertRaises(
            TypeError,
            self.components.registerSubscriptionAdapter, A, required=[IA1])

    def test_register_named_subscriber(self):
        self.components.registerSubscriptionAdapter(
            A, [I1], IA2, u'', u'a sample comment')
        self.assertRaises(TypeError,
                          self.components.registerSubscriptionAdapter, 
                          A, [I1], IA2, u'oops', u'a sample comment')
        subscribers = self.components.subscribers((U1(1),), IA2)
        self.assertEqual(len(subscribers), 1)
        self.assertEqual(repr(subscribers[0]), 'A(U1(1),)')

    def test_register_no_factory(self):
        self.components.registerSubscriptionAdapter(noop, [I1], IA2)
        subscribers = self.components.subscribers((U1(1),), IA2)
        self.assertEqual(len(subscribers), 0)

    def test_sorting_registered_subscription_adapters(self):
        self.components.registerSubscriptionAdapter(A1_2)
        self.components.registerSubscriptionAdapter(A1_12, provided=IA2)
        self.components.registerSubscriptionAdapter(
            A, [I1], IA2, info=u'a sample comment')
        self.components.registerSubscriptionAdapter(
            A, [I1], IA2, u'', u'a sample comment')
        self.components.registerSubscriptionAdapter(noop, [I1], IA2)

        sorted_subscribers = sorted(
            self.components.registeredSubscriptionAdapters())
        sorted_subscribers_name = map(lambda x: getattr(x, 'name'),
                                      sorted_subscribers)
        sorted_subscribers_provided = map(lambda x: getattr(x, 'provided'),
                                          sorted_subscribers) 
        sorted_subscribers_required = map(lambda x: getattr(x, 'required'),
                                          sorted_subscribers)
        sorted_subscribers_factory = map(lambda x: getattr(x, 'factory'),
                                         sorted_subscribers)
        sorted_subscribers_info = map(lambda x: getattr(x, 'info'),
                                      sorted_subscribers)

        self.assertEqual(len(sorted_subscribers), 5)
        self.assertEqual(sorted_subscribers_name, [u'', u'', u'', u'', u''])
        self.assertEqual(sorted_subscribers_provided,
                         [IA2, IA2, IA2, IA2, IA2])
        self.assertEqual(sorted_subscribers_required,
                         [(I1,), (I1,), (I1,),(I1,), (I1,)])
        self.assertEqual(sorted_subscribers_factory,
                         [A, A, A1_12, A1_2, noop])
        self.assertEqual(
            sorted_subscribers_info,
            [u'a sample comment', u'a sample comment', u'', u'', u''])

    def test_unregister(self):
        self.components.registerSubscriptionAdapter(A1_2)
        self.assertEqual(len(self.components.subscribers((U1(1),), IA2)), 1)
        self.assertTrue(self.components.unregisterSubscriptionAdapter(A1_2))
        self.assertEqual(len(self.components.subscribers((U1(1),), IA2)), 0)

    def test_unregister_multiple(self):
        self.components.registerSubscriptionAdapter(A1_2)
        self.components.registerSubscriptionAdapter(A1_12, provided=IA2)
        self.components.registerSubscriptionAdapter(
            A, [I1], IA2, info=u'a sample comment')
        self.components.registerSubscriptionAdapter(
            A, [I1], IA2, u'', u'a sample comment')
        self.components.registerSubscriptionAdapter(noop, [I1], IA2)
        self.assertEqual(len(self.components.subscribers((U1(1),), IA2)), 4)
        self.assertEqual(
            len(list(self.components.registeredSubscriptionAdapters())), 5)

        self.assertTrue(
            self.components.unregisterSubscriptionAdapter(A, [I1], IA2))
        self.assertEqual(len(self.components.subscribers((U1(1),), IA2)), 2)
        self.assertEqual(
            len(list(self.components.registeredSubscriptionAdapters())), 3)

    def test_unregister_no_factory(self):
        self.components.registerSubscriptionAdapter(A1_2)
#.........这里部分代码省略.........
开发者ID:ChimmyTee,项目名称:oh-mainline,代码行数:103,代码来源:test_registry.py


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