Skip to content

Commit

Permalink
handle non-array hasPart entries
Browse files Browse the repository at this point in the history
  • Loading branch information
simleo committed Sep 22, 2023
1 parent b3e24ba commit 70e2a01
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions rocrate/rocrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def __read_data_entities(self, entities, source, gen_preview):

root_entity = entities.pop(root_id)
assert root_id == root_entity.pop('@id')
parts = root_entity.pop('hasPart', [])
parts = as_list(root_entity.pop('hasPart', []))
self.add(RootDataset(self, root_id, properties=root_entity))
preview_entity = entities.pop(Preview.BASENAME, None)
if preview_entity and not gen_preview:
Expand All @@ -167,7 +167,7 @@ def __add_parts(self, parts, entities, source):
else:
instance = cls(self, source / id_, id_, properties=entity)
self.add(instance)
self.__add_parts(entity.get("hasPart", []), entities, source)
self.__add_parts(as_list(entity.get("hasPart", [])), entities, source)

def __read_contextual_entities(self, entities):
type_map = {_.__name__: _ for _ in subclasses(ContextEntity)}
Expand Down
6 changes: 3 additions & 3 deletions test/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,17 @@ def test_indirect_data_entity(tmpdir):
{
"@id": "./",
"@type": "Dataset",
"hasPart": [{"@id": "d1"}]
"hasPart": {"@id": "d1"}
},
{
"@id": "d1",
"@type": "Dataset",
"hasPart": [{"@id": "d1/d2"}]
"hasPart": {"@id": "d1/d2"}
},
{
"@id": "d1/d2",
"@type": "Dataset",
"hasPart": [{"@id": "d1/d2/f1"}]
"hasPart": {"@id": "d1/d2/f1"}
},
{
"@id": "d1/d2/f1",
Expand Down

0 comments on commit 70e2a01

Please sign in to comment.