Skip to content

Commit 929e147

Browse files
committed
push up test_materialize_nonscalar_slot_usage()
1 parent 15c1789 commit 929e147

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

tests/test_utils/test_schemaview.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
from typing import List
77
from unittest import TestCase
88

9+
from jsonasobj2 import JsonObj
10+
911
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, \
1113
ClassDefinitionName, Prefix
1214
from linkml_runtime.loaders.yaml_loader import YAMLLoader
1315
from linkml_runtime.utils.introspection import package_schemaview
@@ -945,6 +947,34 @@ def test_is_inlined(self):
945947
actual_result = sv.is_inlined(slot)
946948
self.assertEqual(actual_result, expected_result)
947949

950+
def test_materialize_nonscalar_slot_usage(self):
951+
schema_path = os.path.join(INPUT_DIR, "DJ_controller_schema.yaml")
952+
sv = SchemaView(schema_path)
953+
cls = sv.induced_class("DJController")
954+
955+
# jog_wheels is a slot asserted at the schema level
956+
# check that the range (scalar value) is being materialized properly
957+
assert cls.attributes["jog_wheels"].range == "integer"
958+
# check that the examples (list) is being materialized properly
959+
assert isinstance(cls.attributes["jog_wheels"].examples, list)
960+
for example in cls.attributes["jog_wheels"].examples:
961+
assert example.value == "2"
962+
for example in cls.attributes["volume_faders"].examples:
963+
assert example.value == "4"
964+
for example in cls.attributes["crossfaders"].examples:
965+
assert example.value == "1"
966+
# check that the annotations (dictionary) is being materialized properly
967+
assert isinstance(cls.attributes["jog_wheels"].annotations, JsonObj)
968+
assert cls.attributes["jog_wheels"].annotations.expected_value.value == "an integer between 0 and 4"
969+
assert cls.attributes["volume_faders"].annotations.expected_value.value == "an integer between 0 and 8"
970+
971+
# examples being overridden by slot_usage modification
972+
assert cls.attributes["tempo"].examples == [Example(value='120.0'), Example(value='144.0'), Example(value='126.8'), Example(value='102.6')]
973+
# annotations remain the same / propagated as is from schema-level
974+
# definition of `tempo` slot
975+
assert cls.attributes["tempo"].annotations.expected_value.value == "a number between 0 and 200"
976+
assert cls.attributes["tempo"].annotations.preferred_unit.value == "BPM"
977+
948978

949979
if __name__ == '__main__':
950980
unittest.main()

0 commit comments

Comments
 (0)