diff --git a/pipeline/src/base.py b/pipeline/src/base.py index 2068e5b..0ce0677 100644 --- a/pipeline/src/base.py +++ b/pipeline/src/base.py @@ -77,7 +77,7 @@ def to_jsonld(self, include_empty_properties=True, embed_linked_nodes=True, with data["@id"] = self.id for property in self.__class__.properties: value = getattr(self, property.name) - if value or include_empty_properties: + if (value is not None) or include_empty_properties: if property.multiple: if value is None: data[property.path] = value diff --git a/pipeline/tests/test_regressions.py b/pipeline/tests/test_regressions.py index 962cba3..13953fe 100644 --- a/pipeline/tests/test_regressions.py +++ b/pipeline/tests/test_regressions.py @@ -316,13 +316,13 @@ def test_issue0069(om): result = om.sands.ParcellationEntity.by_name("NODa,b") assert result.abbreviation == "NODa,b" - result = om.sands.CommonCoordinateSpace.by_name("MEBRAINS population-based monkey brain template") + result = om.sands.CommonCoordinateFramework.by_name("MEBRAINS population-based monkey brain template") assert result.full_name == "MEBRAINS population-based monkey brain template" assert om.controlled_terms.BiologicalOrder.by_name("rodents") == om.controlled_terms.BiologicalOrder.by_name("Rodentia") != None # Test with "all=True" - results = om.sands.BrainAtlasVersion.by_name("Julich-Brain Atlas", all=True) + results = om.sands.AnatomicalAtlasVersion.by_name("Julich-Brain Atlas", all=True) assert len(results) == 30 assert all(r.short_name == "Julich-Brain Atlas" for r in results) assert len(set(r.id for r in results)) == len(results) @@ -332,16 +332,31 @@ def test_issue0069(om): 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 \ No newline at end of file + assert results is None + + +@pytest.mark.parametrize("om", [openminds.latest, openminds.v4]) +def test_issue0084(om): + # Properties whose value evaluates to False (e.g., zero) + # are not serialized if using include_empty_properties=False + obj = om.publications.LivePaperSection(name="test", order=0) + data = obj.to_jsonld(include_empty_properties=False) + assert data == { + "@context": {"@vocab": "https://openminds.om-i.org/props/"}, + "@type": "https://openminds.om-i.org/types/LivePaperSection", + "name": "test", + "order": 0, + }