Skip to content
Snippets Groups Projects
Commit 2d3e0e87 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Pass stack trace of unhandled exceptions to response body

parent e3162d6b
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ from fastapi import FastAPI, HTTPException
from model_server.session import Session
from model_server.workflow import infer_image_to_image
app = FastAPI()
app = FastAPI(debug=True)
session = Session()
@app.on_event("startup")
......
......@@ -15,7 +15,7 @@ class TestApiFromAutomatedClient(unittest.TestCase):
self.server_process = Process(
target=uvicorn.run,
args=('api:app', ),
kwargs={'host': host, 'port': port, 'log_level': 'info'},
kwargs={'host': host, 'port': port, 'log_level': 'debug'},
daemon=True
)
self.uri = f'http://{host}:{port}/'
......@@ -46,7 +46,7 @@ class TestApiFromAutomatedClient(unittest.TestCase):
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.content, b'{}')
def test_load_model(self):
def test_load_dummy_model(self):
model_id = DummyImageToImageModel.model_id
resp_load = requests.put(
self.uri + f'models/load',
......@@ -57,9 +57,21 @@ class TestApiFromAutomatedClient(unittest.TestCase):
self.assertEqual(resp_list.status_code, 200)
rj = resp_list.json()
self.assertEqual(rj[model_id]['class'], 'DummyImageToImageModel')
return model_id
def test_respond_with_error_when_invalid_filepath_requested(self):
model_id = self.test_load_dummy_model()
resp = requests.put(
self.uri + f'i2i/infer/',
params={
'model_id': model_id,
'input_filename': 'not_a_real_file.name'
}
)
self.assertEqual(resp.status_code, 404, resp.content.decode())
def test_i2i_inference_errors_model_not_found(self):
def test_i2i_inference_errors_when_model_not_found(self):
model_id = 'not_a_real_model'
resp = requests.put(
self.uri + f'i2i/infer/',
......@@ -68,23 +80,18 @@ class TestApiFromAutomatedClient(unittest.TestCase):
'input_filename': 'not_a_real_file.name'
}
)
print(resp.content)
self.assertEqual(resp.status_code, 409)
self.assertEqual(resp.status_code, 409, resp.content.decode())
def test_i2i_dummy_inference_by_api(self):
model = DummyImageToImageModel()
resp_load = requests.put(
self.uri + f'models/load',
params={'model_id': model.model_id}
)
self.assertEqual(resp_load.status_code, 200, f'Error loading {model.model_id}')
model_id = self.test_load_dummy_model()
self.copy_input_file_to_server()
resp_infer = requests.put(
self.uri + f'i2i/infer/',
params={
'model_id': model.model_id,
'model_id': model_id,
'input_filename': czifile['filename'],
'channel': 2,
},
)
self.assertEqual(resp_infer.status_code, 200, f'Error inferring from {model.model_id}')
\ No newline at end of file
self.assertEqual(resp_infer.status_code, 200, f'Error inferring from {model_id}', resp_infer.content.decode())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment