Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pipeline/src/additional_methods/by_name.py.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@
else:
cls._instance_lookup[key] = [instance]
if match == "equals":
matches = cls._instance_lookup.get(name, None)
matches = cls._instance_lookup.get(name, [])
elif match == "contains":
matches = []
for key, instances in cls._instance_lookup.items():
if name in key:
matches.extend(instances)
else:
raise ValueError("'match' must be either 'equals' or 'contains'")
if all:
if not matches:
return None
elif all:
return matches
elif len(matches) > 0:
return matches[0]
else:
return None
return matches[0]
14 changes: 14 additions & 0 deletions pipeline/tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,17 @@ def test_issue0069(om):
results = om.core.License.by_name("Creative Commons", all=True, match="contains")
assert len(results) == 7
assert all("CC" in r.short_name for r in results)

@pytest.mark.parametrize("om", [openminds.latest])
def test_pr0083(om):
# https://github.com/openMetadataInitiative/openMINDS_Python/pull/83
# by_name() should return None consistently
# when no matches are found, regardless of the 'all' parameter

# all=False (default) should return None when no match is found
result = om.controlled_terms.BiologicalOrder.by_name("nonexistent_order_xyz")
assert result is None

# all=True should also return None when no match is found
results = om.controlled_terms.BiologicalOrder.by_name("nonexistent_order_xyz", all=True)
assert results is None