From 64f43a10e74b0cec222fce8389854f151576e001 Mon Sep 17 00:00:00 2001 From: Jirka B Date: Thu, 3 Apr 2025 10:31:00 -0400 Subject: [PATCH 1/8] add: `test_check_schema_builtin & use ABC --- src/check_jsonschema/schema_loader/main.py | 5 +++-- tests/unit/cli/test_schemas.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/unit/cli/test_schemas.py diff --git a/src/check_jsonschema/schema_loader/main.py b/src/check_jsonschema/schema_loader/main.py index e056389a9..564e63204 100644 --- a/src/check_jsonschema/schema_loader/main.py +++ b/src/check_jsonschema/schema_loader/main.py @@ -5,6 +5,7 @@ import typing as t import urllib.error import urllib.parse +from abc import ABC import jsonschema @@ -59,7 +60,7 @@ def _extend_with_pattern_implementation( ) -class SchemaLoaderBase: +class SchemaLoaderBase(ABC): def get_validator( self, path: pathlib.Path | str, @@ -68,7 +69,7 @@ def get_validator( regex_impl: RegexImplementation, fill_defaults: bool, ) -> jsonschema.protocols.Validator: - raise NotImplementedError + pass class SchemaLoader(SchemaLoaderBase): diff --git a/tests/unit/cli/test_schemas.py b/tests/unit/cli/test_schemas.py new file mode 100644 index 000000000..03334928b --- /dev/null +++ b/tests/unit/cli/test_schemas.py @@ -0,0 +1,20 @@ +import jsonschema +import pytest + +from check_jsonschema.builtin_schemas import get_builtin_schema +from check_jsonschema.cli.main_command import BUILTIN_SCHEMA_NAMES +from check_jsonschema.regex_variants import RegexImplementation, RegexVariantName +from check_jsonschema.schema_loader.main import _check_schema + + +@pytest.mark.parametrize("name", BUILTIN_SCHEMA_NAMES) +def test_check_schema_builtin(name): + """ + Test that the buildin schema is valid + """ + regex_impl = RegexImplementation(RegexVariantName.default) + schema = get_builtin_schema(name) + + # get the correct validator class and check the schema under its metaschema + validator_cls = jsonschema.validators.validator_for(schema) + _check_schema(validator_cls, schema, regex_impl=regex_impl) \ No newline at end of file From afb82c691db0deae6971c945fa6a83557be05c4b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 3 Apr 2025 14:31:59 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/cli/test_schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/cli/test_schemas.py b/tests/unit/cli/test_schemas.py index 03334928b..63712f5c6 100644 --- a/tests/unit/cli/test_schemas.py +++ b/tests/unit/cli/test_schemas.py @@ -17,4 +17,4 @@ def test_check_schema_builtin(name): # get the correct validator class and check the schema under its metaschema validator_cls = jsonschema.validators.validator_for(schema) - _check_schema(validator_cls, schema, regex_impl=regex_impl) \ No newline at end of file + _check_schema(validator_cls, schema, regex_impl=regex_impl) From 5f44acc67ebffc72bda0a518b98d7b1564e5eb35 Mon Sep 17 00:00:00 2001 From: Jirka B Date: Thu, 3 Apr 2025 11:05:10 -0400 Subject: [PATCH 3/8] mark with `@abstractmethod` --- src/check_jsonschema/schema_loader/main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/check_jsonschema/schema_loader/main.py b/src/check_jsonschema/schema_loader/main.py index 564e63204..971fbe152 100644 --- a/src/check_jsonschema/schema_loader/main.py +++ b/src/check_jsonschema/schema_loader/main.py @@ -5,7 +5,7 @@ import typing as t import urllib.error import urllib.parse -from abc import ABC +from abc import ABC, abstractmethod import jsonschema @@ -61,6 +61,7 @@ def _extend_with_pattern_implementation( class SchemaLoaderBase(ABC): + @abstractmethod def get_validator( self, path: pathlib.Path | str, @@ -69,7 +70,7 @@ def get_validator( regex_impl: RegexImplementation, fill_defaults: bool, ) -> jsonschema.protocols.Validator: - pass + """Get a validator for the given instance document.""" class SchemaLoader(SchemaLoaderBase): From c9c468f01a41de8563bf0c6579f98e583f0144d1 Mon Sep 17 00:00:00 2001 From: Jirka B Date: Thu, 3 Apr 2025 11:28:01 -0400 Subject: [PATCH 4/8] update test with one skip --- tests/unit/cli/test_schemas.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit/cli/test_schemas.py b/tests/unit/cli/test_schemas.py index 63712f5c6..42348c205 100644 --- a/tests/unit/cli/test_schemas.py +++ b/tests/unit/cli/test_schemas.py @@ -12,7 +12,11 @@ def test_check_schema_builtin(name): """ Test that the buildin schema is valid """ - regex_impl = RegexImplementation(RegexVariantName.default) + if name == "vendor.compose-spec": + pytest.skip("vendor.compose-spec does not work") + return + regex_name = RegexVariantName.nonunicode if "azure-pipelines" in name else RegexVariantName.default + regex_impl = RegexImplementation(regex_name) schema = get_builtin_schema(name) # get the correct validator class and check the schema under its metaschema From 07de8f06a7a5658dcfe07c60cb9974f94557fce7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 3 Apr 2025 15:37:51 +0000 Subject: [PATCH 5/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/unit/cli/test_schemas.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit/cli/test_schemas.py b/tests/unit/cli/test_schemas.py index 42348c205..ea2e84278 100644 --- a/tests/unit/cli/test_schemas.py +++ b/tests/unit/cli/test_schemas.py @@ -15,7 +15,11 @@ def test_check_schema_builtin(name): if name == "vendor.compose-spec": pytest.skip("vendor.compose-spec does not work") return - regex_name = RegexVariantName.nonunicode if "azure-pipelines" in name else RegexVariantName.default + regex_name = ( + RegexVariantName.nonunicode + if "azure-pipelines" in name + else RegexVariantName.default + ) regex_impl = RegexImplementation(regex_name) schema = get_builtin_schema(name) From 37d0103353061ed03ee190d883baf0c961dd5c17 Mon Sep 17 00:00:00 2001 From: Jirka B Date: Sat, 5 Apr 2025 15:04:24 +0200 Subject: [PATCH 6/8] skip -> xfail --- tests/unit/cli/test_schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/cli/test_schemas.py b/tests/unit/cli/test_schemas.py index ea2e84278..2bc8fabfa 100644 --- a/tests/unit/cli/test_schemas.py +++ b/tests/unit/cli/test_schemas.py @@ -13,7 +13,7 @@ def test_check_schema_builtin(name): Test that the buildin schema is valid """ if name == "vendor.compose-spec": - pytest.skip("vendor.compose-spec does not work") + pytest.xfail("vendor.compose-spec does not work") return regex_name = ( RegexVariantName.nonunicode From e3d6b6637c47277df2277c94e2053a82a45f1509 Mon Sep 17 00:00:00 2001 From: Jirka B Date: Mon, 7 Apr 2025 10:04:19 +0200 Subject: [PATCH 7/8] with `warnings.filterwarnings("ignore", category=DeprecationWarning)` --- tests/unit/cli/test_schemas.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/unit/cli/test_schemas.py b/tests/unit/cli/test_schemas.py index 2bc8fabfa..1d91cbb79 100644 --- a/tests/unit/cli/test_schemas.py +++ b/tests/unit/cli/test_schemas.py @@ -1,3 +1,5 @@ +import warnings + import jsonschema import pytest @@ -10,16 +12,15 @@ @pytest.mark.parametrize("name", BUILTIN_SCHEMA_NAMES) def test_check_schema_builtin(name): """ - Test that the buildin schema is valid + Test that the builtin schema is valid """ - if name == "vendor.compose-spec": - pytest.xfail("vendor.compose-spec does not work") - return - regex_name = ( - RegexVariantName.nonunicode - if "azure-pipelines" in name - else RegexVariantName.default - ) + regex_name = RegexVariantName.default + if "azure-pipelines" in name: + regex_name = RegexVariantName.nonunicode + elif name == "vendor.compose-spec": + # supress DeprecationWarning: The metaschema specified by $schema was not found. + # This is likely due to the schema being a draft-07 schema. + warnings.filterwarnings("ignore", category=DeprecationWarning) regex_impl = RegexImplementation(regex_name) schema = get_builtin_schema(name) From 10c2cbda2ba45f7c51a72f3fd91be5708079fa45 Mon Sep 17 00:00:00 2001 From: Jirka B Date: Mon, 7 Apr 2025 21:25:28 +0200 Subject: [PATCH 8/8] revert ABC --- src/check_jsonschema/schema_loader/main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/check_jsonschema/schema_loader/main.py b/src/check_jsonschema/schema_loader/main.py index 971fbe152..e056389a9 100644 --- a/src/check_jsonschema/schema_loader/main.py +++ b/src/check_jsonschema/schema_loader/main.py @@ -5,7 +5,6 @@ import typing as t import urllib.error import urllib.parse -from abc import ABC, abstractmethod import jsonschema @@ -60,8 +59,7 @@ def _extend_with_pattern_implementation( ) -class SchemaLoaderBase(ABC): - @abstractmethod +class SchemaLoaderBase: def get_validator( self, path: pathlib.Path | str, @@ -70,7 +68,7 @@ def get_validator( regex_impl: RegexImplementation, fill_defaults: bool, ) -> jsonschema.protocols.Validator: - """Get a validator for the given instance document.""" + raise NotImplementedError class SchemaLoader(SchemaLoaderBase):