Skip to content

Commit

Permalink
Merge pull request #208 from simleo/fix_dir_id
Browse files Browse the repository at this point in the history
Fix dataset id when adding a local dir with trailing slash
  • Loading branch information
simleo authored Dec 10, 2024
2 parents 7bf5116 + 419670d commit 1679a24
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("/"))
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 1679a24

Please sign in to comment.