Skip to content

Commit

Permalink
Prevent Axis.name from staring with "soma_" (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-dark authored Jan 13, 2025
1 parent faab36a commit c3262e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion python-spec/src/somacore/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ class Axis:
Lifecycle: experimental
"""

name: str
name: str = attrs.field()
"""Name of the axis."""
unit: str | None = None
"""Optional string name for the units of the axis."""

@name.validator
def check(self, attribute, value):
if value.startswith("soma_"):
raise ValueError(f"Invalid axis name '{value}'. Cannot start with 'soma_'.")


@attrs.define(frozen=True)
class CoordinateSpace(collections.abc.Sequence[Axis]):
Expand Down
5 changes: 5 additions & 0 deletions python-spec/testing/test_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def check_transform_is_equal(
assert False


def test_invalid_axis_name():
with pytest.raises(ValueError):
Axis("soma_axis")


def test_coordinate_space():
coord_space = CoordinateSpace(
(Axis("x", unit="nanometer"), Axis("y", unit="nanometer")) # type: ignore[arg-type]
Expand Down

0 comments on commit c3262e1

Please sign in to comment.