Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dataset id when adding a local dir with trailing slash #208

Merged
merged 2 commits into from
Dec 10, 2024
Merged
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
2 changes: 1 addition & 1 deletion rocrate/model/file_or_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ def __init__(self, crate, source=None, dest_path=None, fetch_remote=False,
if is_url(str(source)):
identifier = os.path.basename(source) if fetch_remote else source
else:
identifier = "./" if source == "./" else os.path.basename(source)
identifier = os.path.basename(str(source).rstrip("/"))
super().__init__(crate, identifier, properties)
8 changes: 7 additions & 1 deletion test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
RAW_REPO_URL = "https://raw.githubusercontent.com/ResearchObject/ro-crate-py"


def test_dereferencing(test_data_dir, helpers):
def test_dereferencing(test_data_dir, helpers, monkeypatch):
crate = ROCrate(gen_preview=True)

# verify default entities
Expand Down Expand Up @@ -69,6 +69,12 @@ def test_dereferencing(test_data_dir, helpers):
# alias
assert crate.get(readme_url) is readme_entity

# dereference local dir added with trailing slash
monkeypatch.chdir(test_data_dir)
local_dir = "test_add_dir/"
local_dir_entity = crate.add_dataset(local_dir)
assert crate.dereference(local_dir) is local_dir_entity


@pytest.mark.parametrize("name", [".foo", "foo.", ".foo/", "foo./"])
def test_dereferencing_equivalent_id(test_data_dir, name):
Expand Down
Loading