def test_callback_for(self): hub = Hub() reader, writer = Mock(), Mock() hub.readers = {6: reader} hub.writers = {7: writer} self.assertEqual(hub._callback_for(6, READ), reader) self.assertEqual(hub._callback_for(7, WRITE), writer) with self.assertRaises(KeyError): hub._callback_for(6, WRITE) self.assertEqual(hub._callback_for(6, WRITE, 'foo'), 'foo')
def test_callback_for(self): hub = Hub() reader, writer = Mock(), Mock() hub.readers = {6: reader} hub.writers = {7: writer} self.assertEqual(hub._callback_for(6, READ), reader) self.assertEqual(hub._callback_for(7, WRITE), writer) with self.assertRaises(KeyError): hub._callback_for(6, WRITE) self.assertEqual(hub._callback_for(6, WRITE, "foo"), "foo")