Skip to content

Commit 03fc8d2

Browse files
committed
Test dumper when running the examples
1 parent b3349d9 commit 03fc8d2

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

tests/test_dump.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import pathlib
22

3+
from pdl.pdl_ast import BlockType, IncludeBlock
34
from pdl.pdl_ast_utils import iter_block_children
45
from pdl.pdl_dumper import dump_yaml, program_to_dict
56
from pdl.pdl_parser import PDLParseError, parse_file, parse_str
6-
from pdl.pdl_ast import BlockType, IncludeBlock
7+
78

89
def has_include(block: BlockType) -> bool:
910
if isinstance(block, IncludeBlock):
1011
return True
11-
else:
12-
b = False
13-
def f(x):
14-
nonlocal b
15-
if has_include(x):
16-
b = True
17-
iter_block_children(f,block)
18-
return b
12+
b = False
13+
14+
def f(x):
15+
nonlocal b
16+
if has_include(x):
17+
b = True
18+
19+
iter_block_children(f, block)
20+
return b
21+
1922

2023
def test_ast_iterators() -> None:
2124
for yaml_file_name in pathlib.Path(".").glob("**/*.pdl"):
@@ -28,8 +31,6 @@ def test_ast_iterators() -> None:
2831
ast2, _ = parse_str(s)
2932
json1 = ast1.model_dump_json()
3033
json2 = ast2.model_dump_json()
31-
if str(yaml_file_name) == "examples/talk/7-chatbot-roles.pdl":
32-
pass
3334
assert json1 == json2, yaml_file_name
3435
except PDLParseError:
3536
pass

tests/test_examples_run.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from pdl import pdl
1010
from pdl.pdl_ast import ScopeType
11+
from pdl.pdl_dumper import block_to_dict
1112
from pdl.pdl_interpreter import PDLRuntimeError
1213
from pdl.pdl_parser import PDLParseError
1314

@@ -169,7 +170,9 @@ def test_valid_programs(capsys: CaptureFixture[str], monkeypatch: MonkeyPatch) -
169170
scope = inputs.scope
170171
try:
171172
random.seed(11)
172-
result = pdl.exec_file(pdl_file_name, scope=scope)
173+
output = pdl.exec_file(pdl_file_name, scope=scope, output="all")
174+
result = output["result"]
175+
block_to_dict(output["trace"], json_compatible=True)
173176
result_dir_name = (
174177
pathlib.Path(".") / "tests" / "results" / pdl_file_name.parent
175178
)

0 commit comments

Comments
 (0)