-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample.py
More file actions
228 lines (177 loc) · 7.28 KB
/
Copy pathexample.py
File metadata and controls
228 lines (177 loc) · 7.28 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env python3
"""Example usage of the intelligent test generator."""
import json
import logging
from pathlib import Path
from .intelligent_generator import IntelligentTestGenerator
from .domain_analyzer import DomainAnalyzer
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def example_basic_generation():
"""Example: Basic test generation from teacher samples."""
print("\n" + "=" * 80)
print("EXAMPLE 1: Basic Test Generation")
print("=" * 80 + "\n")
# Load teacher samples
test_data_dir = Path(__file__).parent.parent / "test_data"
teacher_sample_file = test_data_dir / "onboarding_intermediate.json"
with open(teacher_sample_file, 'r') as f:
teacher_samples = json.load(f)
logger.info(f"Loaded {len(teacher_samples)} teacher samples")
# Initialize generator
generator = IntelligentTestGenerator(
region_name='us-west-2',
model_id='us.anthropic.claude-opus-4-5-20251101-v1:0',
temperature=0.8
)
# Generate 5 tests
generated = generator.generate_test_cases(
teacher_samples=teacher_samples,
count=5,
diversity_factor=0.7,
output_dir="./example_output/basic"
)
logger.info(f"\nGenerated {len(generated)} tests")
for i, test in enumerate(generated, 1):
logger.info(f" {i}. {test['name']} (complexity: {test['complexity']})")
def example_with_power_md():
"""Example: Generation with POWER.md context."""
print("\n" + "=" * 80)
print("EXAMPLE 2: Generation with POWER.md Context")
print("=" * 80 + "\n")
# Load teacher samples
test_data_dir = Path(__file__).parent.parent / "test_data"
teacher_sample_file = test_data_dir / "onboarding_intermediate.json"
with open(teacher_sample_file, 'r') as f:
teacher_samples = json.load(f)
# Load POWER.md
power_md_path = Path("/path/to/file")
power_instructions = None
if power_md_path.exists():
with open(power_md_path, 'r') as f:
power_instructions = f.read()
logger.info(f"Loaded POWER.md ({len(power_instructions)} chars)")
else:
logger.warning("POWER.md not found, proceeding without it")
# Initialize generator
generator = IntelligentTestGenerator(
region_name='us-west-2',
model_id='us.anthropic.claude-opus-4-5-20251101-v1:0',
temperature=0.8
)
# Generate tests with POWER.md context
generated = generator.generate_test_cases(
teacher_samples=teacher_samples,
count=3,
context=power_instructions,
diversity_factor=0.8,
output_dir="./example_output/with_power"
)
logger.info(f"\nGenerated {len(generated)} tests with POWER.md context")
def example_domain_analysis():
"""Example: Domain analysis without generation."""
print("\n" + "=" * 80)
print("EXAMPLE 3: Domain Analysis Only")
print("=" * 80 + "\n")
# Load teacher samples
test_data_dir = Path(__file__).parent.parent / "test_data"
teacher_sample_file = test_data_dir / "onboarding_intermediate.json"
with open(teacher_sample_file, 'r') as f:
teacher_samples = json.load(f)
# Initialize analyzer
analyzer = DomainAnalyzer(
region_name='us-west-2',
model_id='us.anthropic.claude-opus-4-5-20251101-v1:0'
)
# Analyze domain
analysis = analyzer.analyze_test_samples(teacher_samples, None)
# Save analysis
output_path = "./example_output/analysis/domain_analysis.json"
Path(output_path).parent.mkdir(parents=True, exist_ok=True)
analyzer.save_analysis(analysis, output_path)
# Print summary
logger.info(f"\nDomain Analysis Summary:")
logger.info(f" Domain: {analysis['domain_understanding'].get('domain_description', 'N/A')}")
logger.info(f" Core Capabilities: {len(analysis['domain_understanding'].get('core_capabilities', []))}")
logger.info(f" User Personas: {len(analysis['domain_understanding'].get('user_personas', []))}")
logger.info(f" Assertion Types: {list(analysis['assertion_patterns']['assertion_types'].keys())}")
logger.info(f"\nAnalysis saved to: {output_path}")
def example_high_diversity():
"""Example: High diversity generation for edge cases."""
print("\n" + "=" * 80)
print("EXAMPLE 4: High Diversity Generation")
print("=" * 80 + "\n")
# Load teacher samples
test_data_dir = Path(__file__).parent.parent / "test_data"
teacher_sample_file = test_data_dir / "onboarding_intermediate.json"
with open(teacher_sample_file, 'r') as f:
teacher_samples = json.load(f)
# Initialize generator
generator = IntelligentTestGenerator(
region_name='us-west-2',
model_id='us.anthropic.claude-opus-4-5-20251101-v1:0',
temperature=0.9 # Higher temperature for more creativity
)
# Generate with high diversity
generated = generator.generate_test_cases(
teacher_samples=teacher_samples,
count=5,
diversity_factor=0.95, # Very high diversity
output_dir="./example_output/high_diversity"
)
logger.info(f"\nGenerated {len(generated)} highly diverse tests")
logger.info("\nScenarios covered:")
for i, test in enumerate(generated, 1):
logger.info(f" {i}. {test['name']}")
logger.info(f" Complexity: {test['complexity']}, Assertions: {len(test.get('assertions', []))}")
def example_specific_complexity():
"""Example: Generate tests of specific complexity."""
print("\n" + "=" * 80)
print("EXAMPLE 5: Specific Complexity Generation")
print("=" * 80 + "\n")
# Load teacher samples
test_data_dir = Path(__file__).parent.parent / "test_data"
teacher_sample_file = test_data_dir / "onboarding_intermediate.json"
with open(teacher_sample_file, 'r') as f:
teacher_samples = json.load(f)
# Initialize generator
generator = IntelligentTestGenerator(
region_name='us-west-2',
model_id='us.anthropic.claude-opus-4-5-20251101-v1:0'
)
# Generate only complex tests
generated = generator.generate_test_cases(
teacher_samples=teacher_samples,
count=3,
complexity='complex',
diversity_factor=0.8,
output_dir="./example_output/complex_only"
)
logger.info(f"\nGenerated {len(generated)} complex tests")
for test in generated:
logger.info(f" - {test['name']}: {len(test.get('assertions', []))} assertions")
def main():
"""Run all examples."""
print("\n" + "=" * 80)
print("INTELLIGENT TEST GENERATOR - EXAMPLES")
print("=" * 80)
examples = [
("Basic Generation", example_basic_generation),
("With POWER.md", example_with_power_md),
("Domain Analysis", example_domain_analysis),
("High Diversity", example_high_diversity),
("Specific Complexity", example_specific_complexity),
]
print("\nAvailable examples:")
for i, (name, _) in enumerate(examples, 1):
print(f" {i}. {name}")
print("\nRunning Example 3 (Domain Analysis) as it's quickest...")
print("To run other examples, call them directly from this file.\n")
# Run domain analysis example (quickest)
example_domain_analysis()
print("\n" + "=" * 80)
print("Example complete! Check ./example_output/ for results")
print("=" * 80 + "\n")
if __name__ == '__main__':
main()