Skip to content

Commit

Permalink
fix dataset id when adding a local dir with trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
simleo committed Dec 9, 2024
1 parent 7bf5116 commit a5bf0cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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(os.sep))
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

0 comments on commit a5bf0cb

Please sign in to comment.