Skip to content

Commit

Permalink
feat: resolve paths in datasamples spec
Browse files Browse the repository at this point in the history
Signed-off-by: ThibaultFy <50656860+ThibaultFy@users.noreply.github.com>
  • Loading branch information
ThibaultFy committed Oct 12, 2023
1 parent babec85 commit 34ea495
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
12 changes: 5 additions & 7 deletions substra/sdk/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,17 @@ def exclusive_paths(cls, values): # noqa: N805
@pydantic.model_validator(mode="before")
def resolve_paths(cls, values): # noqa: N805
"""Resolve given path is relative."""

if "paths" in values:
paths = []
for path in values["paths"]:
if not path.is_absolute():
paths.append(path.resolve())
else:
paths.append(path)
path = pathlib.Path(path)
paths.append(path.resolve()) if not path.is_absolute() else paths.append(path)

values["paths"] = paths

elif "path" in values:
if not values["path"].is_absolute():
values["path"] = values["path"].resolve()
path = pathlib.Path(values["path"])
values["path"] = path.resolve() if not path.is_absolute() else path

return values

Expand Down
20 changes: 20 additions & 0 deletions tests/sdk/test_schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pathlib
import uuid

import pytest

from substra.sdk.schemas import DataSampleSpec


@pytest.mark.parametrize("path", [pathlib.Path() / "data", "./data", pathlib.Path().cwd() / "data"])
def test_datasample_spec_resolve_path(path):
datasample_spec = DataSampleSpec(path=path, data_manager_keys=[str(uuid.uuid4())])

assert datasample_spec.path == pathlib.Path().cwd() / "data"


def test_datasample_spec_resolve_paths():
paths = [pathlib.Path() / "data", "./data", pathlib.Path().cwd() / "data"]
datasample_spec = DataSampleSpec(paths=paths, data_manager_keys=[str(uuid.uuid4())])

assert all([path == pathlib.Path().cwd() / "data" for path in datasample_spec.paths])

0 comments on commit 34ea495

Please sign in to comment.