-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_example07_lowering.py
More file actions
50 lines (40 loc) · 1.69 KB
/
test_example07_lowering.py
File metadata and controls
50 lines (40 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from __future__ import annotations
import json
import subprocess
import sys
from pathlib import Path
from Implementations.Reference.Lowerer.fir_lowerer import load_json, lower_fir_artifact
ROOT = Path(__file__).resolve().parents[4]
LOWERER = ROOT / "Implementations" / "Reference" / "Lowerer" / "lower_fir.py"
FIR = ROOT / "Examples" / "07_string_value_roundtrip" / "main.fir.json"
EXPECTED = ROOT / "Examples" / "07_string_value_roundtrip" / "main.lowering.json"
def test_example07_lowerer_check_passes() -> None:
result = subprocess.run(
[sys.executable, str(LOWERER), "--fir", str(FIR), "--expected", str(EXPECTED), "--check"],
cwd=ROOT,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=False,
)
assert result.returncode == 0, result.stdout + result.stderr
assert "Lowering check: ok" in result.stdout
def test_example07_lowerer_writes_json(tmp_path: Path) -> None:
output = tmp_path / "main.generated.lowering.json"
result = subprocess.run(
[sys.executable, str(LOWERER), "--fir", str(FIR), "--output", str(output)],
cwd=ROOT,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=False,
)
assert result.returncode == 0, result.stdout + result.stderr
generated = json.loads(output.read_text(encoding="utf-8"))
expected = json.loads(EXPECTED.read_text(encoding="utf-8"))
assert generated == expected
def test_example07_rule_module_lowers_expected_artifact() -> None:
fir = load_json(FIR)
generated = lower_fir_artifact(fir, "Examples/07_string_value_roundtrip/main.fir.json")
expected = load_json(EXPECTED)
assert generated == expected