Skip to content

Commit

Permalink
Merge pull request #321 from linkml/add-alias-test
Browse files Browse the repository at this point in the history
Adding a test for induced slot alias fields. Additional CURIE tests
  • Loading branch information
cmungall authored Apr 22, 2024
2 parents e5d1886 + 43ba7d3 commit c7815cb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/test_utils/input/kitchen_sink_noimports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ classes:
slots:
- street
- city
- postal code

Event:
slots:
Expand Down Expand Up @@ -348,6 +349,10 @@ slots:
multivalued: true
inlined_as_list: true

postal code:
alias: zip
range: string


enums:
FamilialRelationshipType:
Expand Down
1 change: 1 addition & 0 deletions tests/test_utils/test_metamodelcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_uriorcuries(self):
URIorCURIE(" ")
with self.assertRaises(ValueError):
URIorCURIE("[")
assert URIorCURIE.is_valid("NCIT:C176962")
lax()
URIorCURIE("1abc:def")
URIorCURIE("1:def")
Expand Down
19 changes: 19 additions & 0 deletions tests/test_utils/test_schemaview.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def test_children_method(self):
self.assertEqual(children, ['Adult'])

def test_all_aliases(self):
"""
This tests the aliases slot (not: alias)
:return:
"""
view = SchemaView(SCHEMA_NO_IMPORTS)
aliases = view.all_aliases()
self.assertIn("identifier", aliases["id"])
Expand All @@ -46,6 +50,21 @@ def test_all_aliases(self):
self.assertIn("dad", aliases["Adult"])
self.assertNotIn("test", aliases["Adult"])

def test_alias_slot(self):
"""
Tests the alias slot.
The induced slot alias should always be populated. For induced slots, it should default to the
name field if not present.
"""
view = SchemaView(SCHEMA_NO_IMPORTS)
for c in view.all_classes().values():
for s in view.class_induced_slots(c.name):
self.assertIsNotNone(s.alias)
postal_code_slot = view.induced_slot('postal code', 'Address')
self.assertEqual(postal_code_slot.name, 'postal code')
self.assertEqual(postal_code_slot.alias, 'zip')

def test_schemaview_enums(self):
view = SchemaView(SCHEMA_NO_IMPORTS)
with self.assertRaises(ValueError):
Expand Down

0 comments on commit c7815cb

Please sign in to comment.