def testWhenMethod(self): class WhenTest(observable.Subscriber): def when_foo_baz(self, foo, bazChannel, data): data.called = 1 observable.registerWhenMethods(WhenTest) d = DummyEvent() d.called = 0 w = WhenTest() w.foo = self.publisher self.publisher.publish('baz',d) assert d.called, "This method should have been called." d.called = 0 self.publisher.publish('baz',d) assert d.called, "This method should have been called again." d.called = 0 w.foo = None self.publisher.publish('baz',d) assert not d.called, "This method should not have been called"
def testWhenMethod(self): class WhenTest(observable.Subscriber): def when_foo_baz(self, foo, bazChannel, data): data.called = 1 observable.registerWhenMethods(WhenTest) d = DummyEvent() d.called = 0 w = WhenTest() w.foo = self.publisher self.publisher.publish('baz', d) assert d.called, "This method should have been called." d.called = 0 self.publisher.publish('baz', d) assert d.called, "This method should have been called again." d.called = 0 w.foo = None self.publisher.publish('baz', d) assert not d.called, "This method should not have been called"