diff --git a/src/ome_zarr_models/base.py b/src/ome_zarr_models/base.py index 91e8515..a9b4920 100644 --- a/src/ome_zarr_models/base.py +++ b/src/ome_zarr_models/base.py @@ -12,7 +12,8 @@ class Base(BaseModel): # 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 "." + # We use this so we can handle e.g., the "bioformats2raw.version" + # key - names in Python can't contain a "." populate_by_name=True, + frozen=True, ) diff --git a/tests/v04/test_multiscales.py b/tests/v04/test_multiscales.py index e51632b..acf9266 100644 --- a/tests/v04/test_multiscales.py +++ b/tests/v04/test_multiscales.py @@ -55,6 +55,14 @@ def default_multiscale() -> Multiscale: return multi +def test_immutable(default_multiscale: Multiscale) -> None: + """ + Check that models are immutable. + """ + with pytest.raises(ValidationError, match="Instance is frozen"): + default_multiscale.axes[0].name = "new_name" + + def test_multiscale_unique_axis_names() -> None: # TODO: is unique names actually part of the spec??? axes = (