@@ -310,3 +310,47 @@ def test_rdf_subclassing_switch(self):
310310 rdf_writer = RDFWriter ([doc ], rdf_subclassing = False )
311311 result = rdf_writer .get_rdf_str ()
312312 self .assertNotIn ("odml:Cell" , result )
313+
314+ def test_rdf_custom_subclasses (self ):
315+ sub_class_term = "cell"
316+
317+ # Create minimal document
318+ doc = odml .Document ()
319+ _ = odml .Section (name = "test_subclassing" , type = sub_class_term , parent = doc )
320+
321+ # Test None dict
322+ rdf_writer = RDFWriter ([doc ], custom_subclasses = None )
323+ self .assertIn ("odml:Cell" , rdf_writer .get_rdf_str ())
324+
325+ # Test invalid dict
326+ rdf_writer = RDFWriter ([doc ], custom_subclasses = ["invalid" ])
327+ self .assertIn ("odml:Cell" , rdf_writer .get_rdf_str ())
328+
329+ # Test value whitespace
330+ invalid_dict = {"type_1" : "Class 1" , "type_2" : "Class 2" }
331+ with self .assertRaises (ValueError ):
332+ _ = RDFWriter ([doc ], custom_subclasses = invalid_dict )
333+
334+ # Test custom subclassing
335+ type_custom_class = "species"
336+ custom_class_dict = {type_custom_class : "Species" }
337+
338+ doc = odml .Document ()
339+ _ = odml .Section (name = "test_subclassing" , type = "cell" , parent = doc )
340+ _ = odml .Section (name = "test_custom_subclassing" , type = type_custom_class , parent = doc )
341+
342+ rdf_writer = RDFWriter ([doc ], custom_subclasses = custom_class_dict )
343+ self .assertIn ("odml:Cell" , rdf_writer .get_rdf_str ())
344+ self .assertIn ("odml:Species" , rdf_writer .get_rdf_str ())
345+
346+ # Test custom subclassing overwrite
347+ sub_class_type = "cell"
348+ custom_class_dict = {sub_class_type : "Neuron" }
349+
350+ doc = odml .Document ()
351+ _ = odml .Section (name = "test_subclassing" , type = sub_class_type , parent = doc )
352+
353+ with self .assertWarns (UserWarning ):
354+ rdf_writer = RDFWriter ([doc ], custom_subclasses = custom_class_dict )
355+ self .assertNotIn ("odml:Cell" , rdf_writer .get_rdf_str ())
356+ self .assertIn ("odml:Neuron" , rdf_writer .get_rdf_str ())
0 commit comments