Skip to content

Commit

Permalink
🐛 Fix option inheritance in create_path and add tests (#617)
Browse files Browse the repository at this point in the history
fix and test create_path
  • Loading branch information
Koncopd authored Jan 12, 2024
1 parent adbc4b2 commit cacab00
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lamindb_setup/dev/upath.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,9 @@ def create_path(pathlike: Union[str, Path, UPath]) -> UPath:
else:
raise ValueError("pathlike should be of type Union[str, Path, UPath]")

# ensures there's no trailing slash for directories
path = UPath(path.as_posix().rstrip("/"))
# remove trailing slash
if path._parts[-1] == "":
path._parts = path._parts[:-1]

if isinstance(path, S3Path):
path = UPath(path, cache_regions=True)
Expand Down
18 changes: 18 additions & 0 deletions tests/prod-only/test_upath.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from lamindb_setup.dev.upath import UPath, create_path


def test_create_path():
upath = UPath("s3://lndb-setup-ci/xyz/", default_fill_cache=False)
assert "default_fill_cache" in upath._kwargs

upath = create_path(upath)
# test option inheritance
assert "default_fill_cache" in upath._kwargs
# test cache_regions setting for s3
assert "cache_regions" in upath._kwargs
# test removal of training slash
assert upath.as_posix()[-1] != "/"
assert (
UPath("s3://lndb-setup-ci/xyz").as_posix()
== create_path("s3://lndb-setup-ci/xyz/").as_posix()
)

0 comments on commit cacab00

Please sign in to comment.