diff --git a/Lib/defcon/test/testTools.py b/Lib/defcon/test/testTools.py index 5762fe35..f88066c1 100644 --- a/Lib/defcon/test/testTools.py +++ b/Lib/defcon/test/testTools.py @@ -79,7 +79,7 @@ def __init__(self, name=None): self.stack = [] def __repr__(self): - return "<_TestObservable {name} {id}".format(name=self.name, id=id(self)) + return "<_TestObservable {name} {id}>".format(name=self.name, id=id(self)) def notificationCallback(self, notification): print(notification.name, notification.object.name) diff --git a/Lib/defcon/test/tools/test_notifications.py b/Lib/defcon/test/tools/test_notifications.py index 8b42fe88..01aa6ca0 100644 --- a/Lib/defcon/test/tools/test_notifications.py +++ b/Lib/defcon/test/tools/test_notifications.py @@ -429,7 +429,8 @@ def test_addObserver_identifier(self): dict(observer=observer, observable=observable, notification="A", identifier="identifier1"), dict(observer=observer, observable=observable, notification="B", identifier="identifier2") ] - self.assertEqual(center.findObservations(), expected) + result = center.findObservations() + self.assertEqual(result, expected) def test_addObserver_identifierDuplicate(self): center = NotificationCenter() @@ -528,5 +529,18 @@ def test_findObservations_all(self): result = center.findObservations(observer=observer1, notification="A", observable=observable1, identifier="identifier1-1-A") self.assertEqual(result, expected) + 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) + if __name__ == "__main__": unittest.main() diff --git a/Lib/defcon/tools/notifications.py b/Lib/defcon/tools/notifications.py index 8a7f8c27..9ee631a1 100644 --- a/Lib/defcon/tools/notifications.py +++ b/Lib/defcon/tools/notifications.py @@ -430,17 +430,20 @@ def findObservations(self, observer=None, notification=None, observable=None, id if observable is not None: observable = weakref.ref(observable) found = [] - for (otherNotification, otherObservable), observerDict in self._identifierRegistry.items(): + for (otherNotification, otherObservable), observerDict in self._registry.items(): if notification is not None: if otherNotification != notification: continue if observable is not None: if otherObservable != observable: continue - for otherObserver, otherIdentifier in observerDict.items(): - if identifier is not None: - if not fnmatchcase(otherIdentifier, identifier): - continue + for otherObserver, methodName in observerDict.items(): + otherIdentifier = None + if (otherNotification, otherObservable) in self._identifierRegistry: + otherIdentifier = self._identifierRegistry[otherNotification, otherObservable].get(otherObserver) + if otherIdentifier is not None and identifier is not None: + if not fnmatchcase(otherIdentifier, identifier): + continue if observer is not None: if otherObserver != observer: continue