diff --git a/tests/test_numpy_type.py b/tests/test_numpy_type.py index 1f53f6c..822eceb 100644 --- a/tests/test_numpy_type.py +++ b/tests/test_numpy_type.py @@ -2,6 +2,7 @@ from pydantic import BaseModel, RootModel import numpy as np +from fastapi.testclient import TestClient from labthings_fastapi.testing import create_thing_without_server from labthings_fastapi.types.numpy import NDArray, DenumpifyingDict @@ -70,6 +71,10 @@ class MyNumpyThing(lt.Thing): def action_with_arrays(self, a: NDArray) -> NDArray: return a * 2 + @lt.action + def read_array(self) -> NDArray: + return np.array([1, 2]) + def test_thing_description(): """Make sure the TD validates when numpy types are used.""" @@ -102,3 +107,14 @@ def test_rootmodel(): m = ArrayModel(root=input) assert isinstance(m.root, np.ndarray) assert (m.model_dump() == [0, 1, 2]).all() + + +def test_numpy_over_http(): + """Read numpy array over http.""" + server = lt.ThingServer({"np_thing": MyNumpyThing}) + with TestClient(server.app) as client: + np_thing_client = lt.ThingClient.from_url("/np_thing/", client=client) + + array = np_thing_client.read_array() + assert isinstance(array, np.ndarray) + assert np.array_equal(array, np.array([1, 2]))