Skip to content

Commit

Permalink
push up test_materialize_nonscalar_slot_usage()
Browse files Browse the repository at this point in the history
  • Loading branch information
sujaypatil96 committed Aug 1, 2024
1 parent 15c1789 commit 929e147
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tests/test_utils/test_schemaview.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
from typing import List
from unittest import TestCase

from jsonasobj2 import JsonObj

from linkml_runtime.dumpers import yaml_dumper
from linkml_runtime.linkml_model.meta import SchemaDefinition, ClassDefinition, SlotDefinitionName, SlotDefinition, \
from linkml_runtime.linkml_model.meta import Example, SchemaDefinition, ClassDefinition, SlotDefinitionName, SlotDefinition, \
ClassDefinitionName, Prefix
from linkml_runtime.loaders.yaml_loader import YAMLLoader
from linkml_runtime.utils.introspection import package_schemaview
Expand Down Expand Up @@ -945,6 +947,34 @@ def test_is_inlined(self):
actual_result = sv.is_inlined(slot)
self.assertEqual(actual_result, expected_result)

def test_materialize_nonscalar_slot_usage(self):
schema_path = os.path.join(INPUT_DIR, "DJ_controller_schema.yaml")
sv = SchemaView(schema_path)
cls = sv.induced_class("DJController")

# jog_wheels is a slot asserted at the schema level
# check that the range (scalar value) is being materialized properly
assert cls.attributes["jog_wheels"].range == "integer"
# check that the examples (list) is being materialized properly
assert isinstance(cls.attributes["jog_wheels"].examples, list)
for example in cls.attributes["jog_wheels"].examples:
assert example.value == "2"
for example in cls.attributes["volume_faders"].examples:
assert example.value == "4"
for example in cls.attributes["crossfaders"].examples:
assert example.value == "1"
# check that the annotations (dictionary) is being materialized properly
assert isinstance(cls.attributes["jog_wheels"].annotations, JsonObj)
assert cls.attributes["jog_wheels"].annotations.expected_value.value == "an integer between 0 and 4"
assert cls.attributes["volume_faders"].annotations.expected_value.value == "an integer between 0 and 8"

# examples being overridden by slot_usage modification
assert cls.attributes["tempo"].examples == [Example(value='120.0'), Example(value='144.0'), Example(value='126.8'), Example(value='102.6')]
# annotations remain the same / propagated as is from schema-level
# definition of `tempo` slot
assert cls.attributes["tempo"].annotations.expected_value.value == "a number between 0 and 200"
assert cls.attributes["tempo"].annotations.preferred_unit.value == "BPM"


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

0 comments on commit 929e147

Please sign in to comment.