def test_callback_for(self): reader, writer = Mock(), Mock() self.hub.readers = {6: reader} self.hub.writers = {7: writer} assert callback_for(self.hub, 6, READ) == reader assert callback_for(self.hub, 7, WRITE) == writer with pytest.raises(KeyError): callback_for(self.hub, 6, WRITE) assert callback_for(self.hub, 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(callback_for(hub, 6, READ), reader) self.assertEqual(callback_for(hub, 7, WRITE), writer) with self.assertRaises(KeyError): callback_for(hub, 6, WRITE) self.assertEqual(callback_for(hub, 6, WRITE, 'foo'), 'foo')