Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow additional types for root dataset #126

Merged
merged 1 commit into from May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions rocrate/rocrate.py
Expand Up @@ -151,8 +151,8 @@ def __check_metadata(self, metadata, entities):
root = entities[metadata["about"]["@id"]]
except (KeyError, TypeError):
raise ValueError("metadata descriptor does not reference the root entity")
if root["@type"] != "Dataset":
raise ValueError('root entity must be of type "Dataset"')
if ("Dataset" not in root["@type"] if isinstance(root["@type"], list) else root["@type"] != "Dataset"):
raise ValueError('root entity must have "Dataset" among its types')
return metadata["@id"], root["@id"]

def find_root_entity_id(self, entities):
Expand Down
29 changes: 28 additions & 1 deletion test/test_read.py
Expand Up @@ -530,7 +530,7 @@ def test_find_root_bad_entities():
# root type is not Dataset
entities = deepcopy(orig_entities)
entities["./"]["@type"] = "Thing"
with pytest.raises(ValueError, match="must be of type"):
with pytest.raises(ValueError, match="must have"):
crate.find_root_entity_id(entities)


Expand Down Expand Up @@ -599,3 +599,30 @@ def check_picks_one(entities):
mod_entities = deepcopy(orig_entities)
mod_entities["http://example.com/"]["@type"] = "Thing"
check_finds_org(mod_entities)


def test_find_root_multiple_types():
entities = {_["@id"]: _ for _ in [
{
"@id": "ro-crate-metadata.json",
"@type": "CreativeWork",
"about": {"@id": "./"},
"conformsTo": {"@id": "https://w3id.org/ro/crate/1.1"},
},
{
"@id": "./",
"@type": ["Dataset", "RepositoryCollection"],
},
]}
crate = ROCrate()
m_id, r_id = crate.find_root_entity_id(entities)
assert m_id == "ro-crate-metadata.json"
assert r_id == "./"
# "Dataset" not included
del entities["./"]["@type"][0]
with pytest.raises(ValueError):
crate.find_root_entity_id(entities)
# Check we're not trying to be too clever
entities["./"]["@type"] = "NotADataset"
with pytest.raises(ValueError):
crate.find_root_entity_id(entities)