def test_tick(self, mocker): im = Image.Image() dummy_request = { 'url': 'http://example.com', 'requested_at': datetime.now() } grabber = Grabber('http://example.com') grabber.create_request = mocker.Mock(grabber.create_request, autospec=True, return_value=dummy_request) dummy_result = {'image': im, 'requested_at': datetime.now()} grabber.download_image = mocker.Mock(grabber.download_image, autospec=True, return_value=dummy_result) grabber.handle_received_image = mocker.Mock( grabber.handle_received_image, autospec=True) grabber.tick() grabber.create_request.assert_called_once_with() grabber.download_image.assert_called_once_with(dummy_request) grabber.handle_received_image.assert_called_once_with(dummy_result)
def test_tick__exception(self, mocker): grabber = Grabber('http://example.com') an_exception = IOError('some exception') mocker.patch.object(grabber, 'create_request', side_effect=an_exception) with pytest.raises(IOError): grabber.tick() assert grabber.failed_exception is an_exception
def test_begin(self, mocker): grabber = Grabber('http://example.com') grabber._test_max_ticks = 5 grabber.every = 13 grabber.tick = mocker.Mock(grabber.tick, autospec=True) mock_sleep = mocker.patch('camgrab.camgrab.sleep', autospec=True) grabber.begin() assert grabber.tick.call_count == 5 assert mock_sleep.call_count == 5 mock_sleep.assert_called_with(13)