-
Notifications
You must be signed in to change notification settings - Fork 34
test_schemaview.py: minor tidying, fixture creation #453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
@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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
def creature_view_direct_url() -> SchemaView: | ||
"""Fixture for a SchemaView called directly by using the URL.""" | ||
return SchemaView(CREATURE_SCHEMA_RAW_URL) |
There was a problem hiding this comment.
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(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for .keys()
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) |
There was a problem hiding this comment.
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
@pytest.mark.parametrize( | ||
"schema", ["creature_view", "creature_view_remote", "creature_view_local", "creature_view_direct_url"] | ||
) |
There was a problem hiding this comment.
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
CAT: | ||
LION: | ||
is_a: CAT | ||
ANGRY_LION: | ||
is_a: LION | ||
TABBY: | ||
is_a: CAT | ||
BIRD: | ||
EAGLE: | ||
is_a: BIRD |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add in typing
Making parts of
test_schemaview.py
more consistent:schemaview.py