-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_local.py
More file actions
223 lines (180 loc) · 7.66 KB
/
test_local.py
File metadata and controls
223 lines (180 loc) · 7.66 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
#!/usr/bin/env python3
"""
Local testing script that can run with minimal dependencies.
Tests core functionality without requiring C++ compilation.
"""
import os
import sys
import json
def test_environment():
"""Test what dependencies are available"""
print("Testing Local Environment")
print("=" * 50)
results = {}
# Test basic Python modules
basic_modules = ['os', 'sys', 'json', 're', 'time', 'datetime']
for module in basic_modules:
try:
__import__(module)
results[module] = "Available"
except ImportError:
results[module] = "Missing"
# Test web framework
try:
import flask
results['flask'] = f"[TEST] Available (v{flask.__version__})"
except ImportError:
results['flask'] = "[TEST] Missing - install with: pip install flask"
try:
import requests
results['requests'] = f"[TEST] Available (v{requests.__version__})"
except ImportError:
results['requests'] = "[TEST] Missing - install with: pip install requests"
# Test scientific stack (these might fail due to C++ deps)
scientific_modules = {
'numpy': 'numpy',
'scipy': 'scipy',
'sklearn': 'scikit-learn',
'pandas': 'pandas',
'psutil': 'psutil'
}
for module_name, package_name in scientific_modules.items():
try:
module = __import__(module_name)
version = getattr(module, '__version__', 'unknown')
results[package_name] = f"[TEST] Available (v{version})"
except ImportError as e:
results[package_name] = f"[TEST] Missing - C++ compilation may be required"
except Exception as e:
results[package_name] = f"[TEST][TEST] Import error: {str(e)}"
# Test NLTK
try:
import nltk
results['nltk'] = f"[TEST] Available (v{nltk.__version__})"
# Test NLTK data
try:
from nltk.corpus import stopwords
stopwords.words('english')
results['nltk-data'] = "[TEST] Stopwords available"
except:
results['nltk-data'] = "[TEST][TEST] NLTK data not downloaded"
except ImportError:
results['nltk'] = "[TEST] Missing - install with: pip install nltk"
# Print results
for module, status in results.items():
print(f"{module:15} : {status}")
return results
def test_mock_lda():
"""Test the mock LDA implementation"""
print("\n[TEST]¬ Testing Mock LDA Implementation")
print("=" * 50)
try:
# Import mock implementation
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from app_mock import mock_lda_analysis, preprocess_text
# Test data
test_docs = [
'claude assistant configuration prompt role system behavior instructions',
'project file directory structure organization folder path management',
'code function class method style format convention programming',
'test testing spec validation check verify quality assurance',
'documentation readme docs guide tutorial example usage help support'
]
print(f"[TEST] Testing with {len(test_docs)} documents")
# Test preprocessing
sample_text = test_docs[0]
tokens = preprocess_text(sample_text)
print(f"[TEST]¤ Preprocessing test: '{sample_text[:30]}...' -> {len(tokens)} tokens")
print(f" Tokens: {tokens[:5]}...")
# Test LDA
success, topics_data = mock_lda_analysis(test_docs, num_topics=3)
if success and topics_data:
print(f"[TEST] Mock LDA successful: {len(topics_data)} topics generated")
for i, topic in enumerate(topics_data):
print(f" Topic {i+1}: {topic['label']}")
print(f" Words: {topic['top_words'][:5]}")
return True
else:
print("[TEST] Mock LDA failed")
return False
except Exception as e:
print(f"[TEST] Mock LDA test failed: {e}")
return False
def test_flask_minimal():
"""Test minimal Flask setup"""
print("\n[TEST] Testing Minimal Flask Setup")
print("=" * 50)
try:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return "Hello from minimal Flask!"
@app.route('/test')
def test():
return {"status": "ok", "message": "Flask working"}
print("[TEST] Flask app created successfully")
print(" Routes registered: /, /test")
print(" Ready to run with: app.run()")
return True
except Exception as e:
print(f"[TEST] Flask test failed: {e}")
return False
def suggest_installation_strategy(results):
"""Suggest installation strategy based on test results"""
print("\n[TEST]¡ Installation Strategy Recommendations")
print("=" * 50)
missing_basic = []
missing_scientific = []
basic_required = ['flask', 'requests', 'nltk']
scientific_optional = ['numpy', 'scikit-learn', 'scipy', 'pandas', 'psutil']
for module in basic_required:
if module not in results or '[TEST]' in results[module]:
missing_basic.append(module)
for module in scientific_optional:
if module not in results or '[TEST]' in results[module] or '[TEST][TEST]' in results[module]:
missing_scientific.append(module)
if missing_basic:
print("[TEST]¨ Critical missing dependencies (install these first):")
for module in missing_basic:
print(f" pip install {module}")
if missing_scientific:
print("\n[TEST]Š Scientific stack issues (use mock version if these fail):")
print(" Option 1 - Try installing with wheels:")
for module in missing_scientific:
print(f" pip install {module}")
print("\n Option 2 - Use conda (may have better binary support):")
print(" conda install numpy scipy scikit-learn pandas")
print("\n Option 3 - Use mock version (app_mock.py) to bypass C++ issues")
if not missing_basic and not missing_scientific:
print("[TEST] All dependencies available! You can run the full app.py")
elif not missing_basic:
print("[TEST] Basic dependencies available! Use app_mock.py for testing")
print("\n[TEST]‹ Testing Commands:")
print(" Full version: python app.py")
print(" Mock version: python app_mock.py")
print(" This test: python test_local.py")
def main():
print("Local Testing for Claude.md Analyzer")
print("=" * 60)
print("This script helps you test the analyzer without C++ compilation issues\n")
# Run tests
results = test_environment()
mock_success = test_mock_lda()
flask_success = test_flask_minimal()
# Provide recommendations
suggest_installation_strategy(results)
# Summary
print(f"\n[TEST]Š Test Summary")
print("=" * 50)
print(f"Environment check: {'[TEST] Pass' if results else '[TEST] Fail'}")
print(f"Mock LDA test: {'[TEST] Pass' if mock_success else '[TEST] Fail'}")
print(f"Flask test: {'[TEST] Pass' if flask_success else '[TEST] Fail'}")
if mock_success and flask_success:
print("\n[TEST]‰ You can use the mock version for local testing!")
print(" Run: python app_mock.py")
print(" Then visit: http://localhost:5001")
else:
print("\n[TEST][TEST] Some issues detected. Check the recommendations above.")
if __name__ == "__main__":
main()