Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/datajoint/objectref.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,8 @@ def full_path(self) -> str:
protocol = self._backend.protocol
if protocol == "file":
return str(Path(self._backend.spec.get("location", "")) / self.path)
elif protocol == "s3":
bucket = self._backend.spec["bucket"]
return f"s3://{bucket}/{self.path}"
elif protocol == "gcs":
bucket = self._backend.spec["bucket"]
return f"gs://{bucket}/{self.path}"
elif protocol == "azure":
container = self._backend.spec["container"]
return f"az://{container}/{self.path}"
elif protocol in ("s3", "gcs", "azure"):
return self._backend.get_url(self.path)
else:
return self.path

Expand Down
38 changes: 38 additions & 0 deletions tests/unit/test_objectref.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Unit tests for ObjectRef."""

from datetime import datetime, timezone

import pytest

from datajoint.objectref import ObjectRef
from datajoint.storage import StorageBackend


def _object_ref(spec):
return ObjectRef(
path="_schema/scratch/result/data_abc.txt",
size=5,
hash=None,
ext=".txt",
is_dir=False,
timestamp=datetime.now(timezone.utc),
_backend=StorageBackend(spec),
)


@pytest.mark.parametrize(
("spec", "prefix"),
[
(
{"protocol": "s3", "endpoint": "localhost:9000", "bucket": "bkt", "location": "proj/outbox"},
"s3://bkt/proj/outbox/",
),
({"protocol": "s3", "endpoint": "localhost:9000", "bucket": "bkt"}, "s3://bkt/"),
({"protocol": "gcs", "bucket": "bkt", "location": "proj"}, "gs://bkt/proj/"),
({"protocol": "azure", "container": "ctr", "location": "proj"}, "az://ctr/proj/"),
],
)
def test_full_path_includes_store_location(spec, prefix):
"""full_path points where the backend stores the object, location included."""
ref = _object_ref(spec)
assert ref.full_path == prefix + ref.path
Loading