Skip to content

Commit

Permalink
BF: do allow for user to specify a proper full name for "species" in …
Browse files Browse the repository at this point in the history
…metadata

Apparently before we were checking for URLs and only for "common names", not proper long names.
It is susprising that the problem manifested only now then!

Addressing user report on Slack
  • Loading branch information
yarikoptic committed Dec 3, 2024
1 parent e6ed3ae commit 07fe80f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions dandi/metadata/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,10 @@ def extract_species(metadata: dict) -> models.SpeciesType | None:
else:
lower_value = value_orig.lower()
for common_names, prefix, uri, name in species_map:
if any(key in lower_value for key in common_names) or (
prefix is not None and lower_value.startswith(prefix)
if (
lower_value == name.lower()
or any(key in lower_value for key in common_names)
or (prefix is not None and lower_value.startswith(prefix))
):
value_id = uri
value = name
Expand Down
24 changes: 24 additions & 0 deletions dandi/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,30 @@ def test_species():
}


# all of them should match the same record
# There should be no network access -- just matching records
@pytest.mark.parametrize(
"species",
[
"mongolian gerbil",
"mongolian jird",
"Mongolian jird",
"http://purl.obolibrary.org/obo/NCBITaxon_10047",
"Meriones unguiculatus",
"Meriones Unguiculatus",
"meriones Unguiculatus",
],
)
def test_species_all_possible(species: str):
assert extract_species({"species": species}).model_dump(
mode="json", exclude_none=True
) == {
"identifier": "http://purl.obolibrary.org/obo/NCBITaxon_10047",
"schemaKey": "SpeciesType",
"name": "Meriones unguiculatus",
}


def test_extract_unknown_species():
with pytest.raises(ValueError) as excinfo:
extract_species({"species": "mumba-jumba"})
Expand Down

0 comments on commit 07fe80f

Please sign in to comment.