Skip to content

Commit

Permalink
Check that Step.name doesn't contain dots or spaces (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmbmb committed Apr 16, 2024
1 parent 49e87c0 commit 23c5fe5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/distilabel/steps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def process(self, inputs: *StepInput) -> StepOutput:
arbitrary_types_allowed=True, validate_default=True, validate_assignment=True
)

name: str
name: str = Field(pattern=r"^[a-zA-Z0-9_-]+$")
pipeline: Annotated[Any, Field(exclude=True, repr=False)] = None
input_mappings: Dict[str, str] = {}
output_mappings: Dict[str, str] = {}
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/steps/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)
from distilabel.steps.typing import GeneratorStepOutput, StepOutput
from distilabel.utils.serialization import TYPE_INFO_KEY
from pydantic import ValidationError


class DummyStep(Step):
Expand Down Expand Up @@ -65,6 +66,17 @@ def process(self, inputs: StepInput) -> StepOutput:


class TestStep:
def test_create_step_with_invalid_name(self) -> None:
pipeline = Pipeline(name="unit-test-pipeline")

with pytest.raises(ValidationError):
DummyStep(
name="this-is-not-va.li.d-because-it-contains-dots", pipeline=pipeline
)

with pytest.raises(ValidationError):
DummyStep(name="this is not valid because spaces", pipeline=pipeline)

def test_create_step_passing_pipeline(self) -> None:
pipeline = Pipeline(name="unit-test-pipeline")
step = DummyStep(name="dummy", pipeline=pipeline)
Expand Down

0 comments on commit 23c5fe5

Please sign in to comment.