def testAddObserverAnySenderAndPostithObject(self): nc = NotificationCenter() nc.addObserver(observer=self, method=self.handle, notificationName=TestNotificationName.test) nc.postNotification(notificationName=TestNotificationName.test, notifyingObject=self) self.assertTrue(self.notificationReceived) nc.removeObserver(self)
def testAddObserverWrongNotification(self): nc = NotificationCenter() nc.addObserver(observer=self, method=self.handle, notificationName=TestNotificationName.wrong) nc.postNotification(notificationName=TestNotificationName.test, notifyingObject=self, userInfo="1234") self.assertFalse(self.notificationReceived) self.assertNotEqual(self.postedUserInfo, "1234") nc.removeObserver(self)
def testAddObserverAnySenderAndPostWithUserInfo(self): nc = NotificationCenter() nc.addObserver(observer=self, method=self.handle, notificationName=TestNotificationName.test) nc.postNotification(notificationName=TestNotificationName.test, notifyingObject=self, userInfo="1234") self.assertTrue(self.notificationReceived) self.assertEqual(self.postedUserInfo, "1234") nc.removeObserver(self)
def testAddObserverWrongSender(self): someObject = NotificationCenter() nc = NotificationCenter() nc.addObserver(self, method=self.handle, notificationName=TestNotificationName.test, observedObject=someObject) nc.postNotification(notificationName=TestNotificationName.test, notifyingObject=self, userInfo="1234") self.assertFalse(self.notificationReceived) self.assertNotEqual(self.postedUserInfo, "1234") nc.removeObserver(self) self.assertEqual(nc.observersCount(), 0)
def testSingletonCanPost(self): nc = NotificationCenter() nc.postNotification(TestNotificationName.test, self)