-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_args_format.py
More file actions
103 lines (81 loc) · 3.5 KB
/
test_args_format.py
File metadata and controls
103 lines (81 loc) · 3.5 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
"""Test that enhanced prompts generate Args/Returns/Raises format."""
import asyncio
from pathlib import Path
from empathy_os.workflows.document_gen import DocumentGenerationWorkflow
async def test_args_format():
"""Test Args/Returns/Raises format in generated docs."""
print("📚 Testing Args/Returns/Raises Format\n")
# Use a simple module with functions that have parameters
test_module = Path("src/empathy_os/cache_stats.py")
if not test_module.exists():
print(f"❌ Test module not found: {test_module}")
return
print(f"📝 Generating documentation for: {test_module}")
print("🎯 Expected: **Args:**, **Returns:**, **Raises:** sections\n")
# Read full source code (needed for AST parsing in API reference generation)
source_code = test_module.read_text()
# Create workflow with enhanced prompts
workflow = DocumentGenerationWorkflow(
export_path="docs/generated",
max_cost=0.5,
graceful_degradation=True,
)
print("🔄 Calling LLM with MANDATORY format requirements...\n")
# Generate documentation
result = await workflow.execute(
source_code=source_code,
target=str(test_module),
doc_type="api_reference",
audience="developers",
)
# Extract document
if hasattr(result, "final_output") and isinstance(result.final_output, dict):
document = result.final_output.get("document", "")
export_path = result.final_output.get("export_path", "")
else:
print("❌ Unexpected result format")
return
print("✅ Documentation Generated!\n")
# Check for required format elements
has_args = "**Args:**" in document or "Args:" in document
has_returns = "**Returns:**" in document or "Returns:" in document
has_raises = "**Raises:**" in document or "Raises:" in document
print("📊 Format Check:")
print(f" {'✅' if has_args else '❌'} Has **Args:** sections")
print(f" {'✅' if has_returns else '❌'} Has **Returns:** sections")
print(f" {'✅' if has_raises else '❌'} Has **Raises:** sections")
# Count occurrences
args_count = document.count("**Args:**") + document.count("Args:")
returns_count = document.count("**Returns:**") + document.count("Returns:")
raises_count = document.count("**Raises:**") + document.count("Raises:")
print("\n📈 Occurrences:")
print(f" Args: {args_count} times")
print(f" Returns: {returns_count} times")
print(f" Raises: {raises_count} times")
if export_path:
print(f"\n📁 Saved to: {export_path}")
# Show a sample with Args
if has_args:
print("\n📄 Sample showing Args format:")
print("-" * 60)
lines = document.split("\n")
for i, line in enumerate(lines):
if "**Args:**" in line or "Args:" in line:
# Show 20 lines around this Args section
start = max(0, i - 5)
end = min(len(lines), i + 15)
print("\n".join(lines[start:end]))
break
print("-" * 60)
else:
print("\n⚠️ No Args sections found! Showing first 1000 chars:")
print("-" * 60)
print(document[:1000])
print("-" * 60)
# Overall verdict
if has_args and has_returns:
print("\n✅ SUCCESS: Documentation uses required Args/Returns/Raises format!")
else:
print("\n❌ FAILED: Documentation missing required format sections")
if __name__ == "__main__":
asyncio.run(test_args_format())