Skip to content

Commit 912c486

Browse files
authored
Fix and regression test for #84 (#85)
* Fix and add regression test for #84 * fix merge conflict
1 parent 3824d21 commit 912c486

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

pipeline/src/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def to_jsonld(self, include_empty_properties=True, embed_linked_nodes=True, with
7777
data["@id"] = self.id
7878
for property in self.__class__.properties:
7979
value = getattr(self, property.name)
80-
if value or include_empty_properties:
80+
if (value is not None) or include_empty_properties:
8181
if property.multiple:
8282
if value is None:
8383
data[property.path] = value

pipeline/tests/test_regressions.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,31 @@ def test_issue0069(om):
332332
assert len(results) == 7
333333
assert all("CC" in r.short_name for r in results)
334334

335+
335336
@pytest.mark.parametrize("om", [openminds.latest])
336337
def test_pr0083(om):
337338
# https://github.com/openMetadataInitiative/openMINDS_Python/pull/83
338339
# by_name() should return None consistently
339340
# when no matches are found, regardless of the 'all' parameter
340-
341+
341342
# all=False (default) should return None when no match is found
342343
result = om.controlled_terms.BiologicalOrder.by_name("nonexistent_order_xyz")
343344
assert result is None
344-
345+
345346
# all=True should also return None when no match is found
346347
results = om.controlled_terms.BiologicalOrder.by_name("nonexistent_order_xyz", all=True)
347-
assert results is None
348+
assert results is None
349+
350+
351+
@pytest.mark.parametrize("om", [openminds.latest, openminds.v4])
352+
def test_issue0084(om):
353+
# Properties whose value evaluates to False (e.g., zero)
354+
# are not serialized if using include_empty_properties=False
355+
obj = om.publications.LivePaperSection(name="test", order=0)
356+
data = obj.to_jsonld(include_empty_properties=False)
357+
assert data == {
358+
"@context": {"@vocab": "https://openminds.om-i.org/props/"},
359+
"@type": "https://openminds.om-i.org/types/LivePaperSection",
360+
"name": "test",
361+
"order": 0,
362+
}

0 commit comments

Comments
 (0)