Debian Codegraph @

tests/spec/unit/driver/test_json_stream_trace_stdout.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_stream_trace_stdout():
8 here = Path(__file__).resolve().parent
9 assert isinstance(default_driver, Driver)
10 model_file = here / "test_json_stream_trace_stdout.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 traces = [m for m in messages if m["type"] == "trace"]
20 assert len(traces) == 1
21 assert traces[0] == {"type": "trace", "section": "default", "message": "trace"}
22 solution = next(m for m in messages if m["type"] == "solution")
23 expected = {
24 "type": "solution",
25 "output": {"default": "output", "raw": "output"},
26 "sections": ["default", "raw"],
27 }
28 assert solution == expected