|
2 | 2 | from pathlib import Path |
3 | 3 |
|
4 | 4 | import pytest |
| 5 | +from pydantic import ValidationError |
5 | 6 |
|
6 | 7 | from entitysdk.models.cell_morphology_protocol import ( |
7 | 8 | CellMorphologyProtocol, |
@@ -112,6 +113,32 @@ def test_register(request, client, httpx_mock, auth_token, json_data_fixture, mo |
112 | 113 | assert registered.model_dump(mode="json", exclude_unset=True) == expected_json |
113 | 114 |
|
114 | 115 |
|
| 116 | +@pytest.mark.parametrize( |
| 117 | + ("json_data_fixture", "model_fixture"), |
| 118 | + [ |
| 119 | + ("json_digital_reconstruction", "model_digital_reconstruction"), |
| 120 | + ("json_modified_reconstruction", "model_modified_reconstruction"), |
| 121 | + ("json_computationally_synthesized", "model_computationally_synthesized"), |
| 122 | + ("json_placeholder", "model_placeholder"), |
| 123 | + ], |
| 124 | +) |
| 125 | +def test_adapter(request, json_data_fixture, model_fixture): |
| 126 | + json_data = request.getfixturevalue(json_data_fixture) |
| 127 | + model = request.getfixturevalue(model_fixture) |
| 128 | + |
| 129 | + new_model = Model(**json_data) |
| 130 | + assert new_model == model |
| 131 | + |
| 132 | + new_model = Model.model_validate(json_data) |
| 133 | + assert new_model == model |
| 134 | + |
| 135 | + with pytest.raises(TypeError, match="Positional args not supported"): |
| 136 | + new_model = Model("name") |
| 137 | + |
| 138 | + with pytest.raises(ValidationError, match="Extra inputs are not permitted"): |
| 139 | + Model(generation_type=json_data["generation_type"], invalid_input="invalid") |
| 140 | + |
| 141 | + |
115 | 142 | @pytest.mark.parametrize( |
116 | 143 | ("json_data_fixture", "model_fixture"), |
117 | 144 | [ |
|
0 commit comments