Skip to content

Commit 1679a24

Browse files
authored
Merge pull request #208 from simleo/fix_dir_id
Fix dataset id when adding a local dir with trailing slash
2 parents 7bf5116 + 419670d commit 1679a24

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

rocrate/model/file_or_dir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ def __init__(self, crate, source=None, dest_path=None, fetch_remote=False,
4747
if is_url(str(source)):
4848
identifier = os.path.basename(source) if fetch_remote else source
4949
else:
50-
identifier = "./" if source == "./" else os.path.basename(source)
50+
identifier = os.path.basename(str(source).rstrip("/"))
5151
super().__init__(crate, identifier, properties)

test/test_model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
RAW_REPO_URL = "https://raw.githubusercontent.com/ResearchObject/ro-crate-py"
4242

4343

44-
def test_dereferencing(test_data_dir, helpers):
44+
def test_dereferencing(test_data_dir, helpers, monkeypatch):
4545
crate = ROCrate(gen_preview=True)
4646

4747
# verify default entities
@@ -69,6 +69,12 @@ def test_dereferencing(test_data_dir, helpers):
6969
# alias
7070
assert crate.get(readme_url) is readme_entity
7171

72+
# dereference local dir added with trailing slash
73+
monkeypatch.chdir(test_data_dir)
74+
local_dir = "test_add_dir/"
75+
local_dir_entity = crate.add_dataset(local_dir)
76+
assert crate.dereference(local_dir) is local_dir_entity
77+
7278

7379
@pytest.mark.parametrize("name", [".foo", "foo.", ".foo/", "foo./"])
7480
def test_dereferencing_equivalent_id(test_data_dir, name):

0 commit comments

Comments
 (0)