Skip to content

Commit ad74966

Browse files
authored
Merge pull request #343 from linkml/range_expression_any_of
convert schemaview unittests to pytest
2 parents ccb0772 + 1b5e9f7 commit ad74966

File tree

3 files changed

+878
-1011
lines changed

3 files changed

+878
-1011
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ update_model:
1010
cp -pr $(MODEL_DIR)/* linkml_runtime/linkml_model
1111

1212
test:
13-
poetry run python -m unittest discover
13+
poetry run pytest
14+
1415

1516
# temporary measure until linkml-model is synced
1617
linkml_runtime/processing/validation_datamodel.py: linkml_runtime/processing/validation_datamodel.yaml

linkml_runtime/utils/schemaview.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
ENUM_NAME = Union[EnumDefinitionName, str]
3737

3838
ElementType = TypeVar("ElementType", bound=Element)
39-
ElementNameType = TypeVar("ElementNameType", bound=Union[ElementName,str])
39+
ElementNameType = TypeVar("ElementNameType", bound=Union[ElementName, str])
4040
DefinitionType = TypeVar("DefinitionType", bound=Definition)
41-
DefinitionNameType = TypeVar("DefinitionNameType", bound=Union[DefinitionName,str])
41+
DefinitionNameType = TypeVar("DefinitionNameType", bound=Union[DefinitionName, str])
4242
ElementDict = Dict[ElementNameType, ElementType]
4343
DefDict = Dict[DefinitionNameType, DefinitionType]
4444

@@ -53,7 +53,6 @@ class OrderedBy(Enum):
5353
"""
5454

5555

56-
5756
def _closure(f, x, reflexive=True, depth_first=True, **kwargs):
5857
if reflexive:
5958
rv = [x]
@@ -84,7 +83,7 @@ def load_schema_wrap(path: str, **kwargs):
8483
schema: SchemaDefinition
8584
schema = yaml_loader.load(path, target_class=SchemaDefinition, **kwargs)
8685
if "\n" not in path:
87-
# if "\n" not in path and "://" not in path:
86+
# if "\n" not in path and "://" not in path:
8887
# only set path if the input is not a yaml string or URL.
8988
# Setting the source path is necessary for relative imports;
9089
# while initializing a schema with a yaml string is possible, there
@@ -229,7 +228,8 @@ def load_import(self, imp: str, from_schema: SchemaDefinition = None):
229228
return schema
230229

231230
@lru_cache(None)
232-
def imports_closure(self, imports: bool = True, traverse: Optional[bool] = None, inject_metadata=True) -> List[SchemaDefinitionName]:
231+
def imports_closure(self, imports: bool = True, traverse: Optional[bool] = None, inject_metadata=True) -> List[
232+
SchemaDefinitionName]:
233233
"""
234234
Return all imports
235235
@@ -314,7 +314,7 @@ def imports_closure(self, imports: bool = True, traverse: Optional[bool] = None,
314314
visited.add(sn)
315315

316316
# filter duplicates, keeping first entry
317-
closure = list({k:None for k in closure}.keys())
317+
closure = list({k: None for k in closure}.keys())
318318

319319
if inject_metadata:
320320
for s in self.schema_map.values():
@@ -420,7 +420,6 @@ def _order_inheritance(self, elements: DefDict) -> DefDict:
420420

421421
return {s.name: s for s in slist}
422422

423-
424423
@lru_cache(None)
425424
def all_classes(self, ordered_by=OrderedBy.PRESERVE, imports=True) -> Dict[ClassDefinitionName, ClassDefinition]:
426425
"""
@@ -865,15 +864,14 @@ def permissible_value_ancestors(self, permissible_value_text: str,
865864

866865
@lru_cache(None)
867866
def permissible_value_descendants(self, permissible_value_text: str,
868-
enum_name: ENUM_NAME,
869-
reflexive=True,
870-
depth_first=True) -> List[str]:
867+
enum_name: ENUM_NAME,
868+
reflexive=True,
869+
depth_first=True) -> List[str]:
871870
"""
872871
Closure of permissible_value_children method
873872
:enum
874873
"""
875874

876-
877875
return _closure(lambda x: self.permissible_value_children(x, enum_name),
878876
permissible_value_text,
879877
reflexive=reflexive,
@@ -1396,9 +1394,9 @@ def induced_slot(self, slot_name: SLOT_NAME, class_name: CLASS_NAME = None, impo
13961394
else:
13971395
# can rewrite below as:
13981396
# 1. if v2:
1399-
# 2. if v2 is not None and
1397+
# 2. if v2 is not None and
14001398
# (
1401-
# (isinstance(v2, (dict, list)) and v2) or
1399+
# (isinstance(v2, (dict, list)) and v2) or
14021400
# (isinstance(v2, JsonObj) and as_dict(v2))
14031401
# )
14041402
if not is_empty(v2):
@@ -1548,7 +1546,7 @@ def is_inlined(self, slot: SlotDefinition, imports=True) -> bool:
15481546
return True
15491547
elif slot.inlined_as_list:
15501548
return True
1551-
1549+
15521550
id_slot = self.get_identifier_slot(range, imports=imports)
15531551
if id_slot is None:
15541552
# must be inlined as has no identifier
@@ -1592,7 +1590,7 @@ def slot_range_as_union(self, slot: SlotDefinition) -> List[ElementName]:
15921590
"""
15931591
Returns all applicable ranges for a slot
15941592
1595-
Typically any given slot has exactly one range, and one metamodel element type,
1593+
Typically, any given slot has exactly one range, and one metamodel element type,
15961594
but a proposed feature in LinkML 1.2 is range expressions, where ranges can be defined as unions
15971595
15981596
:param slot:
@@ -1604,9 +1602,9 @@ def slot_range_as_union(self, slot: SlotDefinition) -> List[ElementName]:
16041602
if x.range:
16051603
range_union_of.append(x.range)
16061604
return range_union_of
1607-
1605+
16081606
def get_classes_by_slot(
1609-
self, slot: SlotDefinition, include_induced: bool = False
1607+
self, slot: SlotDefinition, include_induced: bool = False
16101608
) -> List[ClassDefinitionName]:
16111609
"""Get all classes that use a given slot, either as a direct or induced slot.
16121610

0 commit comments

Comments
 (0)