def test_python_builder_flask_distr_runnable(tmpdir, python_builder, pandas_data, server_reqs, request): python_builder: PythonBuilder = request.getfixturevalue(python_builder) args, env = _prepare_distribution(tmpdir, python_builder) from setup import setup_args _check_requirements( tmpdir, { *setup_args['install_requires'], *server_reqs, 'pandas==1.0.3', 'scikit-learn==0.22.2', 'numpy==1.18.2' }) # model reqs check_ebonite_port_free() # TODO make ModelLoader.load cwd-independent server = subprocess.Popen(args, env=env, cwd=tmpdir) with pytest.raises(subprocess.TimeoutExpired): # we hope that 5 seconds is enough to determine that server didn't crash server.wait(5) try: client = HTTPClient() predictions = client.predict(pandas_data) np.testing.assert_array_almost_equal(predictions, [1, 0]) probas = client.predict_proba(pandas_data) np.testing.assert_array_almost_equal(np.argmax(probas, axis=1), [1, 0]) finally: # our server runs for eternity, thus we should kill it to clean up # `server.kill` kills just shell script, Python subprocess still alive parent = psutil.Process(server.pid) for child in parent.children(recursive=True): child.kill() parent.kill()
def main(): try: value_a, value_b = float(sys.argv[1]), float(sys.argv[2]) except (IndexError, ValueError): print(f'Usage: {sys.argv[0]} [float] [float]') return client = HTTPClient() df = pd.DataFrame({'a': [value_a], 'b': [value_b]}) pred = client.predict(df) # pred is numpy array of shape (1,) print(pred.item()) proba = client.predict_proba(df) # proba is numpy array of shape (1, 2) print(list(proba[0]))