-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgenerator_flow_test.py
36 lines (22 loc) · 967 Bytes
/
generator_flow_test.py
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
import ast
import json
from pathlib import Path
import astor
import pytest
from json_codegen import load_schema
from json_codegen.generators.flow import FlowGenerator
SCHEMAS_DIR = Path(__file__).parent / "fixtures" / "schemas"
FIXTURES_DIR = Path(__file__).parent / "fixtures" / "flow"
expected_init_py = astor.dump_tree(ast.Module(body=[]))
test_params = sorted(pytest.param(f, id=f.name) for f in SCHEMAS_DIR.glob("*.schema.json"))
def load_fixture(name):
filename = FIXTURES_DIR / (name + ".ast.json")
return astor.parse_file(filename)
@pytest.mark.parametrize("schema_filename", (test_params))
def test_generate(schema_filename):
fixture_filename = FIXTURES_DIR / (schema_filename.name.split(".")[0] + ".ast.json")
schema = load_schema(schema_filename.read_text())
generator = FlowGenerator(schema)
result = generator.generate().as_ast()
expected = json.loads(fixture_filename.read_text())
assert result == expected