async def test_predict(mocker, output, expected): mocker.patch("src.app.ml.active_predictor.active_predictor.predict", return_value=output) mocker.patch("src.jobs.store_data_job._save_data_job", return_value=job_id) result = await _predict(MockData(), test_uuid, mock_BackgroundTasks) assert nested_floats_almost_equal(result["prediction"], expected["prediction"]) assert result["job_id"] == test_uuid
async def test_test(mocker, output, expected): mocker.patch("src.app.ml.active_predictor.DataConverter.reshape_output", return_value=output) mocker.patch("src.app.ml.active_predictor.active_predictor.predict", return_value=output) result = await _test(MockData()) assert nested_floats_almost_equal(result["prediction"], expected["prediction"])
def test__predict(mocker, prediction, expected): mock_data = MockData() mocker.patch("src.app.ml.active_predictor.DataConverter.reshape_output", return_value=prediction) mocker.patch("src.app.ml.active_predictor.active_predictor.predict", return_value=prediction) __predict(data=mock_data) assert nested_floats_almost_equal(mock_data.prediction, expected["prediction"])
def test_predict_from_redis_cache(mocker, job_id, data, expected): mocker.patch("src.jobs.store_data_job.load_data_redis", return_value=data) mocker.patch("src.jobs.store_data_job.get_image_redis", return_value=data["image_data"]) mocker.patch("src.app.ml.active_predictor.active_predictor.predict", return_value=np.array(expected["prediction"])) result = _predict_from_redis_cache(job_id, MockData) assert expected["image_data"] == result.image_data assert nested_floats_almost_equal(result.prediction, expected["prediction"])
async def test_predict(mocker, output, expected): mock_image_base64 = get_image_data()["image_data"] mock_data = MockData(image_data=mock_image_base64) mocker.patch("PIL.Image.open", return_value=mock_image) mocker.patch("io.BytesIO", return_value=mock_image) mocker.patch("src.app.ml.active_predictor.active_predictor.predict", return_value=output) mocker.patch("src.jobs.store_data_job._save_data_job", return_value=job_id) result = await _predict(mock_data, mock_BackgroundTasks) assert nested_floats_almost_equal(result["prediction"], expected["prediction"]) assert "job_id" in result
async def test_predict(mocker, output, expected): mock_image_base64 = get_image_data()['image_data'] mock_data = MockData(image_data=mock_image_base64) mocker.patch('PIL.Image.open', return_value=mock_image) mocker.patch('io.BytesIO', return_value=mock_image) mocker.patch('src.app.ml.active_predictor.active_predictor.predict', return_value=output) mocker.patch('src.jobs.store_data_job._save_data_job', return_value=job_id) result = await _predict(mock_data, mock_BackgroundTasks) assert nested_floats_almost_equal(result['prediction'], expected['prediction']) assert 'job_id' in result
def test__predict(mocker, prediction, expected): mock_data = MockData() mocker.patch( 'src.app.ml.active_predictor.DataConverter.convert_input_data_to_np', return_value=np.array(mock_data.input_data).astype(np.float32).reshape(MockDataInterface.input_shape)) mocker.patch( 'src.app.ml.active_predictor.DataConverter.reshape_output', return_value=prediction) mocker.patch( 'src.app.ml.active_predictor.active_predictor.predict', return_value=prediction) __predict(data=mock_data) assert nested_floats_almost_equal(mock_data.prediction, expected['prediction'])
def test_predict_from_redis_cache(mocker, job_id, data, expected): mock_data = MockData( input_data=data['input_data'], prediction=expected['prediction'] ) mocker.patch('src.jobs.store_data_job.load_data_redis', return_value=data) mocker.patch( 'src.app.ml.active_predictor.active_predictor.predict', return_value=np.array(expected['prediction'])) result = _predict_from_redis_cache(job_id, MockData) assert expected['input_data'] == result.input_data assert nested_floats_almost_equal(mock_data.prediction, expected['prediction'])
def test_test(mocker, output, expected): mocker.patch("src.app.ml.active_predictor.active_predictor.predict", return_value=output) result = _test(data=MockData()) assert nested_floats_almost_equal(result["prediction"], expected["prediction"])