refactoring
This commit is contained in:
parent
c125e1ff6c
commit
7c2cf44ad0
@ -1,6 +1,7 @@
|
|||||||
# .coveragerc to control coverage.py
|
# .coveragerc to control coverage.py
|
||||||
[run]
|
[run]
|
||||||
branch = True
|
branch = True
|
||||||
|
parallel = True
|
||||||
omit =
|
omit =
|
||||||
*/site-packages/*
|
*/site-packages/*
|
||||||
*/distutils/*
|
*/distutils/*
|
||||||
@ -16,7 +17,6 @@ omit =
|
|||||||
*/src/*
|
*/src/*
|
||||||
source =
|
source =
|
||||||
image_prediction
|
image_prediction
|
||||||
src
|
|
||||||
relative_files = True
|
relative_files = True
|
||||||
data_file = .coverage
|
data_file = .coverage
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
|
import socket
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
@ -12,14 +12,17 @@ def host():
|
|||||||
return "127.0.0.1"
|
return "127.0.0.1"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
def get_free_port(host):
|
||||||
def port(host):
|
|
||||||
import socket
|
|
||||||
sock = socket.socket()
|
sock = socket.socket()
|
||||||
sock.bind((host, 0))
|
sock.bind((host, 0))
|
||||||
return sock.getsockname()[1]
|
return sock.getsockname()[1]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def port(host):
|
||||||
|
return get_free_port(host)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def url(host, port):
|
def url(host, port):
|
||||||
return f"http://{host}:{port}"
|
return f"http://{host}:{port}"
|
||||||
@ -34,16 +37,20 @@ def predict_fn():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def run_server_args(host, port, predict_fn):
|
def server(predict_fn):
|
||||||
prediction_server = make_prediction_server(predict_fn)
|
server = make_prediction_server(predict_fn)
|
||||||
return {"app": prediction_server, "host": host, "port": port}
|
return server
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def server(run_server_args):
|
def host_and_port(host, port, server):
|
||||||
|
return {"host": host, "port": port}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def server_process(server, host_and_port):
|
||||||
def get_server_process():
|
def get_server_process():
|
||||||
return Process(target=run_prediction_server, kwargs=run_server_args)
|
return Process(target=run_prediction_server, kwargs={"app": server, **host_and_port})
|
||||||
|
|
||||||
server = get_server_process()
|
server = get_server_process()
|
||||||
server.start()
|
server.start()
|
||||||
@ -51,24 +58,19 @@ def server(run_server_args):
|
|||||||
server.terminate()
|
server.terminate()
|
||||||
|
|
||||||
|
|
||||||
# def test_run_server():
|
def test_server_predict(url):
|
||||||
# prediction_server = make_prediction_server(predict_fn)
|
|
||||||
# return Process(target=run_prediction_server, kwargs={"app": prediction_server, "host": host, "port": port})
|
|
||||||
|
|
||||||
|
|
||||||
def test_server_predict(server, url):
|
|
||||||
response = requests.post(url)
|
response = requests.post(url)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
assert response.json() == 42
|
assert response.json() == 42
|
||||||
|
|
||||||
|
|
||||||
def test_server_health_check(server, url):
|
def test_server_health_check(url):
|
||||||
response = requests.get(f"{url}/health")
|
response = requests.get(f"{url}/health")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_server_ready_check(server, url):
|
def test_server_ready_check(url):
|
||||||
response = requests.get(f"{url}/ready")
|
response = requests.get(f"{url}/ready")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user