本文整理汇总了Python中observable.Observable.unregister方法的典型用法代码示例。如果您正苦于以下问题:Python Observable.unregister方法的具体用法?Python Observable.unregister怎么用?Python Observable.unregister使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类observable.Observable
的用法示例。
在下文中一共展示了Observable.unregister方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: observerable_test
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import unregister [as 别名]
class observerable_test(unittest.TestCase):
def setUp(self):
self.observable = Observable()
self.observer1 = AnObserver()
self.observer2 = AnObserver()
self.observer3 = AnObserver()
def test_remove_all(self):
self.observable.register(self.observer1)
self.observable.register(self.observer2)
self.observable.register(self.observer3)
self.observable.unregister_all()
# Should be zero registered
self.assertEqual(len(self.observable.observers), 0)
def test_register(self):
self.observable.register(self.observer1)
self.observable.register(self.observer2)
self.observable.register(self.observer3)
# Should be three registered
self.assertEqual(len(self.observable.observers), 3)
self.observable.unregister_all()
def test_unregister(self):
self.observable.register(self.observer1)
self.observable.register(self.observer2)
self.observable.register(self.observer3)
self.observable.unregister(self.observer2)
self.observable.unregister(self.observer3)
# Should be one registered
self.assertEqual(len(self.observable.observers), 1)
self.observable.unregister_all()
def test_update_observers(self):
self.observable.register(self.observer1)
self.observable.update_observers('abc', msg='123')
self.assertEqual(self.observer1.args[0], 'abc')
self.assertEqual(self.observer1.kwargs['msg'], '123')
self.observable.unregister_all()
示例2: observerable_test
# 需要导入模块: from observable import Observable [as 别名]
# 或者: from observable.Observable import unregister [as 别名]
class observerable_test(unittest.TestCase):
def setUp(self):
self.observable = Observable()
self.observer1 = AnObserver()
self.observer2 = AnObserver()
self.observer3 = AnObserver()
def test_remove_all(self):
self.observable.register(self.observer1)
self.observable.register(self.observer2)
self.observable.register(self.observer3)
self.observable.unregister_all()
# Should be zero registered
self.assertEqual(len(self.observable.observers), 0)
def test_register(self):
self.observable.register(self.observer1)
self.observable.register(self.observer2)
self.observable.register(self.observer3)
# Should be three registered
self.assertEqual(len(self.observable.observers), 3)
self.observable.unregister_all()
def test_unregister(self):
self.observable.register(self.observer1)
self.observable.register(self.observer2)
self.observable.register(self.observer3)
self.observable.unregister(self.observer2)
self.observable.unregister(self.observer3)
# Should be one registered
self.assertEqual(len(self.observable.observers), 1)
self.observable.unregister_all()
'''