Skip to content

Commit 64f43a1

Browse files
committed
add: `test_check_schema_builtin & use ABC
1 parent 35d29e6 commit 64f43a1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/check_jsonschema/schema_loader/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import typing as t
66
import urllib.error
77
import urllib.parse
8+
from abc import ABC
89

910
import jsonschema
1011

@@ -59,7 +60,7 @@ def _extend_with_pattern_implementation(
5960
)
6061

6162

62-
class SchemaLoaderBase:
63+
class SchemaLoaderBase(ABC):
6364
def get_validator(
6465
self,
6566
path: pathlib.Path | str,
@@ -68,7 +69,7 @@ def get_validator(
6869
regex_impl: RegexImplementation,
6970
fill_defaults: bool,
7071
) -> jsonschema.protocols.Validator:
71-
raise NotImplementedError
72+
pass
7273

7374

7475
class SchemaLoader(SchemaLoaderBase):

tests/unit/cli/test_schemas.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import jsonschema
2+
import pytest
3+
4+
from check_jsonschema.builtin_schemas import get_builtin_schema
5+
from check_jsonschema.cli.main_command import BUILTIN_SCHEMA_NAMES
6+
from check_jsonschema.regex_variants import RegexImplementation, RegexVariantName
7+
from check_jsonschema.schema_loader.main import _check_schema
8+
9+
10+
@pytest.mark.parametrize("name", BUILTIN_SCHEMA_NAMES)
11+
def test_check_schema_builtin(name):
12+
"""
13+
Test that the buildin schema is valid
14+
"""
15+
regex_impl = RegexImplementation(RegexVariantName.default)
16+
schema = get_builtin_schema(name)
17+
18+
# get the correct validator class and check the schema under its metaschema
19+
validator_cls = jsonschema.validators.validator_for(schema)
20+
_check_schema(validator_cls, schema, regex_impl=regex_impl)

0 commit comments

Comments
 (0)