def test_enter__exit(self): hub = Hub() P = hub.poller = Mock() hub.init = Mock() on_close = Mock() hub.on_close.append(on_close) hub.init() try: hub.init.assert_called_with() read_A = Mock() read_B = Mock() hub.update_readers({10: read_A, File(11): read_B}) write_A = Mock() write_B = Mock() hub.update_writers({20: write_A, File(21): write_B}) self.assertTrue(hub.readers) self.assertTrue(hub.writers) finally: hub.close() self.assertFalse(hub.readers) self.assertFalse(hub.writers) P.unregister.assert_has_calls([ call(10), call(11), call(20), call(21), ], any_order=True) on_close.assert_called_with(hub)
def test_init(self): hub = Hub() cb1 = Mock() cb2 = Mock() hub.on_init.extend([cb1, cb2]) hub.init() cb1.assert_called_with(hub) cb2.assert_called_with(hub)