|
5 | 5 |
|
6 | 6 |
|
7 | 7 | def run_generate_test(tmp_path: Path, config_name: str): |
8 | | - """ |
9 | | - Run the generate test with the given configuration file and temporary path. |
10 | | -
|
11 | | - Args: |
12 | | - tmp_path: pytest temporary path |
13 | | - config_name: configuration file name (e.g. "atomic_config.yaml") |
14 | | -
|
15 | | - Returns: |
16 | | - tuple: (run_folder, json_files[0]) |
17 | | - """ |
18 | 8 | repo_root = Path(__file__).resolve().parents[2] |
19 | 9 | os.chdir(repo_root) |
20 | 10 |
|
21 | | - config_path = repo_root / "graphgen" / "configs" / config_name |
22 | | - output_dir = tmp_path / "output" |
23 | | - output_dir.mkdir(parents=True, exist_ok=True) |
| 11 | + config_path = repo_root / config_name |
24 | 12 |
|
25 | 13 | result = subprocess.run( |
26 | 14 | [ |
27 | 15 | "python", |
28 | 16 | "-m", |
29 | | - "graphgen.generate", |
| 17 | + "graphgen.run", |
30 | 18 | "--config_file", |
31 | 19 | str(config_path), |
32 | | - "--output_dir", |
33 | | - str(output_dir), |
34 | 20 | ], |
35 | 21 | capture_output=True, |
36 | 22 | text=True, |
37 | 23 | check=False, |
38 | 24 | ) |
39 | 25 | assert result.returncode == 0, f"Script failed with error: {result.stderr}" |
40 | 26 |
|
41 | | - data_root = output_dir / "data" / "graphgen" |
42 | | - assert data_root.exists(), f"{data_root} does not exist" |
43 | | - run_folders = sorted(data_root.iterdir(), key=lambda p: p.name, reverse=True) |
44 | | - assert run_folders, f"No run folders found in {data_root}" |
| 27 | + run_root = repo_root / "cache" / "output" |
| 28 | + assert run_root.exists(), f"{run_root} does not exist" |
| 29 | + run_folders = sorted( |
| 30 | + [p for p in run_root.iterdir() if p.is_dir()], key=lambda p: p.name, reverse=True |
| 31 | + ) |
| 32 | + assert run_folders, f"No run folders found in {run_root}" |
45 | 33 | run_folder = run_folders[0] |
46 | 34 |
|
47 | | - config_saved = run_folder / "config.yaml" |
48 | | - assert config_saved.exists(), f"{config_saved} not found" |
| 35 | + node_dirs = [p for p in run_folder.iterdir() if p.is_dir()] |
| 36 | + assert node_dirs, f"No node outputs found in {run_folder}" |
49 | 37 |
|
50 | | - json_files = list(run_folder.glob("*.json")) |
51 | | - assert json_files, f"No JSON output found in {run_folder}" |
| 38 | + json_files = [] |
| 39 | + for nd in node_dirs: |
| 40 | + json_files.extend(nd.glob("*.jsonl")) |
| 41 | + assert json_files, f"No JSONL output found under nodes in {run_folder}" |
52 | 42 |
|
53 | | - log_files = list(run_folder.glob("*.log")) |
54 | | - assert log_files, "No log file generated" |
| 43 | + log_file = repo_root / "cache" / "logs" / "Driver.log" |
| 44 | + assert log_file.exists(), "No log file generated" |
55 | 45 |
|
56 | 46 | with open(json_files[0], "r", encoding="utf-8") as f: |
57 | | - data = json.load(f) |
58 | | - assert ( |
59 | | - isinstance(data, list) and len(data) > 0 |
60 | | - ), "JSON output is empty or not a list" |
| 47 | + first_line = f.readline().strip() |
| 48 | + assert first_line, "JSONL output is empty" |
| 49 | + data = json.loads(first_line) |
| 50 | + assert isinstance(data, dict), "First JSONL record is not a dict" |
61 | 51 |
|
62 | 52 | return run_folder, json_files[0] |
63 | | - |
0 commit comments