File: test_json_schema_summary.py

package info (click to toggle)
python-validate-pyproject 0.24.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,340 kB
  • sloc: python: 3,053; makefile: 46; sh: 25
file content (30 lines) | stat: -rw-r--r-- 847 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Test summary generation from schema examples"""

import json
from pathlib import Path

import pytest

from validate_pyproject.error_reporting import _SummaryWriter

EXAMPLE_FOLDER = Path(__file__).parent / "json_schema_summary"
EXAMPLES = (p.name for p in EXAMPLE_FOLDER.glob("*"))


def load_example(file):
    text = file.read_text(encoding="utf-8")
    schema, _, summary = text.partition("# - # - # - #\n")

    # # Auto fix examples:
    # fixed = _SummaryWriter()(json.loads(schema))
    # file.write_text(text.replace(summary, fixed), encoding="utf-8")

    return json.loads(schema), summary


@pytest.mark.parametrize("example", EXAMPLES)
def test_summary_generation(example):
    schema, expected = load_example(EXAMPLE_FOLDER / example)
    summarize = _SummaryWriter()
    summary = summarize(schema)
    assert summary == expected