pytest-jsonschema-snapshot 0.2.2__tar.gz → 0.2.4__tar.gz
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_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/PKG-INFO +2 -1
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/README.md +1 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/pytest_jsonschema_snapshot/__init__.py +1 -1
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/pytest_jsonschema_snapshot/core.py +15 -12
- pytest_jsonschema_snapshot-0.2.4/pytest_jsonschema_snapshot/stats.py +225 -0
- pytest_jsonschema_snapshot-0.2.2/pytest_jsonschema_snapshot/stats.py +0 -185
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/.flake8 +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/.github/ISSUE_TEMPLATE/documentation_issue.yml +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/.github/PULL_REQUEST_TEMPLATE/general.md +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/.github/actions/build-docs/action.yml +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/.github/workflows/release.yml +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/.github/workflows/reusable-test.yml +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/.github/workflows/test.yml +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/.gitignore +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/LICENSE +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/Makefile +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/assets/logo.png +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/docs/source/_static/logo_day.png +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/docs/source/_static/logo_night.png +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/docs/source/basic/quick_start.rst +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/docs/source/conf.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/docs/source/index.rst +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/pyproject.toml +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/pytest_jsonschema_snapshot/plugin.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/pytest_jsonschema_snapshot/py.typed +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/pytest_jsonschema_snapshot/tools/__init__.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/pytest_jsonschema_snapshot/tools/genson_addon/__init__.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/pytest_jsonschema_snapshot/tools/genson_addon/format_detector.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/pytest_jsonschema_snapshot/tools/genson_addon/to_schema_converter.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/pytest_jsonschema_snapshot/tools/name_maker.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/reinstall_plugin.sh +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/requirements.txt +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/test_stats.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/tools/genson_addon/test_format_safe.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/tools/test_name_maker.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/TestDataClass.get_data.first.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/TestDataClass.get_data.first.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/TestDataClass.get_data.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/TestDataClass.get_data.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/array_formats_test.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/array_formats_test.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/date_test.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/date_test.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/datetime_test.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/datetime_test.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/email_test.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/email_test.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/get_data.first.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/get_data.first.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/get_data.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/get_data.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/ipv4_test.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/ipv4_test.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/mixed_formats_test.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/mixed_formats_test.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/multi_schema_one.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/multi_schema_three.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/multi_schema_two.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/regular_strings_test.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/regular_strings_test.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/some_schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/some_schema.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/strict_email_validation_test.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/strict_email_validation_test.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/uri_test.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/uri_test.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/uuid_test.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/__snapshots__/uuid_test.schema.json +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/test_base.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/test_base_name_callable.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/test_format_detection.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/test_format_validation.py +0 -0
- {pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/test_multiple_schema_creation.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pytest-jsonschema-snapshot
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Pytest plugin for automatic JSON Schema generation and validation from examples
|
|
5
5
|
Project-URL: Homepage, https://miskler.github.io/pytest-jsonschema-snapshot/basic/quick_start.html
|
|
6
6
|
Project-URL: Repository, https://github.com/Miskler/pytest-jsonschema-snapshot
|
|
@@ -58,6 +58,7 @@ Description-Content-Type: text/markdown
|
|
|
58
58
|
[](https://pypi.org/project/pytest-jsonschema-snapshot/)
|
|
59
59
|
[](LICENSE)
|
|
60
60
|
[](https://github.com/psf/black)
|
|
61
|
+
[](https://pycqa.github.io/isort/)
|
|
61
62
|
[](https://mypy.readthedocs.io/en/stable/index.html)
|
|
62
63
|
[](https://discord.gg/UnJnGHNbBp)
|
|
63
64
|
[](https://t.me/miskler_dev)
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
[](https://pypi.org/project/pytest-jsonschema-snapshot/)
|
|
14
14
|
[](LICENSE)
|
|
15
15
|
[](https://github.com/psf/black)
|
|
16
|
+
[](https://pycqa.github.io/isort/)
|
|
16
17
|
[](https://mypy.readthedocs.io/en/stable/index.html)
|
|
17
18
|
[](https://discord.gg/UnJnGHNbBp)
|
|
18
19
|
[](https://t.me/miskler_dev)
|
|
@@ -233,6 +233,14 @@ class SchemaShot:
|
|
|
233
233
|
# --- схема уже была: сравнение и валидация --------------------------------
|
|
234
234
|
schema_updated = False
|
|
235
235
|
|
|
236
|
+
def merge_schemas(old: dict, new: dict) -> dict:
|
|
237
|
+
builder = JsonToSchemaConverter(
|
|
238
|
+
format_mode=self.format_mode # type: ignore[arg-type]
|
|
239
|
+
) # , examples=self.examples_limit)
|
|
240
|
+
builder.add_schema(old)
|
|
241
|
+
builder.add_schema(new)
|
|
242
|
+
return builder.to_schema()
|
|
243
|
+
|
|
236
244
|
if existing_schema != current_schema: # есть отличия
|
|
237
245
|
if (self.update_mode or self.reset_mode) and self.update_actions.get("update"):
|
|
238
246
|
# обновляем файл
|
|
@@ -246,12 +254,7 @@ class SchemaShot:
|
|
|
246
254
|
json.dump(current_schema, f, indent=2, ensure_ascii=False)
|
|
247
255
|
self.logger.warning(f"Schema `{name}` updated (reset).\n\n{differences}")
|
|
248
256
|
elif self.update_mode and not self.reset_mode:
|
|
249
|
-
|
|
250
|
-
format_mode=self.format_mode # type: ignore[arg-type]
|
|
251
|
-
) # , examples=self.examples_limit)
|
|
252
|
-
builder.add_schema(existing_schema)
|
|
253
|
-
builder.add_schema(current_schema)
|
|
254
|
-
merged_schema = builder.to_schema()
|
|
257
|
+
merged_schema = merge_schemas(existing_schema, current_schema)
|
|
255
258
|
|
|
256
259
|
differences = self.differ.compare(
|
|
257
260
|
dict(existing_schema), merged_schema
|
|
@@ -268,9 +271,9 @@ class SchemaShot:
|
|
|
268
271
|
)
|
|
269
272
|
schema_updated = True
|
|
270
273
|
elif data is not None:
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
).render()
|
|
274
|
+
merged_schema = merge_schemas(existing_schema, current_schema)
|
|
275
|
+
|
|
276
|
+
differences = self.differ.compare(dict(existing_schema), merged_schema).render()
|
|
274
277
|
GLOBAL_STATS.add_uncommitted(schema_path.name, differences)
|
|
275
278
|
|
|
276
279
|
# только валидируем по старой схеме
|
|
@@ -293,9 +296,9 @@ class SchemaShot:
|
|
|
293
296
|
format_checker=FormatChecker(),
|
|
294
297
|
)
|
|
295
298
|
except ValidationError as e:
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
).render()
|
|
299
|
+
merged_schema = merge_schemas(existing_schema, current_schema)
|
|
300
|
+
|
|
301
|
+
differences = self.differ.compare(dict(existing_schema), merged_schema).render()
|
|
299
302
|
pytest.fail(f"\n\n{differences}\n\nValidation error in `{name}`: {e.message}")
|
|
300
303
|
|
|
301
304
|
return name, schema_updated
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Module for collecting and displaying statistics about schemas.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import Dict, Generator, List, Optional
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SchemaStats:
|
|
11
|
+
"""Class for collecting and displaying statistics about schemas"""
|
|
12
|
+
|
|
13
|
+
def __init__(self) -> None:
|
|
14
|
+
self.created: List[str] = []
|
|
15
|
+
self.updated: List[str] = []
|
|
16
|
+
self.updated_diffs: Dict[str, str] = {} # schema_name -> diff
|
|
17
|
+
self.uncommitted: List[str] = [] # New category for uncommitted changes
|
|
18
|
+
self.uncommitted_diffs: Dict[str, str] = {} # schema_name -> diff
|
|
19
|
+
self.deleted: List[str] = []
|
|
20
|
+
self.unused: List[str] = []
|
|
21
|
+
|
|
22
|
+
def add_created(self, schema_name: str) -> None:
|
|
23
|
+
"""Adds created schema"""
|
|
24
|
+
self.created.append(schema_name)
|
|
25
|
+
|
|
26
|
+
def add_updated(self, schema_name: str, diff: Optional[str] = None) -> None:
|
|
27
|
+
"""Adds updated schema"""
|
|
28
|
+
# Generate diff if both schemas are provided
|
|
29
|
+
if diff and diff.strip():
|
|
30
|
+
self.updated.append(schema_name)
|
|
31
|
+
self.updated_diffs[schema_name] = diff
|
|
32
|
+
else:
|
|
33
|
+
# If schemas are not provided, assume it was an update
|
|
34
|
+
self.updated.append(schema_name)
|
|
35
|
+
|
|
36
|
+
def add_uncommitted(self, schema_name: str, diff: Optional[str] = None) -> None:
|
|
37
|
+
"""Adds schema with uncommitted changes"""
|
|
38
|
+
# Add only if there are real changes
|
|
39
|
+
if diff and diff.strip():
|
|
40
|
+
self.uncommitted.append(schema_name)
|
|
41
|
+
self.uncommitted_diffs[schema_name] = diff
|
|
42
|
+
|
|
43
|
+
def add_deleted(self, schema_name: str) -> None:
|
|
44
|
+
"""Adds deleted schema"""
|
|
45
|
+
self.deleted.append(schema_name)
|
|
46
|
+
|
|
47
|
+
def add_unused(self, schema_name: str) -> None:
|
|
48
|
+
"""Adds unused schema"""
|
|
49
|
+
self.unused.append(schema_name)
|
|
50
|
+
|
|
51
|
+
def has_changes(self) -> bool:
|
|
52
|
+
"""Returns True if any schema has changes"""
|
|
53
|
+
return bool(self.created or self.updated or self.deleted)
|
|
54
|
+
|
|
55
|
+
def has_any_info(self) -> bool:
|
|
56
|
+
"""Is there any information about schemas"""
|
|
57
|
+
return bool(self.created or self.updated or self.deleted or self.unused or self.uncommitted)
|
|
58
|
+
|
|
59
|
+
def __str__(self) -> str:
|
|
60
|
+
parts = []
|
|
61
|
+
if self.created:
|
|
62
|
+
parts.append(
|
|
63
|
+
f"Created schemas ({len(self.created)}): "
|
|
64
|
+
+ ", ".join(f"`{s}`" for s in self.created)
|
|
65
|
+
)
|
|
66
|
+
if self.updated:
|
|
67
|
+
parts.append(
|
|
68
|
+
f"Updated schemas ({len(self.updated)}): "
|
|
69
|
+
+ ", ".join(f"`{s}`" for s in self.updated)
|
|
70
|
+
)
|
|
71
|
+
if self.deleted:
|
|
72
|
+
parts.append(
|
|
73
|
+
f"Deleted schemas ({len(self.deleted)}): "
|
|
74
|
+
+ ", ".join(f"`{s}`" for s in self.deleted)
|
|
75
|
+
)
|
|
76
|
+
if self.unused:
|
|
77
|
+
parts.append(
|
|
78
|
+
f"Unused schemas ({len(self.unused)}): " + ", ".join(f"`{s}`" for s in self.unused)
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
return "\n".join(parts)
|
|
82
|
+
|
|
83
|
+
def _iter_schemas(self, names: List[str]) -> Generator[tuple[str, Optional[str]], None, None]:
|
|
84
|
+
"""
|
|
85
|
+
Iterates over schema displays: (display, schema_key)
|
|
86
|
+
- display: string to display (may have " + original")
|
|
87
|
+
- schema_key: file name of the schema (<name>.schema.json) to find diffs,
|
|
88
|
+
or None if it's not a schema.
|
|
89
|
+
Preserves the original list order: merging happens at .schema.json
|
|
90
|
+
position; skips .json if paired with schema.
|
|
91
|
+
"""
|
|
92
|
+
names = list(names) # order matters
|
|
93
|
+
schema_sfx = ".schema.json"
|
|
94
|
+
json_sfx = ".json"
|
|
95
|
+
|
|
96
|
+
# sets of bases
|
|
97
|
+
# bases_with_schema = {n[: -len(schema_sfx)] for n in names if n.endswith(schema_sfx)}
|
|
98
|
+
bases_with_original = {
|
|
99
|
+
n[: -len(json_sfx)]
|
|
100
|
+
for n in names
|
|
101
|
+
if n.endswith(json_sfx) and not n.endswith(schema_sfx)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
for n in names:
|
|
105
|
+
if n.endswith(schema_sfx):
|
|
106
|
+
base = n[: -len(schema_sfx)]
|
|
107
|
+
if base in bases_with_original:
|
|
108
|
+
yield f"{n} + original", n # display, schema_key
|
|
109
|
+
else:
|
|
110
|
+
yield n, n
|
|
111
|
+
# if .json, skip if paired
|
|
112
|
+
# if other, yield n, n (but assume all are .json or .schema.json)
|
|
113
|
+
|
|
114
|
+
def _iter_only_originals(self, names: List[str]) -> Generator[str, None, None]:
|
|
115
|
+
"""
|
|
116
|
+
Iterates over only unpaired .json files, in the order they appear.
|
|
117
|
+
"""
|
|
118
|
+
names = list(names) # order matters
|
|
119
|
+
schema_sfx = ".schema.json"
|
|
120
|
+
json_sfx = ".json"
|
|
121
|
+
|
|
122
|
+
bases_with_schema = {n[: -len(schema_sfx)] for n in names if n.endswith(schema_sfx)}
|
|
123
|
+
|
|
124
|
+
for n in names:
|
|
125
|
+
if n.endswith(json_sfx) and not n.endswith(schema_sfx):
|
|
126
|
+
base = n[: -len(json_sfx)]
|
|
127
|
+
if base not in bases_with_schema:
|
|
128
|
+
yield n
|
|
129
|
+
|
|
130
|
+
def print_summary(self, terminalreporter: pytest.TerminalReporter, update_mode: bool) -> None:
|
|
131
|
+
"""
|
|
132
|
+
Prints schema summary to pytest terminal output.
|
|
133
|
+
Pairs of "<name>.schema.json" + "<name>.json" are merged into one line:
|
|
134
|
+
"<name>.schema.json + original" (if original is present).
|
|
135
|
+
Unpaired .json are shown in separate "only originals" sections.
|
|
136
|
+
"""
|
|
137
|
+
|
|
138
|
+
if not self.has_any_info():
|
|
139
|
+
return
|
|
140
|
+
|
|
141
|
+
terminalreporter.write_sep("=", "Schema Summary")
|
|
142
|
+
|
|
143
|
+
# Created
|
|
144
|
+
if self.created:
|
|
145
|
+
schemas = list(self._iter_schemas(self.created))
|
|
146
|
+
only_originals = list(self._iter_only_originals(self.created))
|
|
147
|
+
if schemas:
|
|
148
|
+
terminalreporter.write_line(f"Created schemas ({len(schemas)}):", green=True)
|
|
149
|
+
for display, _key in schemas:
|
|
150
|
+
terminalreporter.write_line(f" - {display}", green=True)
|
|
151
|
+
if only_originals:
|
|
152
|
+
terminalreporter.write_line(
|
|
153
|
+
f"Created only originals ({len(only_originals)}):", green=True
|
|
154
|
+
)
|
|
155
|
+
for display in only_originals:
|
|
156
|
+
terminalreporter.write_line(f" - {display}", green=True)
|
|
157
|
+
|
|
158
|
+
# Updated
|
|
159
|
+
if self.updated:
|
|
160
|
+
schemas = list(self._iter_schemas(self.updated))
|
|
161
|
+
only_originals = list(self._iter_only_originals(self.updated))
|
|
162
|
+
if schemas:
|
|
163
|
+
terminalreporter.write_line(f"Updated schemas ({len(schemas)}):", yellow=True)
|
|
164
|
+
for display, key in schemas:
|
|
165
|
+
terminalreporter.write_line(f" - {display}", yellow=True)
|
|
166
|
+
# Show diff if available for schema
|
|
167
|
+
if key and key in self.updated_diffs:
|
|
168
|
+
diff = self.updated_diffs[key]
|
|
169
|
+
if diff.strip():
|
|
170
|
+
terminalreporter.write_line(" Changes:", yellow=True)
|
|
171
|
+
for line in diff.split("\n"):
|
|
172
|
+
if line.strip():
|
|
173
|
+
terminalreporter.write_line(f" {line}")
|
|
174
|
+
terminalreporter.write_line("") # separation
|
|
175
|
+
else:
|
|
176
|
+
terminalreporter.write_line(
|
|
177
|
+
" (Schema unchanged - no differences detected)", cyan=True
|
|
178
|
+
)
|
|
179
|
+
if only_originals:
|
|
180
|
+
terminalreporter.write_line(
|
|
181
|
+
f"Updated only originals ({len(only_originals)}):", yellow=True
|
|
182
|
+
)
|
|
183
|
+
for display in only_originals:
|
|
184
|
+
terminalreporter.write_line(f" - {display}", yellow=True)
|
|
185
|
+
|
|
186
|
+
# Uncommitted
|
|
187
|
+
if self.uncommitted:
|
|
188
|
+
terminalreporter.write_line(
|
|
189
|
+
f"Uncommitted minor updates ({len(self.uncommitted)}):", bold=True
|
|
190
|
+
)
|
|
191
|
+
for display, key in self._iter_schemas(self.uncommitted): # assuming mostly schemas
|
|
192
|
+
terminalreporter.write_line(f" - {display}", cyan=True)
|
|
193
|
+
# Show diff if available
|
|
194
|
+
if key and key in self.uncommitted_diffs:
|
|
195
|
+
terminalreporter.write_line(" Detected changes:", cyan=True)
|
|
196
|
+
for line in self.uncommitted_diffs[key].split("\n"):
|
|
197
|
+
if line.strip():
|
|
198
|
+
terminalreporter.write_line(f" {line}")
|
|
199
|
+
terminalreporter.write_line("") # separation
|
|
200
|
+
terminalreporter.write_line("Use --schema-update to commit these changes", cyan=True)
|
|
201
|
+
|
|
202
|
+
# Deleted
|
|
203
|
+
if self.deleted:
|
|
204
|
+
schemas = list(self._iter_schemas(self.deleted))
|
|
205
|
+
only_originals = list(self._iter_only_originals(self.deleted))
|
|
206
|
+
if schemas:
|
|
207
|
+
terminalreporter.write_line(f"Deleted schemas ({len(schemas)}):", red=True)
|
|
208
|
+
for display, _key in schemas:
|
|
209
|
+
terminalreporter.write_line(f" - {display}", red=True)
|
|
210
|
+
if only_originals:
|
|
211
|
+
terminalreporter.write_line(
|
|
212
|
+
f"Deleted only originals ({len(only_originals)}):", red=True
|
|
213
|
+
)
|
|
214
|
+
for display in only_originals:
|
|
215
|
+
terminalreporter.write_line(f" - {display}", red=True)
|
|
216
|
+
|
|
217
|
+
# Unused (only if not update_mode)
|
|
218
|
+
if self.unused and not update_mode:
|
|
219
|
+
terminalreporter.write_line(f"Unused schemas ({len(self.unused)}):")
|
|
220
|
+
for display, _key in self._iter_schemas(self.unused): # assuming schemas
|
|
221
|
+
terminalreporter.write_line(f" - {display}")
|
|
222
|
+
terminalreporter.write_line("Use --schema-update to delete unused schemas", yellow=True)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
GLOBAL_STATS = SchemaStats()
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Module for collecting and displaying statistics about schemas.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from typing import Dict, Generator, List, Optional
|
|
6
|
-
|
|
7
|
-
import pytest
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class SchemaStats:
|
|
11
|
-
"""Class for collecting and displaying statistics about schemas"""
|
|
12
|
-
|
|
13
|
-
def __init__(self) -> None:
|
|
14
|
-
self.created: List[str] = []
|
|
15
|
-
self.updated: List[str] = []
|
|
16
|
-
self.updated_diffs: Dict[str, str] = {} # schema_name -> diff
|
|
17
|
-
self.uncommitted: List[str] = [] # New category for uncommitted changes
|
|
18
|
-
self.uncommitted_diffs: Dict[str, str] = {} # schema_name -> diff
|
|
19
|
-
self.deleted: List[str] = []
|
|
20
|
-
self.unused: List[str] = []
|
|
21
|
-
|
|
22
|
-
def add_created(self, schema_name: str) -> None:
|
|
23
|
-
"""Adds created schema"""
|
|
24
|
-
self.created.append(schema_name)
|
|
25
|
-
|
|
26
|
-
def add_updated(self, schema_name: str, diff: Optional[str] = None) -> None:
|
|
27
|
-
"""Adds updated schema"""
|
|
28
|
-
# Generate diff if both schemas are provided
|
|
29
|
-
if diff and diff.strip():
|
|
30
|
-
self.updated.append(schema_name)
|
|
31
|
-
self.updated_diffs[schema_name] = diff
|
|
32
|
-
else:
|
|
33
|
-
# If schemas are not provided, assume it was an update
|
|
34
|
-
self.updated.append(schema_name)
|
|
35
|
-
|
|
36
|
-
def add_uncommitted(self, schema_name: str, diff: Optional[str] = None) -> None:
|
|
37
|
-
"""Adds schema with uncommitted changes"""
|
|
38
|
-
# Add only if there are real changes
|
|
39
|
-
if diff and diff.strip():
|
|
40
|
-
self.uncommitted.append(schema_name)
|
|
41
|
-
self.uncommitted_diffs[schema_name] = diff
|
|
42
|
-
|
|
43
|
-
def add_deleted(self, schema_name: str) -> None:
|
|
44
|
-
"""Adds deleted schema"""
|
|
45
|
-
self.deleted.append(schema_name)
|
|
46
|
-
|
|
47
|
-
def add_unused(self, schema_name: str) -> None:
|
|
48
|
-
"""Adds unused schema"""
|
|
49
|
-
self.unused.append(schema_name)
|
|
50
|
-
|
|
51
|
-
def has_changes(self) -> bool:
|
|
52
|
-
"""Returns True if any schema has changes"""
|
|
53
|
-
return bool(self.created or self.updated or self.deleted)
|
|
54
|
-
|
|
55
|
-
def has_any_info(self) -> bool:
|
|
56
|
-
"""Is there any information about schemas"""
|
|
57
|
-
return bool(self.created or self.updated or self.deleted or self.unused or self.uncommitted)
|
|
58
|
-
|
|
59
|
-
def __str__(self) -> str:
|
|
60
|
-
parts = []
|
|
61
|
-
if self.created:
|
|
62
|
-
parts.append(
|
|
63
|
-
f"Created schemas ({len(self.created)}): "
|
|
64
|
-
+ ", ".join(f"`{s}`" for s in self.created)
|
|
65
|
-
)
|
|
66
|
-
if self.updated:
|
|
67
|
-
parts.append(
|
|
68
|
-
f"Updated schemas ({len(self.updated)}): "
|
|
69
|
-
+ ", ".join(f"`{s}`" for s in self.updated)
|
|
70
|
-
)
|
|
71
|
-
if self.deleted:
|
|
72
|
-
parts.append(
|
|
73
|
-
f"Deleted schemas ({len(self.deleted)}): "
|
|
74
|
-
+ ", ".join(f"`{s}`" for s in self.deleted)
|
|
75
|
-
)
|
|
76
|
-
if self.unused:
|
|
77
|
-
parts.append(
|
|
78
|
-
f"Unused schemas ({len(self.unused)}): " + ", ".join(f"`{s}`" for s in self.unused)
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
return "\n".join(parts)
|
|
82
|
-
|
|
83
|
-
def print_summary(self, terminalreporter: pytest.TerminalReporter, update_mode: bool) -> None:
|
|
84
|
-
"""
|
|
85
|
-
Prints schema summary to pytest terminal output.
|
|
86
|
-
Pairs of "<name>.schema.json" + "<name>.json" are merged into one line:
|
|
87
|
-
"<name>.schema.json + original" (if original is present).
|
|
88
|
-
"""
|
|
89
|
-
|
|
90
|
-
def _iter_merged(names: List[str]) -> Generator[tuple[str, Optional[str]], None, None]:
|
|
91
|
-
"""
|
|
92
|
-
Iterates over (display, schema_key):
|
|
93
|
-
- display: string to display (may have " + original")
|
|
94
|
-
- schema_key: file name of the schema (<name>.schema.json) to find diffs,
|
|
95
|
-
or None if it's not a schema.
|
|
96
|
-
Preserves the original list order: merging happens at .schema.json
|
|
97
|
-
position; single .json outputs are left as is.
|
|
98
|
-
"""
|
|
99
|
-
names = list(names) # порядок важен
|
|
100
|
-
schema_sfx = ".schema.json"
|
|
101
|
-
json_sfx = ".json"
|
|
102
|
-
|
|
103
|
-
# множество баз, где имеются схемы/оригиналы
|
|
104
|
-
bases_with_schema = {n[: -len(schema_sfx)] for n in names if n.endswith(schema_sfx)}
|
|
105
|
-
bases_with_original = {
|
|
106
|
-
n[: -len(json_sfx)]
|
|
107
|
-
for n in names
|
|
108
|
-
if n.endswith(json_sfx) and not n.endswith(schema_sfx)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
for n in names:
|
|
112
|
-
if n.endswith(schema_sfx):
|
|
113
|
-
base = n[: -len(schema_sfx)]
|
|
114
|
-
if base in bases_with_original:
|
|
115
|
-
yield f"{n} + original", n # display, schema_key
|
|
116
|
-
else:
|
|
117
|
-
yield n, n
|
|
118
|
-
elif n.endswith(json_sfx) and not n.endswith(schema_sfx):
|
|
119
|
-
base = n[: -len(json_sfx)]
|
|
120
|
-
# если есть парная схема — .json не выводим отдельно
|
|
121
|
-
if base in bases_with_schema:
|
|
122
|
-
continue
|
|
123
|
-
yield n, None
|
|
124
|
-
else:
|
|
125
|
-
# на всякий случай — прочие имена
|
|
126
|
-
yield n, n
|
|
127
|
-
|
|
128
|
-
if not self.has_any_info():
|
|
129
|
-
return
|
|
130
|
-
|
|
131
|
-
terminalreporter.write_sep("=", "Schema Summary")
|
|
132
|
-
|
|
133
|
-
# Created
|
|
134
|
-
if self.created:
|
|
135
|
-
terminalreporter.write_line(f"Created schemas ({len(self.created)}):", green=True)
|
|
136
|
-
for display, _key in _iter_merged(self.created):
|
|
137
|
-
terminalreporter.write_line(f" - {display}", green=True)
|
|
138
|
-
|
|
139
|
-
# Updated
|
|
140
|
-
if self.updated:
|
|
141
|
-
terminalreporter.write_line(f"Updated schemas ({len(self.updated)}):", yellow=True)
|
|
142
|
-
for display, key in _iter_merged(self.updated):
|
|
143
|
-
terminalreporter.write_line(f" - {display}", yellow=True)
|
|
144
|
-
# Показываем diff, если он есть под ключом схемы (.schema.json)
|
|
145
|
-
if key and key in self.updated_diffs:
|
|
146
|
-
terminalreporter.write_line(" Changes:", yellow=True)
|
|
147
|
-
for line in self.updated_diffs[key].split("\n"):
|
|
148
|
-
if line.strip():
|
|
149
|
-
terminalreporter.write_line(f" {line}")
|
|
150
|
-
terminalreporter.write_line("") # разделение
|
|
151
|
-
elif key:
|
|
152
|
-
terminalreporter.write_line(
|
|
153
|
-
" (Schema unchanged - no differences detected)", cyan=True
|
|
154
|
-
)
|
|
155
|
-
|
|
156
|
-
# Uncommitted
|
|
157
|
-
if self.uncommitted:
|
|
158
|
-
terminalreporter.write_line(
|
|
159
|
-
f"Uncommitted minor updates ({len(self.uncommitted)}):", bold=True
|
|
160
|
-
)
|
|
161
|
-
for display, key in _iter_merged(self.uncommitted):
|
|
162
|
-
terminalreporter.write_line(f" - {display}", cyan=True)
|
|
163
|
-
if key and key in self.uncommitted_diffs:
|
|
164
|
-
terminalreporter.write_line(" Detected changes:", cyan=True)
|
|
165
|
-
for line in self.uncommitted_diffs[key].split("\n"):
|
|
166
|
-
if line.strip():
|
|
167
|
-
terminalreporter.write_line(f" {line}")
|
|
168
|
-
terminalreporter.write_line("") # разделение
|
|
169
|
-
terminalreporter.write_line("Use --schema-update to commit these changes", cyan=True)
|
|
170
|
-
|
|
171
|
-
# Deleted
|
|
172
|
-
if self.deleted:
|
|
173
|
-
terminalreporter.write_line(f"Deleted schemas ({len(self.deleted)}):", red=True)
|
|
174
|
-
for display, _key in _iter_merged(self.deleted):
|
|
175
|
-
terminalreporter.write_line(f" - {display}", red=True)
|
|
176
|
-
|
|
177
|
-
# Unused (только если не update_mode)
|
|
178
|
-
if self.unused and not update_mode:
|
|
179
|
-
terminalreporter.write_line(f"Unused schemas ({len(self.unused)}):")
|
|
180
|
-
for display, _key in _iter_merged(self.unused):
|
|
181
|
-
terminalreporter.write_line(f" - {display}")
|
|
182
|
-
terminalreporter.write_line("Use --schema-update to delete unused schemas", yellow=True)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
GLOBAL_STATS = SchemaStats()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/.github/workflows/release.yml
RENAMED
|
File without changes
|
|
File without changes
|
{pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/.github/workflows/test.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/tools/test_name_maker.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pytest_jsonschema_snapshot-0.2.2 → pytest_jsonschema_snapshot-0.2.4}/tests/usage/test_base.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|