Пример #1
0
 def test_addObserver_identifierDuplicate(self):
     center = NotificationCenter()
     observable = _TestObservable(center, "Observable")
     observer = NotificationTestObserver()
     center.addObserver(observer,
                        "notificationCallback",
                        "A",
                        observable,
                        identifier="identifier1")
     center.addObserver(observer,
                        "notificationCallback",
                        "B",
                        observable,
                        identifier="identifier1")
     expected = [
         dict(observer=observer,
              observable=observable,
              notification="A",
              identifier="identifier1"),
         dict(observer=observer,
              observable=observable,
              notification="B",
              identifier="identifier1")
     ]
     self.assertEqual(center.findObservations(), expected)
Пример #2
0
 def test_removeObserver_identifier(self):
     center = NotificationCenter()
     observable = _TestObservable(center, "Observable")
     observer = NotificationTestObserver()
     center.addObserver(observer,
                        "notificationCallback",
                        "A",
                        observable,
                        identifier="identifier1")
     center.addObserver(observer,
                        "notificationCallback",
                        "B",
                        observable,
                        identifier="identifier2")
     center.removeObserver(observer, "A", observable)
     center.removeObserver(observer, "B", observable)
     expected = []
     self.assertEqual(center.findObservations(), expected)
Пример #3
0
 def test_findObservations_noIdentifier(self):
     center = NotificationCenter()
     observable = _TestObservable(center, "Observable")
     observer = NotificationTestObserver()
     center.addObserver(observer,
                        "notificationCallback",
                        "A",
                        observable,
                        identifier="identifier1")
     center.addObserver(observer, "notificationCallback", "B", observable)
     expected = [
         dict(observer=observer,
              observable=observable,
              notification="A",
              identifier="identifier1"),
         dict(observer=observer,
              observable=observable,
              notification="B",
              identifier=None)
     ]
     result = center.findObservations()
     self.assertEqual(result, expected)