def test_areNotificationsHeld_all_held(self):
     center = NotificationCenter()
     observable = _TestObservable(center, "Observable")
     observer = NotificationTestObserver()
     center.addObserver(observer, "notificationCallback", "A", observable)
     center.holdNotifications()
     self.assertTrue(center.areNotificationsHeld())
     center.releaseHeldNotifications()
     self.assertFalse(center.areNotificationsHeld())
예제 #2
0
 def test_areNotificationsHeld_all_held(self):
     center = NotificationCenter()
     observable = _TestObservable(center, "Observable")
     observer = NotificationTestObserver()
     center.addObserver(observer, "notificationCallback", "A", observable)
     center.holdNotifications()
     self.assertTrue(center.areNotificationsHeld())
     center.releaseHeldNotifications()
     self.assertFalse(center.areNotificationsHeld())
 def test_areNotificationsHeld_observer_off(self):
     center = NotificationCenter()
     observable = _TestObservable(center, "Observable")
     observer1 = NotificationTestObserver()
     observer2 = NotificationTestObserver()
     center.addObserver(observer1, "notificationCallback", "A", observable)
     center.addObserver(observer2, "notificationCallback", "A", observable)
     center.holdNotifications(observer=observer1)
     self.assertTrue(center.areNotificationsHeld(observer=observer1))
     self.assertFalse(center.areNotificationsHeld(observer=observer2))
     center.releaseHeldNotifications(observer=observer1)
     self.assertFalse(center.areNotificationsHeld(observer=observer1))
 def test_areNotificationsHeld_observable_off(self):
     center = NotificationCenter()
     observable1 = _TestObservable(center, "Observable1")
     observable2 = _TestObservable(center, "Observable2")
     observer = NotificationTestObserver()
     center.addObserver(observer, "notificationCallback", "A", observable1)
     center.addObserver(observer, "notificationCallback", "B", observable2)
     center.holdNotifications(observable=observable1)
     self.assertTrue(center.areNotificationsHeld(observable=observable1))
     self.assertFalse(center.areNotificationsHeld(observable=observable2))
     center.releaseHeldNotifications(observable=observable1)
     self.assertFalse(center.areNotificationsHeld(observable=observable1))
예제 #5
0
 def test_areNotificationsHeld_observer_off(self):
     center = NotificationCenter()
     observable = _TestObservable(center, "Observable")
     observer1 = NotificationTestObserver()
     observer2 = NotificationTestObserver()
     center.addObserver(observer1, "notificationCallback", "A", observable)
     center.addObserver(observer2, "notificationCallback", "A", observable)
     center.holdNotifications(observer=observer1)
     self.assertTrue(center.areNotificationsHeld(observer=observer1))
     self.assertFalse(center.areNotificationsHeld(observer=observer2))
     center.releaseHeldNotifications(observer=observer1)
     self.assertFalse(center.areNotificationsHeld(observer=observer1))
예제 #6
0
 def test_areNotificationsHeld_observable_off(self):
     center = NotificationCenter()
     observable1 = _TestObservable(center, "Observable1")
     observable2 = _TestObservable(center, "Observable2")
     observer = NotificationTestObserver()
     center.addObserver(observer, "notificationCallback", "A", observable1)
     center.addObserver(observer, "notificationCallback", "B", observable2)
     center.holdNotifications(observable=observable1)
     self.assertTrue(center.areNotificationsHeld(observable=observable1))
     self.assertFalse(center.areNotificationsHeld(observable=observable2))
     center.releaseHeldNotifications(observable=observable1)
     self.assertFalse(center.areNotificationsHeld(observable=observable1))
예제 #7
0
    def test_hold_and_releaseHeldNotifications_notifications_of_observable(self):
        "Hold all notifications of a specific observable"
        center = NotificationCenter()
        observable1 = _TestObservable(center, "Observable1")
        observable2 = _TestObservable(center, "Observable2")
        observer = NotificationTestObserver()
        center.addObserver(observer, "notificationCallback", "A", observable1)
        center.addObserver(observer, "notificationCallback", "B", observable1)
        center.addObserver(observer, "notificationCallback", "C", observable2)

        center.holdNotifications(observable=observable1)
        observable1.postNotification("A")
        observable1.postNotification("A")
        observable1.postNotification("B")
        observable2.postNotification("C")
        self.assertEqual(observer.stack[-1], ("C", "Observable2"))
        center.releaseHeldNotifications(observable=observable1)
        self.assertEqual(observer.stack[-2], ("A", "Observable1"))
        self.assertEqual(observer.stack[-1], ("B", "Observable1"))
        self.assertEqual(len(observer.stack), 3)
예제 #8
0
 def test_hold_and_releaseHeldNotifications_notifications_of_observable(
         self):
     "Hold all notifications of a specific notification"
     center = NotificationCenter()
     observable1 = _TestObservable(center, "Observable1")
     observable2 = _TestObservable(center, "Observable2")
     observer = NotificationTestObserver()
     center.addObserver(observer, "notificationCallback", "A", observable1)
     center.addObserver(observer, "notificationCallback", "B", observable1)
     center.addObserver(observer, "notificationCallback", "C", observable2)
     center.holdNotifications(notification="A")
     observable1.postNotification("A")
     observable1.postNotification("A")
     observable1.postNotification("B")
     self.assertEqual(observer.stack[-1], ("B", "Observable1"))
     observable2.postNotification("C")
     self.assertEqual(observer.stack[-1], ("C", "Observable2"))
     center.releaseHeldNotifications(notification="A")
     self.assertEqual(observer.stack[-1], ("A", "Observable1"))
     self.assertEqual(len(observer.stack), 3)