Skip to content

Commit 7f1b6c4

Browse files
committed
Fix and regression test for #84
1 parent 0f9a729 commit 7f1b6c4

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

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: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,19 @@ def test_pr0083(om):
337337
# https://github.com/openMetadataInitiative/openMINDS_Python/pull/83
338338
# by_name() should return None consistently
339339
# when no matches are found, regardless of the 'all' parameter
340-
340+
341341
# all=False (default) should return None when no match is found
342342
result = om.controlled_terms.BiologicalOrder.by_name("nonexistent_order_xyz")
343343
assert result is None
344-
344+
345345
# all=True should also return None when no match is found
346346
results = om.controlled_terms.BiologicalOrder.by_name("nonexistent_order_xyz", all=True)
347-
assert results is None
347+
assert results is None
348+
349+
@pytest.mark.parametrize("om", [openminds.latest, openminds.v4])
350+
def test_issue0084(om):
351+
# Properties whose value evaluates to False (e.g., zero)
352+
# are not serialized if using include_empty_properties=False
353+
obj = om.publications.LivePaperSection(name="test", order=0)
354+
data = obj.to_jsonld(include_empty_properties=False)
355+
assert data == {"name": "test", "order": 0}

0 commit comments

Comments
 (0)