Skip to content

Commit ab1ab68

Browse files
committed
data entity not linked from hasPart: raise only for 1.2
1 parent a63f49a commit ab1ab68

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

rocrate/rocrate.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import os
2828
import shutil
2929
import tempfile
30+
import warnings
3031

3132
from collections import OrderedDict
3233
from pathlib import Path
@@ -207,7 +208,11 @@ def __read_contextual_entities(self, entities):
207208
type_map = {_.__name__: _ for _ in subclasses(ContextEntity)}
208209
for identifier, entity in entities.items():
209210
if is_data_entity(entity):
210-
raise ValueError(f"{entity['@id']} is a data entity but it's not linked from the root dataset's hasPart")
211+
id_ = entity['@id']
212+
if self.version_obj >= Version("1.2"):
213+
raise ValueError(f"'{id_}' is a data entity but it's not linked to from the root dataset's hasPart")
214+
else:
215+
warnings.warn(f"'{id_}' looks like a data entity but it's not listed in the root dataset's hasPart")
211216
assert identifier == entity.pop('@id')
212217
cls = pick_type(entity, type_map, fallback=ContextEntity)
213218
self.add(cls(self, identifier, entity))

test/test_read.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ def test_read_version(test_data_dir):
709709
assert crate.version == "1.1"
710710

711711

712+
@pytest.mark.filterwarnings("ignore")
712713
@pytest.mark.parametrize("version", ["1.0", "1.1", "1.2"])
713714
def test_data_entity_not_linked(version):
714715
metadata = {
@@ -737,8 +738,13 @@ def test_data_entity_not_linked(version):
737738
}
738739
]
739740
}
740-
with pytest.raises(ValueError, match="hasPart"):
741-
ROCrate(metadata)
741+
if version == "1.2":
742+
with pytest.raises(ValueError, match="hasPart"):
743+
ROCrate(metadata)
744+
else:
745+
crate = ROCrate(metadata)
746+
f1 = crate.get("f1.txt")
747+
assert f1 in crate.contextual_entities
742748

743749

744750
@pytest.mark.parametrize("version", ["1.0", "1.1", "1.2"])

0 commit comments

Comments
 (0)