Skip to content

Commit 866dc7c

Browse files
Merge pull request #93 from CHERRY-ui8/refactor/extract-e2e-test-common-logic
fix: refactor e2e tests to extract common test logic
2 parents 18a616d + f745401 commit 866dc7c

File tree

6 files changed

+78
-230
lines changed

6 files changed

+78
-230
lines changed

tests/e2e_tests/conftest.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import json
2+
import os
3+
import subprocess
4+
from pathlib import Path
5+
6+
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+
repo_root = Path(__file__).resolve().parents[2]
19+
os.chdir(repo_root)
20+
21+
config_path = repo_root / "graphgen" / "configs" / config_name
22+
output_dir = tmp_path / "output"
23+
output_dir.mkdir(parents=True, exist_ok=True)
24+
25+
result = subprocess.run(
26+
[
27+
"python",
28+
"-m",
29+
"graphgen.generate",
30+
"--config_file",
31+
str(config_path),
32+
"--output_dir",
33+
str(output_dir),
34+
],
35+
capture_output=True,
36+
text=True,
37+
check=False,
38+
)
39+
assert result.returncode == 0, f"Script failed with error: {result.stderr}"
40+
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}"
45+
run_folder = run_folders[0]
46+
47+
config_saved = run_folder / "config.yaml"
48+
assert config_saved.exists(), f"{config_saved} not found"
49+
50+
json_files = list(run_folder.glob("*.json"))
51+
assert json_files, f"No JSON output found in {run_folder}"
52+
53+
log_files = list(run_folder.glob("*.log"))
54+
assert log_files, "No log file generated"
55+
56+
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"
61+
62+
return run_folder, json_files[0]
63+
Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,7 @@
1-
import json
2-
import os
3-
import subprocess
41
from pathlib import Path
52

3+
from .conftest import run_generate_test
64

7-
def test_generate_aggregated(tmp_path: Path):
8-
repo_root = Path(__file__).resolve().parents[2]
9-
os.chdir(repo_root)
10-
11-
config_path = repo_root / "graphgen" / "configs" / "aggregated_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]
365

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"
6+
def test_generate_aggregated(tmp_path: Path):
7+
run_generate_test(tmp_path, "aggregated_config.yaml")
Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,7 @@
1-
import json
2-
import os
3-
import subprocess
41
from pathlib import Path
52

3+
from .conftest import run_generate_test
64

7-
def test_generate_atomic(tmp_path: Path):
8-
repo_root = Path(__file__).resolve().parents[2]
9-
os.chdir(repo_root)
10-
11-
config_path = repo_root / "graphgen" / "configs" / "atomic_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]
365

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"
6+
def test_generate_atomic(tmp_path: Path):
7+
run_generate_test(tmp_path, "atomic_config.yaml")
Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,7 @@
1-
import json
2-
import os
3-
import subprocess
41
from pathlib import Path
52

3+
from .conftest import run_generate_test
64

7-
def test_generate_aggregated(tmp_path: Path):
8-
repo_root = Path(__file__).resolve().parents[2]
9-
os.chdir(repo_root)
105

11-
config_path = repo_root / "graphgen" / "configs" / "cot_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"
6+
def test_generate_cot(tmp_path: Path):
7+
run_generate_test(tmp_path, "cot_config.yaml")
Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,7 @@
1-
import json
2-
import os
3-
import subprocess
41
from pathlib import Path
52

3+
from .conftest import run_generate_test
64

7-
def test_generate_aggregated(tmp_path: Path):
8-
repo_root = Path(__file__).resolve().parents[2]
9-
os.chdir(repo_root)
105

11-
config_path = repo_root / "graphgen" / "configs" / "multi_hop_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() and data_root.is_dir(), f"{data_root} does not exist or is not a directory"
33-
run_folders = sorted(list(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"
6+
def test_generate_multi_hop(tmp_path: Path):
7+
run_generate_test(tmp_path, "multi_hop_config.yaml")
Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,7 @@
1-
import json
2-
import os
3-
import subprocess
41
from pathlib import Path
52

3+
from .conftest import run_generate_test
64

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]
365

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"
6+
def test_generate_vqa(tmp_path: Path):
7+
run_generate_test(tmp_path, "vqa_config.yaml")

0 commit comments

Comments
 (0)