Files

42 lines
1.2 KiB
Python

from __future__ import annotations
import json
import tempfile
import unittest
from pathlib import Path
from techviz.spec import load_spec
ROOT = Path(__file__).resolve().parents[1]
class SpecParsingTests(unittest.TestCase):
def setUp(self) -> None:
self.data = json.loads((ROOT / "examples/work/payment/spec.json").read_text(encoding="utf-8"))
def _write(self, data: dict) -> Path:
self.temp = tempfile.TemporaryDirectory()
path = Path(self.temp.name) / "spec.json"
path.write_text(json.dumps(data, ensure_ascii=False), encoding="utf-8")
return path
def tearDown(self) -> None:
temp = getattr(self, "temp", None)
if temp is not None:
temp.cleanup()
def test_boolean_fields_are_not_coerced_from_strings(self) -> None:
self.data["nodes"][0]["assumption"] = "false"
with self.assertRaisesRegex(ValueError, "expected boolean"):
load_spec(self._write(self.data))
def test_unknown_model_output_fields_are_rejected(self) -> None:
self.data["nodes"][0]["visual_magic"] = "glow"
with self.assertRaisesRegex(ValueError, "unknown field"):
load_spec(self._write(self.data))
if __name__ == "__main__":
unittest.main()