Skip to content

Commit

Permalink
remove uses of jsonschema in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Feb 26, 2024
1 parent 651c225 commit 63a8c53
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 26 deletions.
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ docs = [
test = [
'pytest',
'pyyaml',
'asdf >= 2.8.0',
'asdf >= 3.0.0',
'packaging>=16.0',
'jsonschema<4.18',
]

[project.urls]
Expand Down
18 changes: 0 additions & 18 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
ref_to_id,
split_id,
)
from jsonschema.validators import Draft4Validator, RefResolver


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -205,20 +204,3 @@ def _assert_latest_schema_correct(path):
)

return _assert_latest_schema_correct


@pytest.fixture(scope="session")
def create_validator(schemas, yaml_schemas):
"""
Fixture method that creates validators with access to schemas in
this repository.
"""

def _create_validator(schema):
store = {s["id"]: s for s in schemas + yaml_schemas}

resolver = RefResolver.from_schema(schema, id_of=Draft4Validator.ID_OF, store=store)

return Draft4Validator(schema, resolver=resolver)

return _create_validator
7 changes: 4 additions & 3 deletions tests/test_asdf_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asdf
import pytest
from asdf.exceptions import ValidationError
from common import SCHEMAS_PATH, assert_yaml_header_and_footer, load_yaml
from jsonschema import ValidationError


@pytest.mark.parametrize("path", SCHEMAS_PATH.glob("asdf-schema-*.yaml"))
Expand All @@ -12,12 +13,12 @@ def test_asdf_schema(path):


@pytest.mark.parametrize("path", SCHEMAS_PATH.glob("asdf-schema-*.yaml"))
def test_nested_object_validation(path, create_validator):
def test_nested_object_validation(path):
"""
Test that the validations are applied to nested objects.
"""
metaschema = load_yaml(path)
validator = create_validator(metaschema)
validator = asdf.schema.get_validator(schema=metaschema)

schema = {"$schema": metaschema["id"], "type": "object", "properties": {"foo": {"datatype": "float32"}}}
# No error here
Expand Down
7 changes: 4 additions & 3 deletions tests/test_yaml_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asdf
import pytest
from asdf.exceptions import ValidationError
from common import YAML_SCHEMA_PATH, assert_yaml_header_and_footer, list_schema_paths, load_yaml
from jsonschema import ValidationError


@pytest.mark.parametrize("path", list_schema_paths(YAML_SCHEMA_PATH))
Expand All @@ -12,12 +13,12 @@ def test_yaml_schema(path):


@pytest.mark.parametrize("path", YAML_SCHEMA_PATH.glob("*.yaml"))
def test_nested_object_validation(path, create_validator):
def test_nested_object_validation(path):
"""
Test that the validations are applied to nested objects.
"""
metaschema = load_yaml(path)
validator = create_validator(metaschema)
validator = asdf.schema.get_validator(schema=metaschema)

schema = {"$schema": metaschema["id"], "type": "object", "properties": {"foo": {"flowStyle": "block"}}}
# No error here
Expand Down

0 comments on commit 63a8c53

Please sign in to comment.