Debian Codegraph @

tests/spec/unit/regression/test_output_checker.py

raw
1 from pathlib import Path
2 from minizinc import Instance, Model, Solver, Status, default_driver, Driver
3 import json
4 from minizinc_testing.utils import temporary_file
5
6
7 def test_output_checker():
8 here = Path(__file__).resolve().parent
9 assert isinstance(default_driver, Driver)
10 model_file = here / "test_output_checker.mzn"
11 checker_file = here / "test_output_checker.mzc.mzn"
12 p = default_driver._run([model_file, checker_file, "--output-mode", "checker"])
13 messages = [json.loads(l) for l in p.stdout.splitlines(False)]
14 solutions = [m for m in messages if m["type"] == "solution"]
15 assert len(solutions) > 0
16 for s in solutions:
17 model = Model(checker_file)
18 instance = Instance(Solver.lookup("gecode"), model)
19 with temporary_file(
20 s["output"]["dzn"], suffix=".dzn"
21 ) as dzn, instance.branch() as child:
22 child.add_file(dzn)
23 solution = child.solve()
24 assert solution.status in [
25 Status.ALL_SOLUTIONS,
26 Status.OPTIMAL_SOLUTION,
27 Status.SATISFIED,
28 ]