-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_pipeline_functionality.py
More file actions
133 lines (105 loc) · 4.62 KB
/
test_pipeline_functionality.py
File metadata and controls
133 lines (105 loc) · 4.62 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python3
"""
Pre-flight functionality tests for GNN pipeline core capabilities.
These tests exercise core modules directly in isolated temp directories,
without assuming prior pipeline steps have produced global artifacts.
"""
import pytest
pytestmark = pytest.mark.pipeline
import json
class TestPipelineFunctionality:
"""Pre-flight checks that run each core module in isolation."""
def test_visualization_generates_images(self, isolated_temp_dir):
from visualization.processor import process_visualization
# Create a minimal markdown GNN file (processor expects .md)
gnn_dir = isolated_temp_dir / "gnn"
gnn_dir.mkdir(parents=True, exist_ok=True)
md = gnn_dir / "sample.md"
md.write_text(
"""
# Test Model
## Variables
s: state
o: observation
## Connections
s -> o
## Matrices
A = [0.5, 0.5; 0.3, 0.7]
""".strip()
)
out_root = isolated_temp_dir / "viz_out"
out_root.mkdir(parents=True, exist_ok=True)
ok = process_visualization(gnn_dir, out_root, verbose=False)
assert ok is True
# Processor creates model-specific subdirectories and files directly in output_dir
# Check for the visualization summary and/or PNG files
assert (out_root / "visualization_summary.json").exists() or list(out_root.glob("**/*.png"))
# ensure at least one image exists in any subdirectory
png_files = list(out_root.glob("**/*.png"))
assert len(png_files) > 0
for png in png_files:
assert png.stat().st_size > 100
def test_gnn_processing_generates_results(self, sample_gnn_files, isolated_temp_dir):
from gnn.core_processor import process_gnn_directory
gnn_dir = list(sample_gnn_files.values())[0].parent
out_root = isolated_temp_dir / "gnn_proc"
out_root.mkdir(parents=True, exist_ok=True)
result = process_gnn_directory(gnn_dir, output_dir=out_root, recursive=True)
assert result["status"] in ("SUCCESS", "FAILED")
results_file = out_root / "gnn_core_results.json"
assert results_file.exists()
data = json.loads(results_file.read_text())
assert isinstance(data, dict)
def test_multi_format_export_generates_files(self, isolated_temp_dir):
from export.processor import generate_exports
# Create a minimal markdown GNN file for export
gnn_dir = isolated_temp_dir / "gnn"
gnn_dir.mkdir(parents=True, exist_ok=True)
(gnn_dir / "sample.md").write_text(
"""
# Test Model
## Variables
x: latent
y: observed
## Connections
x -> y
""".strip()
)
out_root = isolated_temp_dir / "exports"
out_root.mkdir(parents=True, exist_ok=True)
ok = generate_exports(gnn_dir, out_root, verbose=False)
assert ok is True
exports_dir = out_root / "exports"
assert exports_dir.exists()
produced = list(exports_dir.glob("*.*"))
# Expect at least JSON to be present
assert any(p.suffix == ".json" for p in produced)
def test_results_json_are_valid(self, sample_gnn_files, isolated_temp_dir):
# Produce viz and export results on local temp files, then validate JSON summaries
from export.processor import generate_exports
from visualization.processor import process_visualization
gnn_dir = isolated_temp_dir / "gnn"
gnn_dir.mkdir(parents=True, exist_ok=True)
(gnn_dir / "sample.md").write_text("# M\n\n## Variables\na: v\n\n## Connections\na -> a\n")
out_root = isolated_temp_dir / "preflight"
out_root.mkdir(parents=True, exist_ok=True)
process_visualization(gnn_dir, out_root)
generate_exports(gnn_dir, out_root)
viz_summary = out_root / "visualization_summary.json"
exp_summary = out_root / "exports" / "export_results.json"
for fpath in [viz_summary, exp_summary]:
assert fpath.exists(), f"Missing summary: {fpath}"
data = json.loads(fpath.read_text())
assert isinstance(data, dict)
assert len(data) > 0
def test_preflight_metrics(self, sample_gnn_files, isolated_temp_dir):
# Sanity metrics based on generated artifacts
from visualization.processor import process_visualization
gnn_dir = list(sample_gnn_files.values())[0].parent
out_root = isolated_temp_dir / "metrics"
out_root.mkdir(parents=True, exist_ok=True)
process_visualization(gnn_dir, out_root)
png_count = len(list(out_root.glob("**/*.png")))
assert png_count >= 1
if __name__ == "__main__":
pytest.main([__file__, "-v"])