-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_workflow_implementation.py
More file actions
148 lines (129 loc) · 4.36 KB
/
test_workflow_implementation.py
File metadata and controls
148 lines (129 loc) · 4.36 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
"""
Test script to verify the static analysis workflow implementation.
"""
import sys
from pathlib import Path
from test_utils import run_command
def test_script_exists():
"""Test that the script exists."""
script_path = Path("/scratch-public/add-static-analysis-workflow.py")
if not script_path.exists():
print("FAIL: Script does not exist")
return False
print("PASS: Script exists")
return True
def test_script_is_executable():
"""Test that the script can be executed."""
returncode, stdout, stderr = run_command(
"python3 /scratch-public/add-static-analysis-workflow.py --help"
)
if returncode != 0:
print(f"FAIL: Script help failed: {stderr}")
return False
print("PASS: Script is executable")
return True
def test_dry_run():
"""Test dry run mode."""
returncode, stdout, stderr = run_command(
"python3 /scratch-public/add-static-analysis-workflow.py /scratch-public --dry-run"
)
if returncode != 0:
print(f"FAIL: Dry run failed: {stderr}")
return False
if "Generated workflow content:" not in stdout:
print(f"FAIL: Dry run did not show workflow content")
return False
print("PASS: Dry run works")
return True
def test_actual_run():
"""Test actual execution."""
returncode, stdout, stderr = run_command(
"python3 /scratch-public/add-static-analysis-workflow.py /scratch-public"
)
if returncode != 0:
print(f"FAIL: Actual run failed: {stderr}")
return False
# Check if workflow file was created
workflow_file = Path("/scratch-public/.github/workflows/static-analysis.yaml")
if not workflow_file.exists():
print("FAIL: Workflow file was not created")
return False
# Check content
content = workflow_file.read_text()
if "static-analysis:" not in content:
print("FAIL: Workflow file does not contain expected content")
return False
print("PASS: Actual run created workflow file")
return True
def test_idempotency():
"""Test that running again doesn't change anything."""
returncode, stdout, stderr = run_command(
"python3 /scratch-public/add-static-analysis-workflow.py /scratch-public"
)
if returncode != 0:
print(f"FAIL: Second run failed: {stderr}")
return False
if "skipped" not in stdout.lower():
print(f"FAIL: Second run did not skip: {stdout}")
return False
print("PASS: Idempotency check passed")
return True
def test_tracking_log():
"""Test that tracking log is created."""
log_file = Path("/scratch-public/tracking-log.json")
if not log_file.exists():
print("FAIL: Tracking log was not created")
return False
import json
try:
with open(log_file, 'r') as f:
logs = json.load(f)
if not isinstance(logs, list):
print("FAIL: Tracking log is not a list")
return False
if len(logs) == 0:
print("FAIL: Tracking log is empty")
return False
print(f"PASS: Tracking log created with {len(logs)} entries")
return True
except Exception as e:
print(f"FAIL: Error reading tracking log: {e}")
return False
def main():
"""Run all tests."""
print("=" * 80)
print("Testing Static Analysis Workflow Implementation")
print("=" * 80)
tests = [
("Script exists", test_script_exists),
("Script is executable", test_script_is_executable),
("Dry run mode", test_dry_run),
("Actual execution", test_actual_run),
("Idempotency", test_idempotency),
("Tracking log", test_tracking_log),
]
results = []
for test_name, test_func in tests:
print(f"\nTest: {test_name}")
print("-" * 80)
try:
result = test_func()
results.append(result)
except Exception as e:
print(f"FAIL: Exception: {e}")
results.append(False)
print("\n" + "=" * 80)
print("TEST SUMMARY")
print("=" * 80)
passed = sum(results)
total = len(results)
print(f"Passed: {passed}/{total}")
if passed == total:
print("\n✓ All tests passed!")
return 0
else:
print("\n✗ Some tests failed")
return 1
if __name__ == "__main__":
sys.exit(main())