From 9798766065f8979d96b3fbe9f9a8c02e4590148d Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 23 Nov 2024 10:09:49 +0100 Subject: [PATCH] Add test --- src/ome_zarr_models/base.py | 6 ++++++ tests/v04/test_bioformats2raw.py | 21 ++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/ome_zarr_models/base.py b/src/ome_zarr_models/base.py index 1d86801..689a715 100644 --- a/src/ome_zarr_models/base.py +++ b/src/ome_zarr_models/base.py @@ -12,3 +12,9 @@ class Config: """ validate_assignment = True + # This allows fields with aliases to be populated by either + # their alias or class attribute name + # + # We use this so we can handle (at least) the "bioformats2raw.version" + # key - attributes in Python can't contain a "." + populate_by_name = True diff --git a/tests/v04/test_bioformats2raw.py b/tests/v04/test_bioformats2raw.py index d5829b6..fb5205a 100644 --- a/tests/v04/test_bioformats2raw.py +++ b/tests/v04/test_bioformats2raw.py @@ -1,4 +1,3 @@ -import json from pathlib import Path from ome_zarr_models.v04.bioformats2raw import BioFormats2Raw @@ -13,6 +12,22 @@ def test_bioformats2raw_exmaple_json(): with open(Path(__file__).parent / "data" / "bioformats2raw_example.json") as f: - data = json.load(f) + model = BioFormats2Raw.model_validate_json(f.read()) - assert BioFormats2Raw(**data["bioformats"]) + assert model == BioFormats2Raw( + bioformats2raw_layout=3, + plate=Plate( + acquisitions=[ + AcquisitionInPlate( + id=0, maximumfieldcount=None, name=None, description=None + ) + ], + columns=[ColumnInPlate(name="1")], + field_count=1, + name="Plate Name 0", + rows=[RowInPlate(name="A")], + version="0.4", + wells=[WellInPlate(path="A/1", rowIndex=0, columnIndex=0)], + ), + series=None, + )