Skip to content

Commit

Permalink
tests for any_of ranges in usage_index()
Browse files Browse the repository at this point in the history
  • Loading branch information
sujaypatil96 committed May 23, 2024
1 parent 2b90134 commit ef4f5a5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions linkml_runtime/utils/schemaview.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,7 @@ def usage_index(self) -> Dict[ElementName, List[SchemaUsage]]:
if isinstance(x, AnonymousSlotExpression):
x = x.range
k = f"{k}[range]"
k = k.split("[")[0] + "[range]" if "[range]" in k else k
u = SchemaUsage(used_by=cn, slot=sn, metaslot=k, used=x)
u.inferred = sn in direct_slots
ix[x].append(u)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_utils/input/kitchen_sink_noimports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,15 @@ classes:
- age in years
- addresses
- has birth event
- reason_for_happiness
slot_usage:
name:
pattern: "^\\S+ \\S+" ## do not do this in a real schema, people have all kinds of names
reason_for_happiness:
any_of:
- range: BirthEvent
- range: EmploymentEvent
- range: MarriageEvent

Adult:
is_a: Person
Expand Down Expand Up @@ -353,6 +359,10 @@ slots:
alias: zip
range: string

reason_for_happiness:
range: string
required: false


enums:
FamilialRelationshipType:
Expand Down
38 changes: 37 additions & 1 deletion tests/test_utils/test_schemaview.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_schemaview(self):

self.assertCountEqual(['id', 'name', ## From Thing
'has employment history', 'has familial relationships', 'has medical history',
AGE_IN_YEARS, 'addresses', 'has birth event', ## From Person
AGE_IN_YEARS, 'addresses', 'has birth event', 'reason_for_happiness', ## From Person
'aliases' ## From HasAliases
],
view.class_slots('Person'))
Expand Down Expand Up @@ -256,6 +256,42 @@ def test_schemaview(self):
logging.debug(f' {k} = {v}')
self.assertIn(SchemaUsage(used_by='FamilialRelationship', slot=RELATED_TO,
metaslot='range', used='Person', inferred=False), u['Person'])
self.assertListEqual(
[SchemaUsage(used_by='Person',
slot='reason_for_happiness',
metaslot='any_of[range]',
used='MarriageEvent',
inferred=True
),
SchemaUsage(used_by='Adult',
slot='reason_for_happiness',
metaslot='any_of[range]',
used='MarriageEvent',
inferred=False
)],
u['MarriageEvent'])
self.assertListEqual(
[SchemaUsage(used_by='Person',
slot='has employment history',
metaslot='range',
used='EmploymentEvent',
inferred=True),
SchemaUsage(used_by='Person',
slot='reason_for_happiness',
metaslot='any_of[range]',
used='EmploymentEvent',
inferred=True),
SchemaUsage(used_by='Adult',
slot='has employment history',
metaslot='range',
used='EmploymentEvent',
inferred=False),
SchemaUsage(used_by='Adult',
slot='reason_for_happiness',
metaslot='any_of[range]',
used='EmploymentEvent',
inferred=False)],
u['EmploymentEvent'])

# test methods also work for attributes
leaves = view.class_leaves()
Expand Down

0 comments on commit ef4f5a5

Please sign in to comment.