File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 2727import os
2828import shutil
2929import tempfile
30+ import warnings
3031
3132from collections import OrderedDict
3233from 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 ))
Original file line number Diff line number Diff 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" ])
713714def 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" ])
You can’t perform that action at this time.
0 commit comments