Debian Codegraph @

tests/spec/unit/driver/test_json_section.py

raw
1 from pathlib import Path
2 from minizinc import default_driver, Driver
3 import subprocess
4 import json
5
6
7 def test_json_section():
8 here = Path(__file__).resolve().parent
9 assert isinstance(default_driver, Driver)
10 model_file = here / "test_json_section.mzn"
11 p = subprocess.run(
12 [default_driver._executable, model_file, "--json-stream"],
13 stdin=None,
14 stdout=subprocess.PIPE,
15 stderr=subprocess.PIPE,
16 )
17 assert p.returncode == 0
18 messages = [json.loads(l) for l in p.stdout.splitlines(False)]
19 solution = next(m for m in messages if m["type"] == "solution")
20 expected = {
21 "type": "solution",
22 "output": {
23 "foo": {"a": 1, "b": [2, 3], "c": None},
24 "raw": '{"a": 1, "b": [2, 3], "c": null}\n',
25 "dzn": "",
26 },
27 "sections": ["foo", "raw", "dzn"],
28 }
29 assert solution == expected