Skip to content

Commit a8bdf57

Browse files
Merge pull request #72 from open-sciencelab/copilot/add-test-for-vqa-generation
Add test for VQA generation
2 parents 97cdde3 + 11d7bb9 commit a8bdf57

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import json
2+
import os
3+
import subprocess
4+
from pathlib import Path
5+
6+
7+
def test_generate_vqa(tmp_path: Path):
8+
repo_root = Path(__file__).resolve().parents[2]
9+
os.chdir(repo_root)
10+
11+
config_path = repo_root / "graphgen" / "configs" / "vqa_config.yaml"
12+
output_dir = tmp_path / "output"
13+
output_dir.mkdir(parents=True, exist_ok=True)
14+
15+
result = subprocess.run(
16+
[
17+
"python",
18+
"-m",
19+
"graphgen.generate",
20+
"--config_file",
21+
str(config_path),
22+
"--output_dir",
23+
str(output_dir),
24+
],
25+
capture_output=True,
26+
text=True,
27+
check=False,
28+
)
29+
assert result.returncode == 0, f"Script failed with error: {result.stderr}"
30+
31+
data_root = output_dir / "data" / "graphgen"
32+
assert data_root.exists(), f"{data_root} does not exist"
33+
run_folders = sorted(data_root.iterdir(), key=lambda p: p.name, reverse=True)
34+
assert run_folders, f"No run folders found in {data_root}"
35+
run_folder = run_folders[0]
36+
37+
config_saved = run_folder / "config.yaml"
38+
assert config_saved.exists(), f"{config_saved} not found"
39+
40+
json_files = list(run_folder.glob("*.json"))
41+
assert json_files, f"No JSON output found in {run_folder}"
42+
43+
log_files = list(run_folder.glob("*.log"))
44+
assert log_files, "No log file generated"
45+
46+
with open(json_files[0], "r", encoding="utf-8") as f:
47+
data = json.load(f)
48+
assert (
49+
isinstance(data, list) and len(data) > 0
50+
), "JSON output is empty or not a list"

0 commit comments

Comments
 (0)