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 31
|
from __future__ import annotations
import json
import re
from pathlib import Path
import fastjsonschema
import pytest
import uhi.schema
def test_valid_schemas(valid: Path) -> None:
with valid.open(encoding="utf-8") as f:
data = json.load(f)
uhi.schema.validate(data)
def test_invalid_schemas(invalid: Path) -> None:
with invalid.open(encoding="utf-8") as f:
data = json.load(f)
try:
errmsg = invalid.with_suffix(".error.txt").read_text(encoding="utf-8").strip()
except FileNotFoundError:
errmsg = "NO ERROR MESSAGE FILE FOUND"
with pytest.raises(
fastjsonschema.exceptions.JsonSchemaException, match=re.escape(errmsg)
):
uhi.schema.validate(data)
|