|
7 | 7 | from linkml_runtime.loaders.yaml_loader import YAMLLoader
|
8 | 8 | from linkml_runtime.utils.schema_as_dict import schema_as_yaml_dump, schema_as_dict
|
9 | 9 | from linkml_runtime.utils.schemaview import SchemaView
|
| 10 | +from linkml_runtime.utils.schema_builder import ClassDefinition, SchemaBuilder, SlotDefinition |
10 | 11 |
|
11 | 12 | from tests.test_utils import INPUT_DIR, OUTPUT_DIR
|
12 | 13 |
|
@@ -45,5 +46,31 @@ def test_as_dict(self):
|
45 | 46 | assert 'text' not in pv
|
46 | 47 | self.assertIn('name', obj['slots'])
|
47 | 48 |
|
| 49 | + |
| 50 | + def test_as_dict_with_attributes(self): |
| 51 | + """ |
| 52 | + tests schema_as_dict, see https://github.com/linkml/linkml/issues/100 |
| 53 | + """ |
| 54 | + |
| 55 | + # Create a class with an attribute named 'name' |
| 56 | + cls = ClassDefinition(name="Patient") |
| 57 | + slots = [ |
| 58 | + SlotDefinition(name="id", range="string"), |
| 59 | + SlotDefinition(name="name", range="string"), |
| 60 | + ] |
| 61 | + builder = SchemaBuilder() |
| 62 | + builder.add_class(cls=cls, slots=slots, use_attributes=True) |
| 63 | + |
| 64 | + # Verify that the 'name' slot exists in the schema |
| 65 | + view = SchemaView(builder.schema) |
| 66 | + self.assertIn('name', view.all_slots()) |
| 67 | + |
| 68 | + # Convert the schema to a dict |
| 69 | + obj = schema_as_dict(view.schema) |
| 70 | + |
| 71 | + # Verify that the 'name' slot still exists, as an attribute |
| 72 | + self.assertIn('name', obj['classes']['Patient']['attributes']) |
| 73 | + |
| 74 | + |
48 | 75 | if __name__ == '__main__':
|
49 | 76 | unittest.main()
|
0 commit comments