Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rocrate/rocrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ def __add_parts(self, parts, entities, source):
if not is_data_entity(entities[id_]):
continue
entity = entities.pop(id_)
assert id_ == entity.pop('@id')
cls = pick_type(entity, type_map, fallback=DataEntity, load_subcrates=self.load_subcrates)
assert id_ == entity.pop('@id')

if cls is Subcrate:

Expand Down Expand Up @@ -288,8 +288,8 @@ def __read_contextual_entities(self, entities):
raise ValueError(f"'{id_}' is a data entity but it's not linked to from the root dataset's hasPart")
else:
warnings.warn(f"'{id_}' looks like a data entity but it's not listed in the root dataset's hasPart")
assert identifier == entity.pop('@id')
cls = pick_type(entity, type_map, fallback=ContextEntity)
assert identifier == entity.pop('@id')
self.add(cls(self, identifier, entity))

@property
Expand Down
30 changes: 30 additions & 0 deletions test/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,36 @@ def test_read_version(test_data_dir):
assert crate.version == "1.2-DRAFT"


@pytest.mark.parametrize(("entity_id", "has_part"), [
("missing-type.txt", True),
("#missing-type", False),
])
def test_entity_without_type_reports_its_id(entity_id, has_part):
root = {
"@id": "./",
"@type": "Dataset",
}
if has_part:
root["hasPart"] = {"@id": entity_id}
metadata = {
"@context": "https://w3id.org/ro/crate/1.1/context",
"@graph": [
{
"@id": "ro-crate-metadata.json",
"@type": "CreativeWork",
"about": {"@id": "./"},
"conformsTo": {"@id": "https://w3id.org/ro/crate/1.1"},
},
root,
{"@id": entity_id},
],
}

with pytest.raises(ValueError) as exc_info:
ROCrate(metadata)
assert str(exc_info.value) == f"entity {entity_id!r} has no @type"


@pytest.mark.filterwarnings("ignore")
@pytest.mark.parametrize("version", ["1.0", "1.1", "1.2"])
def test_data_entity_not_linked(version):
Expand Down
Loading