Skip to content

Commit c3262e1

Browse files
authored
Prevent Axis.name from staring with "soma_" (#253)
1 parent faab36a commit c3262e1

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

python-spec/src/somacore/coordinates.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ class Axis:
2323
Lifecycle: experimental
2424
"""
2525

26-
name: str
26+
name: str = attrs.field()
2727
"""Name of the axis."""
2828
unit: str | None = None
2929
"""Optional string name for the units of the axis."""
3030

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

3237
@attrs.define(frozen=True)
3338
class CoordinateSpace(collections.abc.Sequence[Axis]):

python-spec/testing/test_coordinates.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ def check_transform_is_equal(
3030
assert False
3131

3232

33+
def test_invalid_axis_name():
34+
with pytest.raises(ValueError):
35+
Axis("soma_axis")
36+
37+
3338
def test_coordinate_space():
3439
coord_space = CoordinateSpace(
3540
(Axis("x", unit="nanometer"), Axis("y", unit="nanometer")) # type: ignore[arg-type]

0 commit comments

Comments
 (0)