Skip to content

Conversation

ialarmedalien
Copy link
Collaborator

Making parts of test_schemaview.py more consistent:

  • importing/using some "constants" from schemaview.py
  • create fixtures of some of the schemaviews to avoid recreating them for multiple tests
  • load Path objects directly into SchemaView as it can handle them directly now

Copy link

codecov bot commented Sep 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.38%. Comparing base (66b3861) to head (ccdc7f5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #453   +/-   ##
=======================================
  Coverage   77.38%   77.38%           
=======================================
  Files          52       52           
  Lines        4479     4479           
  Branches      979      979           
=======================================
  Hits         3466     3466           
  Misses        785      785           
  Partials      228      228           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines +96 to +99
@pytest.fixture(scope="session")
def sv_import_tree() -> SchemaView:
"""Fixture for a SchemaView for testing imports and ordering."""
return SchemaView(INPUT_DIR_PATH / "imports" / "main.yaml")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a fixture instead of generating the SV in the test

def sv_attributes() -> SchemaView:
"""Fixture for a SchemaView for testing attribute edge cases."""
return SchemaView(os.path.join(INPUT_DIR, "attribute_edge_cases.yaml"))
return SchemaView(INPUT_DIR_PATH / "attribute_edge_cases.yaml")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for that ugly os.path.join

@pytest.fixture(scope="session")
def creature_view() -> SchemaView:
return SchemaView(str(CREATURE_SCHEMA_BASE_PATH / "creature_schema.yaml"))
return SchemaView(CREATURE_SCHEMA_BASE_PATH / "creature_schema.yaml")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to stringify - SV can deal with Paths

Comment on lines +138 to +140
def creature_view_direct_url() -> SchemaView:
"""Fixture for a SchemaView called directly by using the URL."""
return SchemaView(CREATURE_SCHEMA_RAW_URL)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional test case

assert set(view.imports_closure()) == {"kitchen_sink", "core", "linkml:types"}

for t in view.all_types().keys():
for t in view.all_types():
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for .keys()

Comment on lines +506 to +508
def test_imports_closure_order(sv_import_tree: SchemaView) -> None:
"""Imports should override in a python-like order."""
sv = SchemaView(SCHEMA_IMPORT_TREE)
closure = sv.imports_closure(imports=True)
closure = sv_import_tree.imports_closure(imports=True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use fixture instead of generating SV

Comment on lines +812 to +814
@pytest.mark.parametrize(
"schema", ["creature_view", "creature_view_remote", "creature_view_local", "creature_view_direct_url"]
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add in an extra test case for testing imports

Comment on lines +971 to +980
CAT:
LION:
is_a: CAT
ANGRY_LION:
is_a: LION
TABBY:
is_a: CAT
BIRD:
EAGLE:
is_a: BIRD
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was in the SchemaView module for some reason -- moving it to a more appropriate location



def test_materialize_patterns() -> None:
def test_materialize_patterns(sv_structured_patterns: SchemaView) -> None:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the fixture instead of creating an SV each time

"""Trivial case: merge a schema into an empty schema."""
sv_empty.merge_schema(sv_merge_1.schema)
for k in ELEMENTS:
for k in ALL_ELEMENTS:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what was ELEMENTS is now ALL_ELEMENTS due to importing ELEMENTS from schemaview.py



def test_get_slots_by_enum_schema_slot(sv_issue_998) -> None:
def test_get_slots_by_enum_schema_slot(sv_issue_998: SchemaView) -> None:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add in typing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant