Skip to content

Commit 390887a

Browse files
correctly failing tests for import order and overrides before fixing import closure
1 parent 965c71c commit 390887a

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

tests/test_utils/test_schemaview.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,49 @@ def test_imports_from_schemaview(self):
479479
self.assertCountEqual(view.all_classes(), view2.all_classes())
480480
self.assertCountEqual(view.all_classes(imports=False), view2.all_classes(imports=False))
481481

482-
def test_imports_order(self):
482+
def test_imports_closure_order(self):
483483
"""
484484
Imports should override in a python-like order.
485485
486-
See https://github.com/linkml/linkml/issues/1839
486+
See
487+
- https://github.com/linkml/linkml/issues/1839 for initial discussion
488+
- input/imports/README.md for explanation of the test schema
487489
"""
490+
sv = SchemaView(SCHEMA_IMPORT_TREE)
491+
closure = sv.imports_closure(imports=True, traverse=True)
492+
target = [
493+
'linkml:types',
494+
's1_1',
495+
's1_2_1_1_1', 's1_2_1_1_2',
496+
's1_2_1_1', 's1_2_1', 's1_2',
497+
's1',
498+
's2_1', 's2_2', 's2',
499+
's3_1', 's3_2', 's3',
500+
'main'
501+
]
502+
self.assertEqual(closure, target)
503+
504+
def test_imports_overrides(self):
505+
"""
506+
Classes defined in the importing module should override same-named classes in
507+
imported modules.
508+
509+
Tests recursively across an import tree. Each class defines all classes lower
510+
in the tree with a `value` attribute with an `ifabsent` value matching the
511+
current schema. Lower (closer to the importing schema) schemas should override
512+
each class at that level or lower, keeping the rest.
513+
514+
See `input/imports/README.md` for further explanation.
515+
"""
516+
sv = SchemaView(SCHEMA_IMPORT_TREE)
517+
defaults = {}
518+
target = {}
519+
for name, cls in sv.all_classes(imports=True).items():
520+
target[name] = name
521+
defaults[name] = cls.attributes['value'].ifabsent
522+
523+
self.assertEqual(defaults, target)
524+
488525

489526
def test_direct_remote_imports(self):
490527
"""

0 commit comments

Comments
 (0)