Coverage for skema/img2mml/tests/test_eqn2mml.py: 97%
30 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-30 17:15 +0000
1from pathlib import Path
2from fastapi.testclient import TestClient
3from skema.img2mml.eqn2mml import app
4from skema.img2mml.api import retrieve_model
6import pytest
9client = TestClient(app)
11@pytest.fixture
12def retrieve_and_load_model():
13 '''Retrieves model if not present and stores on disk'''
14 retrieve_model()
16def test_post_image_to_mml():
17 '''Test case for /image/mml endpoint.'''
18 retrieve_and_load_model
19 cwd = Path(__file__).parents[0]
20 image_path = cwd / "data" / "261.png"
21 with open(image_path, "rb") as infile:
22 image_bytes = infile.read()
23 response = client.post("/image/mml", files={"data": image_bytes})
24 assert response.status_code == 200, "Request was unsuccessful"
25 assert response.text != None, "Response was empty"
27def test_post_image_with_transparent_background_to_mml():
28 '''Test case for /image/mml endpoint.'''
29 retrieve_and_load_model
30 cwd = Path(__file__).parents[0]
31 image_path = cwd / "data" / "sidarthe_eqn1_with_transparent_background.png"
32 with open(image_path, "rb") as infile:
33 image_bytes = infile.read()
34 response = client.post("/image/mml", files={"data": image_bytes})
35 assert response.status_code == 200, "Request was unsuccessful"
36 assert response.text != None, "Response was empty"
38def test_healthcheck():
39 '''Test case for /img2mml/healthcheck endpoint.'''
40 response = client.get("/img2mml/healthcheck")
41 assert response.status_code == 200