@@ -61,7 +61,9 @@ def test_issue_0003(om):
6161 }
6262
6363 assert (
64- node1 .to_jsonld (include_empty_properties = False ) == node2 .to_jsonld (include_empty_properties = False ) == expected
64+ node1 .to_jsonld (include_empty_properties = False )
65+ == node2 .to_jsonld (include_empty_properties = False )
66+ == expected
6567 )
6668
6769
@@ -96,7 +98,9 @@ def test_issue0007(om):
9698 om .core .Affiliation (member_of = uni2 ),
9799 ]
98100
99- actual = person .to_jsonld (include_empty_properties = False , embed_linked_nodes = False , with_context = True )
101+ actual = person .to_jsonld (
102+ include_empty_properties = False , embed_linked_nodes = False , with_context = True
103+ )
100104 expected = {
101105 "@context" : {"@vocab" : "https://openminds.om-i.org/props/" },
102106 "@id" : "_:001" ,
@@ -117,7 +121,9 @@ def test_issue0007(om):
117121 assert actual == expected
118122
119123 c = Collection (person , uni1 , uni2 )
120- output_paths = c .save ("issue0007.jsonld" , individual_files = False , include_empty_properties = False )
124+ output_paths = c .save (
125+ "issue0007.jsonld" , individual_files = False , include_empty_properties = False
126+ )
121127 assert output_paths == ["issue0007.jsonld" ]
122128
123129 with open (output_paths [0 ]) as fp :
@@ -170,7 +176,9 @@ def test_issue0008(om):
170176 family_name = "Professor" ,
171177 affiliations = [om .core .Affiliation (member_of = uni1 , end_date = date (2023 , 9 , 30 ))],
172178 )
173- actual = person .to_jsonld (include_empty_properties = False , embed_linked_nodes = False , with_context = True )
179+ actual = person .to_jsonld (
180+ include_empty_properties = False , embed_linked_nodes = False , with_context = True
181+ )
174182 expected = {
175183 "@context" : {"@vocab" : "https://openminds.om-i.org/props/" },
176184 "@id" : "_:002" ,
@@ -196,22 +204,31 @@ def test_issue0026(om):
196204
197205 uni1 = om .core .Organization (full_name = "University of This Place" , id = "_:uthisp" )
198206 person = om .core .Person (
199- given_name = "A" , family_name = "Professor" , affiliations = [om .core .Affiliation (member_of = uni1 )], id = "_:ap"
207+ given_name = "A" ,
208+ family_name = "Professor" ,
209+ affiliations = [om .core .Affiliation (member_of = uni1 )],
210+ id = "_:ap" ,
200211 )
201212
202213 c = Collection (person )
203214
204215 # uni1 was not added explicitly, but should nevertheless be included in the JSON-LD export
205216
206- output_paths = c .save ("issue0026.jsonld" , individual_files = False , include_empty_properties = False )
217+ output_paths = c .save (
218+ "issue0026.jsonld" , individual_files = False , include_empty_properties = False
219+ )
207220
208221 new_collection = Collection ()
209222 new_collection .load (* output_paths , version = om .__name__ .split ("." )[1 ])
210223 os .remove ("issue0026.jsonld" )
211224
212- person_again = [item for item in new_collection if isinstance (item , om .core .Person )][0 ]
225+ person_again = [
226+ item for item in new_collection if isinstance (item , om .core .Person )
227+ ][0 ]
213228 assert len (person_again .affiliations ) == 1
214- assert person_again .affiliations [0 ].member_of .full_name == "University of This Place"
229+ assert (
230+ person_again .affiliations [0 ].member_of .full_name == "University of This Place"
231+ )
215232
216233
217234@pytest .mark .parametrize ("om" , [openminds .latest , openminds .v4 ])
@@ -222,9 +239,14 @@ def test_issue0023(om):
222239
223240 uni1 = om .core .Organization (full_name = "University of This Place" , id = "_:uthisp" )
224241 person = om .core .Person (
225- given_name = "A" , family_name = "Professor" , affiliations = [om .core .Affiliation (member_of = uni1 )], id = "_:ap"
242+ given_name = "A" ,
243+ family_name = "Professor" ,
244+ affiliations = [om .core .Affiliation (member_of = uni1 )],
245+ id = "_:ap" ,
246+ )
247+ dv = om .core .DatasetVersion (
248+ full_name = "The name of the dataset version" , custodians = [person ], id = "_:dv"
226249 )
227- dv = om .core .DatasetVersion (full_name = "The name of the dataset version" , custodians = [person ], id = "_:dv" )
228250
229251 c = Collection (dv )
230252
@@ -234,18 +256,28 @@ def test_issue0023(om):
234256 person .affiliations .append (om .core .Affiliation (member_of = uni2 ))
235257 dv .repository = om .core .FileRepository (iri = "http://example.com" , id = "_:fr" )
236258
237- output_paths = c .save ("issue0023.jsonld" , individual_files = False , include_empty_properties = False )
259+ output_paths = c .save (
260+ "issue0023.jsonld" , individual_files = False , include_empty_properties = False
261+ )
238262
239263 new_collection = Collection ()
240264 new_collection .load (* output_paths , version = om .__name__ .split ("." )[1 ])
241265 os .remove ("issue0023.jsonld" )
242266
243- dv_again = [item for item in new_collection if isinstance (item , om .core .DatasetVersion )][0 ]
267+ dv_again = [
268+ item for item in new_collection if isinstance (item , om .core .DatasetVersion )
269+ ][0 ]
244270 assert isinstance (dv_again .repository , om .core .FileRepository )
245271 assert dv_again .repository .iri .value == "http://example.com"
246272 assert len (dv_again .custodians [0 ].affiliations ) == 2
247- assert dv_again .custodians [0 ].affiliations [0 ].member_of .full_name == "University of This Place"
248- assert dv_again .custodians [0 ].affiliations [1 ].member_of .full_name == "University of That Place"
273+ assert (
274+ dv_again .custodians [0 ].affiliations [0 ].member_of .full_name
275+ == "University of This Place"
276+ )
277+ assert (
278+ dv_again .custodians [0 ].affiliations [1 ].member_of .full_name
279+ == "University of That Place"
280+ )
249281
250282
251283@pytest .mark .parametrize ("om" , [openminds .latest , openminds .v4 ])
@@ -258,12 +290,14 @@ def test_issue0056(om):
258290 dataset = om .core .Dataset (
259291 digital_identifier = [
260292 om .core .DOI (identifier = "abc" ),
261- om .core .DOI (identifier = "def" )
293+ om .core .DOI (identifier = "def" ),
262294 ]
263295 )
264296 failures = dataset .validate (ignore = ["required" ])
265297 assert len (failures ) == 1
266- assert failures ["multiplicity" ] == ['digital_identifier does not accept multiple values, but contains 2' ]
298+ assert failures ["multiplicity" ] == [
299+ "digital_identifier does not accept multiple values, but contains 2"
300+ ]
267301 data = dataset .to_jsonld ()
268302 json .dumps (data ) # this should not raise an Exception
269303
@@ -272,14 +306,8 @@ def test_issue0056(om):
272306def test_issue0073a (om ):
273307 # https://github.com/openMetadataInitiative/openMINDS_Python/issues/73
274308 # Infinite recursion in validate()
275- ds1 = om .core .DatasetVersion (
276- short_name = "ds1" ,
277- is_alternative_version_of = None
278- )
279- ds2 = om .core .DatasetVersion (
280- short_name = "ds2" ,
281- is_alternative_version_of = ds1
282- )
309+ ds1 = om .core .DatasetVersion (short_name = "ds1" , is_alternative_version_of = None )
310+ ds2 = om .core .DatasetVersion (short_name = "ds2" , is_alternative_version_of = ds1 )
283311 ds1 .is_alternative_version_of = ds2
284312
285313 failures = ds1 .validate ()
@@ -289,14 +317,8 @@ def test_issue0073a(om):
289317def test_issue0073b (om ):
290318 # https://github.com/openMetadataInitiative/openMINDS_Python/issues/73
291319 # Infinite recursion in validate()
292- ds1 = om .core .DatasetVersion (
293- short_name = "ds1" ,
294- is_variant_of = None
295- )
296- ds2 = om .core .DatasetVersion (
297- short_name = "ds2" ,
298- is_variant_of = ds1
299- )
320+ ds1 = om .core .DatasetVersion (short_name = "ds1" , is_variant_of = None )
321+ ds2 = om .core .DatasetVersion (short_name = "ds2" , is_variant_of = ds1 )
300322 ds1 .is_variant_of = ds2
301323
302324 failures = ds1 .validate ()
@@ -316,10 +338,16 @@ def test_issue0069(om):
316338 result = om .sands .ParcellationEntity .by_name ("NODa,b" )
317339 assert result .abbreviation == "NODa,b"
318340
319- result = om .sands .CommonCoordinateSpace .by_name ("MEBRAINS population-based monkey brain template" )
341+ result = om .sands .CommonCoordinateSpace .by_name (
342+ "MEBRAINS population-based monkey brain template"
343+ )
320344 assert result .full_name == "MEBRAINS population-based monkey brain template"
321345
322- assert om .controlled_terms .BiologicalOrder .by_name ("rodents" ) == om .controlled_terms .BiologicalOrder .by_name ("Rodentia" ) != None
346+ assert (
347+ om .controlled_terms .BiologicalOrder .by_name ("rodents" )
348+ == om .controlled_terms .BiologicalOrder .by_name ("Rodentia" )
349+ != None
350+ )
323351
324352 # Test with "all=True"
325353 results = om .sands .BrainAtlasVersion .by_name ("Julich-Brain Atlas" , all = True )
@@ -332,16 +360,33 @@ def test_issue0069(om):
332360 assert len (results ) == 7
333361 assert all ("CC" in r .short_name for r in results )
334362
363+
335364@pytest .mark .parametrize ("om" , [openminds .latest ])
336365def test_pr0083 (om ):
337366 # https://github.com/openMetadataInitiative/openMINDS_Python/pull/83
338367 # by_name() should return None consistently
339368 # when no matches are found, regardless of the 'all' parameter
340-
369+
341370 # all=False (default) should return None when no match is found
342371 result = om .controlled_terms .BiologicalOrder .by_name ("nonexistent_order_xyz" )
343372 assert result is None
344-
373+
345374 # all=True should also return None when no match is found
346- results = om .controlled_terms .BiologicalOrder .by_name ("nonexistent_order_xyz" , all = True )
347- assert results is None
375+ results = om .controlled_terms .BiologicalOrder .by_name (
376+ "nonexistent_order_xyz" , all = True
377+ )
378+ assert results is None
379+
380+
381+ @pytest .mark .parametrize ("om" , [openminds .latest , openminds .v4 ])
382+ def test_issue0084 (om ):
383+ # Properties whose value evaluates to False (e.g., zero)
384+ # are not serialized if using include_empty_properties=False
385+ obj = om .publications .LivePaperSection (name = "test" , order = 0 )
386+ data = obj .to_jsonld (include_empty_properties = False )
387+ assert data == {
388+ "@context" : {"@vocab" : "https://openminds.om-i.org/props/" },
389+ "@type" : "https://openminds.om-i.org/types/LivePaperSection" ,
390+ "name" : "test" ,
391+ "order" : 0 ,
392+ }
0 commit comments