-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_validate.py
More file actions
266 lines (217 loc) · 7.34 KB
/
simple_validate.py
File metadata and controls
266 lines (217 loc) · 7.34 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/usr/bin/env python3
"""
蝪??游?撽??單 - ?畾?蝚衣????郊撽?蝯曹?蝟餌絞?敹???"""
import os
import sys
import json
import sqlite3
from datetime import datetime
def log(message):
"""蝪?亥?頛詨"""
print(f"[{datetime.now().strftime('%H:%M:%S')}] {message}")
def test_basic_setup():
"""皜祈岫?箸閮剖?"""
log("1. 皜祈岫?箸瑼?摮??..")
required_files = [
'modules/game_data.py',
'modules/unified_data_manager.py',
'modules/unified_stock_manager.py',
'modules/unified_achievement_manager.py',
'server/main.py'
]
missing_files =
for file_path in required_files:
full_path = os.path.join(os.path.dirname(__file__), file_path)
if os.path.exists(full_path):
log(f" OK: {file_path}")
else:
# 文字待補
missing_files.append(file_path)
if missing_files:
log(f"FAIL: 蝻箏?瑼?: {missing_files}")
return False
log("PASS: ?箸瑼?瑼??")
return True
def test_directory_structure():
"""皜祈岫?桅?蝯?"""
log("2. 皜祈岫?桅?蝯?...")
required_dirs = [
'modules',
'server',
'saves',
'data'
]
missing_dirs =
for dir_name in required_dirs:
dir_path = os.path.join(os.path.dirname(__file__), dir_name)
if os.path.exists(dir_path):
log(f" OK: {dir_name}/ ?桅?摮")
else:
# 文字待補
missing_dirs.append(dir_name)
if missing_dirs:
log(f"FAIL: 蝻箏??桅?: {missing_dirs}")
return False
log("PASS: ?桅?蝯?瑼??")
return True
def test_json_data_integrity():
"""皜祈岫JSON鞈?摰??""
log("3. 皜祈岫?暹?摮?鞈?...")
saves_dir = os.path.join(os.path.dirname(__file__), 'saves')
if not os.path.exists(saves_dir):
# 文字待補
return False
save_files = [f for f in os.listdir(saves_dir) if f.endswith('.json')]
if not save_files:
log("WARN: 瘝??曉摮?瑼?")
return True
valid_saves = 0
for save_file in save_files:
file_path = os.path.join(saves_dir, save_file)
try:
with open(file_path, 'r', encoding='utf-8') as f:
data = json.load(f)
required_fields = ['cash', 'days', 'stocks']
missing_fields = [field for field in required_fields if field not in data]
if missing_fields:
log(f" FAIL: {save_file} 蝻箏?甈?: {missing_fields}")
else:
valid_saves += 1
log(f" OK: {save_file} 鞈?摰")
except Exception as e:
log(f" FAIL: {save_file} 霈?仃?? {str(e)[:50]}")
if valid_saves > 0:
# 文字待補
return True
else:
log("FAIL: 瘝???摮?")
return False
def test_server_api_structure():
"""皜祈岫隡箸??杗PI蝯?"""
log("4. 皜祈岫隡箸??杗PI蝯?...")
server_main = os.path.join(os.path.dirname(__file__), 'server', 'main.py')
try:
with open(server_main, 'r', encoding='utf-8') as f:
content = f.read()
required_endpoints = [
'/game/save',
'/game/load',
'/stocks/overview',
'/achievements/check',
'/achievements/user'
]
found_endpoints =
for endpoint in required_endpoints:
if endpoint in content:
found_endpoints.append(endpoint)
log(f" OK: {endpoint} 蝡舫?摮")
else:
# 文字待補
if len(found_endpoints) == len(required_endpoints):
log("PASS: 隡箸??杗PI蝯?瑼??")
return True
else:
log(f"FAIL: 蝻箏? {len(required_endpoints) - len(found_endpoints)} ?PI蝡舫?")
return False
except Exception as e:
log(f"FAIL: 隡箸??冽?獢炎?亙仃?? {e}")
return False
def test_module_structure():
"""皜祈岫璅?瑼?蝯?"""
log("5. 皜祈岫璅?瑼?蝯?...")
modules_dir = os.path.join(os.path.dirname(__file__), 'modules')
test_modules = [
'game_data.py',
'unified_data_manager.py',
'unified_stock_manager.py',
'unified_achievement_manager.py'
]
missing_modules =
for module_file in test_modules:
module_path = os.path.join(modules_dir, module_file)
if os.path.exists(module_path):
# 瑼瑼?憭批?
size = os.path.getsize(module_path)
if size > 100: # ?喳?100摮?
log(f" OK: {module_file} ({size} bytes)")
else:
log(f" FAIL: {module_file} 瑼??? ({size} bytes)")
missing_modules.append(module_file)
else:
# 文字待補
missing_modules.append(module_file)
if missing_modules:
log(f"FAIL: 璅?瑼???: {missing_modules}")
return False
log("PASS: 璅?瑼?蝯?瑼??")
return True
def generate_report(results):
"""???游??勗?"""
log("="*50)
log("INTEGRATION VALIDATION REPORT")
log("="*50)
total_tests = len(results)
passed_tests = sum(1 for result in results.values() if result)
log(f"Total Tests: {total_tests}")
log(f"Passed: {passed_tests}")
log(f"Failed: {total_tests - passed_tests}")
log(".1f")
if passed_tests == total_tests:
log("SUCCESS: All validations passed!")
status = "SUCCESS"
else:
log("ISSUES: Some tests failed")
status = "ISSUES_FOUND"
log("Detailed Results:")
for test_name, result in results.items():
icon = "PASS" if result else "FAIL"
log(f" {icon}: {test_name}")
# Save report
report = {
'timestamp': datetime.now().isoformat(),
'status': status,
'results': results,
'summary': {
'total': total_tests,
'passed': passed_tests,
'failed': total_tests - passed_tests,
'success_rate': (passed_tests / total_tests) * 100 if total_tests > 0 else 0
}
}
report_path = os.path.join(os.path.dirname(__file__), 'integration_validation_report.json')
with open(report_path, 'w', encoding='utf-8') as f:
json.dump(report, f, ensure_ascii=False, indent=2)
log(f"Report saved to: {report_path}")
return status == "SUCCESS"
def main():
"""銝駁?霅??""
log("Starting integration validation...")
test_functions = [
('Basic File Check', test_basic_setup),
('Directory Structure', test_directory_structure),
('JSON Data Integrity', test_json_data_integrity),
('Server API Structure', test_server_api_structure),
('Module Structure', test_module_structure)
]
results = {}
for test_name, test_func in test_functions:
log(f"Running: {test_name}")
try:
results[test_name] = test_func()
except Exception as e:
log(f"Test execution failed: {e}")
results[test_name] = False
success = generate_report(results)
return success
if __name__ == "__main__":
try:
success = main()
if success:
log("VALIDATION COMPLETE - System ready!")
sys.exit(0)
else:
log("VALIDATION COMPLETE - Issues found")
sys.exit(1)
except Exception as e:
log(f"Validation process error: {e}")
sys.exit(1)