|
6 | 6 | from typing import List
|
7 | 7 | from unittest import TestCase
|
8 | 8 |
|
| 9 | +from jsonasobj2 import JsonObj |
| 10 | + |
9 | 11 | from linkml_runtime.dumpers import yaml_dumper
|
10 |
| -from linkml_runtime.linkml_model.meta import SchemaDefinition, ClassDefinition, SlotDefinitionName, SlotDefinition, \ |
| 12 | +from linkml_runtime.linkml_model.meta import Example, SchemaDefinition, ClassDefinition, SlotDefinitionName, SlotDefinition, \ |
11 | 13 | ClassDefinitionName, Prefix
|
12 | 14 | from linkml_runtime.loaders.yaml_loader import YAMLLoader
|
13 | 15 | from linkml_runtime.utils.introspection import package_schemaview
|
@@ -945,6 +947,47 @@ def test_is_inlined(self):
|
945 | 947 | actual_result = sv.is_inlined(slot)
|
946 | 948 | self.assertEqual(actual_result, expected_result)
|
947 | 949 |
|
| 950 | + def test_materialize_nonscalar_slot_usage(self): |
| 951 | + """ |
| 952 | + ``slot_usage`` overrides values in the base slot definition without |
| 953 | + clobbering unrelated, nonscalar values. |
| 954 | + |
| 955 | + See: |
| 956 | + - https://github.com/linkml/linkml/issues/2224 |
| 957 | + - https://github.com/linkml/linkml-runtime/pull/335 |
| 958 | + """ |
| 959 | + schema_path = os.path.join(INPUT_DIR, "DJ_controller_schema.yaml") |
| 960 | + sv = SchemaView(schema_path) |
| 961 | + cls = sv.induced_class("DJController") |
| 962 | + |
| 963 | + # jog_wheels is a slot asserted at the schema level |
| 964 | + # check that the range (scalar value) is being materialized properly |
| 965 | + assert cls.attributes["jog_wheels"].range == "integer" |
| 966 | + # check that the examples (list) is being materialized properly |
| 967 | + assert isinstance(cls.attributes["jog_wheels"].examples, list) |
| 968 | + for example in cls.attributes["jog_wheels"].examples: |
| 969 | + assert example.value == "2" |
| 970 | + for example in cls.attributes["volume_faders"].examples: |
| 971 | + assert example.value == "4" |
| 972 | + for example in cls.attributes["crossfaders"].examples: |
| 973 | + assert example.value == "1" |
| 974 | + # check that the annotations (dictionary) is being materialized properly |
| 975 | + assert isinstance(cls.attributes["jog_wheels"].annotations, JsonObj) |
| 976 | + assert cls.attributes["jog_wheels"].annotations.expected_value.value == "an integer between 0 and 4" |
| 977 | + assert cls.attributes["volume_faders"].annotations.expected_value.value == "an integer between 0 and 8" |
| 978 | + |
| 979 | + # examples being overridden by slot_usage modification |
| 980 | + assert cls.attributes["tempo"].examples == [Example(value='120.0'), Example(value='144.0'), Example(value='126.8'), Example(value='102.6')] |
| 981 | + # annotations remain the same / propagated as is from schema-level |
| 982 | + # definition of `tempo` slot |
| 983 | + assert cls.attributes["tempo"].annotations.expected_value.value == "a number between 0 and 200" |
| 984 | + assert cls.attributes["tempo"].annotations.preferred_unit.value == "BPM" |
| 985 | + |
| 986 | + assert cls.attributes["tempo"].domain_of == ["DJController"] |
| 987 | + # ensure that domain_of is not being populated in slot_usage |
| 988 | + # test for https://github.com/linkml/linkml/pull/2262 from upstream linkml |
| 989 | + assert cls.slot_usage["tempo"].domain_of == [] |
| 990 | + |
948 | 991 |
|
949 | 992 | if __name__ == '__main__':
|
950 | 993 | unittest.main()
|
0 commit comments