| 1 |
from pathlib import Path |
| 2 |
from minizinc import default_driver, Driver |
| 3 |
import subprocess |
| 4 |
import json |
| 5 |
|
| 6 |
|
| 7 |
def test_model_interface_only_1(): |
| 8 |
assert isinstance(default_driver, Driver) |
| 9 |
p = subprocess.Popen( |
| 10 |
[default_driver._executable, "-", "--model-interface-only",], |
| 11 |
stdin=subprocess.PIPE, |
| 12 |
stdout=subprocess.PIPE, |
| 13 |
stderr=subprocess.PIPE, |
| 14 |
) |
| 15 |
stdout, stderr = p.communicate( |
| 16 |
input=b'int: n; var 1..3: x; solve minimize x; output ["foo"];' |
| 17 |
) |
| 18 |
assert p.returncode == 0 |
| 19 |
interface = json.loads(stdout) |
| 20 |
assert interface == { |
| 21 |
"type": "interface", |
| 22 |
"input": {"n": {"type": "int"}}, |
| 23 |
"output": {"x": {"type": "int"}}, |
| 24 |
"method": "min", |
| 25 |
"has_output_item": True, |
| 26 |
"included_files": [], |
| 27 |
"globals": [], |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
def test_model_interface_only_2(): |
| 32 |
assert isinstance(default_driver, Driver) |
| 33 |
p = subprocess.Popen( |
| 34 |
[default_driver._executable, "-", "--model-interface-only"], |
| 35 |
stdin=subprocess.PIPE, |
| 36 |
stdout=subprocess.PIPE, |
| 37 |
stderr=subprocess.PIPE, |
| 38 |
) |
| 39 |
stdout, stderr = p.communicate(input=b"int: n; var 1..3: x; solve maximize x;") |
| 40 |
assert p.returncode == 0 |
| 41 |
interface = json.loads(stdout) |
| 42 |
assert interface == { |
| 43 |
"type": "interface", |
| 44 |
"input": {"n": {"type": "int"}}, |
| 45 |
"output": {"x": {"type": "int"}}, |
| 46 |
"method": "max", |
| 47 |
"has_output_item": False, |
| 48 |
"included_files": [], |
| 49 |
"globals": [], |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
def test_model_interface_only_3(): |
| 54 |
assert isinstance(default_driver, Driver) |
| 55 |
p = subprocess.Popen( |
| 56 |
[default_driver._executable, "-", "--model-interface-only"], |
| 57 |
stdin=subprocess.PIPE, |
| 58 |
stdout=subprocess.PIPE, |
| 59 |
stderr=subprocess.PIPE, |
| 60 |
) |
| 61 |
stdout, stderr = p.communicate( |
| 62 |
input=b'float: n; var set of 1..3: x; output ["foo"];' |
| 63 |
) |
| 64 |
assert p.returncode == 0 |
| 65 |
interface = json.loads(stdout) |
| 66 |
assert interface == { |
| 67 |
"type": "interface", |
| 68 |
"input": {"n": {"type": "float"}}, |
| 69 |
"output": {"x": {"type": "int", "set": True}}, |
| 70 |
"method": "sat", |
| 71 |
"has_output_item": True, |
| 72 |
"included_files": [], |
| 73 |
"globals": [], |
| 74 |
} |