pytest-jsonschema 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytest_jsonschema/__init__.py +1 -0
- pytest_jsonschema/fixtures.py +44 -0
- pytest_jsonschema/loaders.py +50 -0
- pytest_jsonschema/schemas/__init__.py +9 -0
- pytest_jsonschema/schemas/ansible-vars.json +30 -0
- pytest_jsonschema/schemas/ansible.json +1388 -0
- pytest_jsonschema/schemas/docker-compose.json +2474 -0
- pytest_jsonschema/schemas/github-action.json +725 -0
- pytest_jsonschema/schemas/github-funding.json +113 -0
- pytest_jsonschema/schemas/github-issue-config.json +55 -0
- pytest_jsonschema/schemas/github-issue-forms.json +2302 -0
- pytest_jsonschema/schemas/github-workflow.json +2045 -0
- pytest_jsonschema/schemas/gitlab-ci.json +3107 -0
- pytest_jsonschema/schemas/package.json +1309 -0
- pytest_jsonschema/schemas/pre-commit-config.json +278 -0
- pytest_jsonschema/schemas/pre-commit-hooks.json +450 -0
- pytest_jsonschema/schemas/prettierrc.json +533 -0
- pytest_jsonschema/schemas/pyproject.json +1157 -0
- pytest_jsonschema/schemas/tsconfig.json +1894 -0
- pytest_jsonschema/types.py +20 -0
- pytest_jsonschema/utils/__init__.py +0 -0
- pytest_jsonschema/utils/update_schema.py +58 -0
- pytest_jsonschema/validator.py +19 -0
- pytest_jsonschema-1.0.0.dist-info/METADATA +160 -0
- pytest_jsonschema-1.0.0.dist-info/RECORD +28 -0
- pytest_jsonschema-1.0.0.dist-info/WHEEL +4 -0
- pytest_jsonschema-1.0.0.dist-info/entry_points.txt +2 -0
- pytest_jsonschema-1.0.0.dist-info/licenses/LICENSE +22 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from . import loaders
|
|
2
|
+
from . import schemas
|
|
3
|
+
from . import types
|
|
4
|
+
from . import validator
|
|
5
|
+
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.fixture
|
|
10
|
+
def schema_validate_file() -> types.FileValidator:
|
|
11
|
+
"""Validate a file againstt a known JSON Schema."""
|
|
12
|
+
|
|
13
|
+
def func(path: types.StrPath, schema_name: str, file_type: str = "") -> bool:
|
|
14
|
+
"""Validate a file against a known JSON Schema."""
|
|
15
|
+
data = loaders.data_from_file(path, file_type=file_type)
|
|
16
|
+
schema = schemas.load(schema_name)
|
|
17
|
+
return validator.validate(data, schema)
|
|
18
|
+
|
|
19
|
+
return func
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture
|
|
23
|
+
def schema_validate_string() -> types.StrValidator:
|
|
24
|
+
"""Validate a string againstt a known JSON Schema."""
|
|
25
|
+
|
|
26
|
+
def func(data: str, schema_name: str, file_type: str = "") -> bool:
|
|
27
|
+
"""Validate a string against a known JSON Schema."""
|
|
28
|
+
parsed = loaders.data_from_string(data, file_type=file_type)
|
|
29
|
+
schema = schemas.load(schema_name)
|
|
30
|
+
return validator.validate(parsed, schema)
|
|
31
|
+
|
|
32
|
+
return func
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.fixture
|
|
36
|
+
def schema_validate() -> types.Validator:
|
|
37
|
+
"""Validate a string againstt a known JSON Schema."""
|
|
38
|
+
|
|
39
|
+
def func(data: types.DataStructure, schema_name: str) -> bool:
|
|
40
|
+
"""Validate a file against a known JSON Schema."""
|
|
41
|
+
schema = schemas.load(schema_name)
|
|
42
|
+
return validator.validate(data, schema)
|
|
43
|
+
|
|
44
|
+
return func
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from . import types
|
|
2
|
+
from collections.abc import Callable
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from ruamel.yaml import YAML
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
if sys.version_info >= (3, 12):
|
|
11
|
+
import tomllib
|
|
12
|
+
else:
|
|
13
|
+
import tomli as tomllib
|
|
14
|
+
|
|
15
|
+
yaml = YAML()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
_FILETYPES: dict[str, str] = {
|
|
19
|
+
".json": "json",
|
|
20
|
+
".toml": "toml",
|
|
21
|
+
".yaml": "yaml",
|
|
22
|
+
".yml": "yaml",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
_LOADERS: dict[str, Callable] = {
|
|
26
|
+
"json": json.loads,
|
|
27
|
+
"toml": tomllib.loads,
|
|
28
|
+
"yaml": yaml.load,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _guess_format(path: Path) -> str:
|
|
33
|
+
"""Given a path, try to guess the correct filetype."""
|
|
34
|
+
extension = path.suffix
|
|
35
|
+
return _FILETYPES.get(extension, "")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def data_from_file(path: types.StrPath, file_type: str = "") -> dict | list:
|
|
39
|
+
"""Load data from file."""
|
|
40
|
+
path = Path(path)
|
|
41
|
+
if file_type not in _LOADERS:
|
|
42
|
+
file_type = _guess_format(path)
|
|
43
|
+
data = path.read_text()
|
|
44
|
+
return data_from_string(data, file_type)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def data_from_string(data: str, file_type: str) -> dict:
|
|
48
|
+
"""Load data from string."""
|
|
49
|
+
loader = _LOADERS.get(file_type)
|
|
50
|
+
return loader(data) if loader else {}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/vars.json",
|
|
3
|
+
"$schema": "http://json-schema.org/draft-07/schema",
|
|
4
|
+
"anyOf": [
|
|
5
|
+
{
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"patternProperties": {
|
|
8
|
+
"^(?!(False|None|True|and|any_errors_fatal|as|assert|async|await|become|become_exe|become_flags|become_method|become_user|break|check_mode|class|collections|connection|continue|debugger|def|del|diff|elif|else|environment|except|fact_path|finally|for|force_handlers|from|gather_facts|gather_subset|gather_timeout|global|handlers|hosts|if|ignore_errors|ignore_unreachable|import|in|is|lambda|max_fail_percentage|module_defaults|name|no_log|nonlocal|not|or|order|pass|port|post_tasks|pre_tasks|raise|remote_user|return|roles|run_once|serial|strategy|tags|tasks|throttle|timeout|try|vars|vars_files|vars_prompt|while|with|yield)$)[a-zA-Z_][\\w]*$": {}
|
|
9
|
+
},
|
|
10
|
+
"type": "object"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"pattern": "^\\$ANSIBLE_VAULT;",
|
|
14
|
+
"type": "string"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"type": "null"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"description": "https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html",
|
|
21
|
+
"examples": [
|
|
22
|
+
"playbooks/vars/*.yml",
|
|
23
|
+
"vars/*.yml",
|
|
24
|
+
"defaults/*.yml",
|
|
25
|
+
"host_vars/*.yml",
|
|
26
|
+
"group_vars/*.yml"
|
|
27
|
+
],
|
|
28
|
+
"markdownDescription": "See [Using Variables](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html)",
|
|
29
|
+
"title": "Ansible Vars Schema"
|
|
30
|
+
}
|