evgeniy778 commited on
Commit
1b6862d
·
verified ·
1 Parent(s): e642a03

Add Compute Adapter Test Version 1.0

Browse files
Files changed (1) hide show
  1. test_compute_adapter.py +369 -0
test_compute_adapter.py ADDED
@@ -0,0 +1,369 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # =====================================================
2
+ # Apckeyl Framework
3
+ # Version 1.0
4
+ # test_compute_adapter.py
5
+ # =====================================================
6
+
7
+ """
8
+ Tests for Apckeyl Compute Adapter.
9
+
10
+ Version 1.0
11
+ """
12
+
13
+ from compute_adapter import (
14
+ ComputeAdapter,
15
+ RealESRGANAdapter,
16
+ )
17
+
18
+
19
+ # =====================================================
20
+ # Test 1 — Base Adapter Exists
21
+ # =====================================================
22
+
23
+ def test_base_adapter_exists():
24
+
25
+ adapter = ComputeAdapter(
26
+ module_id="test_module",
27
+ module_name="Test Module",
28
+ )
29
+
30
+ assert adapter is not None
31
+
32
+
33
+ # =====================================================
34
+ # Test 2 — Adapter Information
35
+ # =====================================================
36
+
37
+ def test_adapter_info():
38
+
39
+ adapter = ComputeAdapter(
40
+
41
+ module_id="test_module",
42
+
43
+ module_name="Test Module",
44
+
45
+ endpoint="https://example.com",
46
+ )
47
+
48
+ info = adapter.get_info()
49
+
50
+ assert info["module_id"] == (
51
+ "test_module"
52
+ )
53
+
54
+ assert info["module_name"] == (
55
+ "Test Module"
56
+ )
57
+
58
+ assert info["endpoint"] == (
59
+ "https://example.com"
60
+ )
61
+
62
+
63
+ # =====================================================
64
+ # Test 3 — Dispatch Preparation
65
+ # =====================================================
66
+
67
+ def test_dispatch():
68
+
69
+ adapter = ComputeAdapter(
70
+
71
+ module_id="test_module",
72
+
73
+ module_name="Test Module",
74
+ )
75
+
76
+ task = {
77
+
78
+ "task_id": "task_000001",
79
+
80
+ "task_type": "image_upscale",
81
+
82
+ "payload": {
83
+
84
+ "filename": "test.png",
85
+
86
+ "scale": 4,
87
+ },
88
+ }
89
+
90
+ result = adapter.dispatch(
91
+ task
92
+ )
93
+
94
+ assert result["status"] == (
95
+ "prepared"
96
+ )
97
+
98
+ assert result["module_id"] == (
99
+ "test_module"
100
+ )
101
+
102
+ assert result["task_id"] == (
103
+ "task_000001"
104
+ )
105
+
106
+ assert result["task_type"] == (
107
+ "image_upscale"
108
+ )
109
+
110
+ assert result["payload"] == (
111
+ task["payload"]
112
+ )
113
+
114
+
115
+ # =====================================================
116
+ # Test 4 — None Task Rejected
117
+ # =====================================================
118
+
119
+ def test_none_task_rejected():
120
+
121
+ adapter = ComputeAdapter(
122
+
123
+ module_id="test_module",
124
+
125
+ module_name="Test Module",
126
+ )
127
+
128
+ try:
129
+
130
+ adapter.dispatch(None)
131
+
132
+ except ValueError:
133
+
134
+ return
135
+
136
+ raise AssertionError(
137
+ "None task was not rejected"
138
+ )
139
+
140
+
141
+ # =====================================================
142
+ # Test 5 — Invalid Task Type Rejected
143
+ # =====================================================
144
+
145
+ def test_invalid_task_type_rejected():
146
+
147
+ adapter = ComputeAdapter(
148
+
149
+ module_id="test_module",
150
+
151
+ module_name="Test Module",
152
+ )
153
+
154
+ try:
155
+
156
+ adapter.dispatch(
157
+ "invalid_task"
158
+ )
159
+
160
+ except TypeError:
161
+
162
+ return
163
+
164
+ raise AssertionError(
165
+ "Invalid task type was not rejected"
166
+ )
167
+
168
+
169
+ # =====================================================
170
+ # Test 6 — Task Without ID Rejected
171
+ # =====================================================
172
+
173
+ def test_missing_task_id_rejected():
174
+
175
+ adapter = ComputeAdapter(
176
+
177
+ module_id="test_module",
178
+
179
+ module_name="Test Module",
180
+ )
181
+
182
+ task = {
183
+
184
+ "task_type": "image_upscale",
185
+
186
+ "payload": {},
187
+ }
188
+
189
+ try:
190
+
191
+ adapter.dispatch(task)
192
+
193
+ except ValueError:
194
+
195
+ return
196
+
197
+ raise AssertionError(
198
+ "Task without task_id was not rejected"
199
+ )
200
+
201
+
202
+ # =====================================================
203
+ # Test 7 — RealESRGAN Adapter
204
+ # =====================================================
205
+
206
+ def test_realesrgan_adapter():
207
+
208
+ adapter = RealESRGANAdapter(
209
+
210
+ endpoint="https://example.com",
211
+ )
212
+
213
+ info = adapter.get_info()
214
+
215
+ assert info["module_id"] == (
216
+ "realesrgan"
217
+ )
218
+
219
+ assert info["module_name"] == (
220
+ "Apckeyl_RealESRGAN"
221
+ )
222
+
223
+ assert info["endpoint"] == (
224
+ "https://example.com"
225
+ )
226
+
227
+
228
+ # =====================================================
229
+ # Test 8 — RealESRGAN Dispatch
230
+ # =====================================================
231
+
232
+ def test_realesrgan_dispatch():
233
+
234
+ adapter = RealESRGANAdapter()
235
+
236
+ task = {
237
+
238
+ "task_id": "task_realesrgan_001",
239
+
240
+ "task_type": "image_upscale",
241
+
242
+ "payload": {
243
+
244
+ "filename": "image.png",
245
+
246
+ "scale": 4,
247
+ },
248
+ }
249
+
250
+ result = adapter.dispatch(
251
+ task
252
+ )
253
+
254
+ assert result["status"] == (
255
+ "prepared"
256
+ )
257
+
258
+ assert result["module_id"] == (
259
+ "realesrgan"
260
+ )
261
+
262
+ assert result["module_name"] == (
263
+ "Apckeyl_RealESRGAN"
264
+ )
265
+
266
+
267
+ # =====================================================
268
+ # Test Runner
269
+ # =====================================================
270
+
271
+ def main():
272
+
273
+ tests = [
274
+
275
+ test_base_adapter_exists,
276
+
277
+ test_adapter_info,
278
+
279
+ test_dispatch,
280
+
281
+ test_none_task_rejected,
282
+
283
+ test_invalid_task_type_rejected,
284
+
285
+ test_missing_task_id_rejected,
286
+
287
+ test_realesrgan_adapter,
288
+
289
+ test_realesrgan_dispatch,
290
+ ]
291
+
292
+ passed = 0
293
+
294
+ failed = 0
295
+
296
+ print(
297
+ "===================================="
298
+ )
299
+
300
+ print(
301
+ "Apckeyl Compute Adapter Test"
302
+ )
303
+
304
+ print(
305
+ "Version 1.0"
306
+ )
307
+
308
+ print(
309
+ "===================================="
310
+ )
311
+
312
+ for test in tests:
313
+
314
+ try:
315
+
316
+ test()
317
+
318
+ print(
319
+ f"PASS: {test.__name__}"
320
+ )
321
+
322
+ passed += 1
323
+
324
+ except Exception as error:
325
+
326
+ print(
327
+ f"FAIL: {test.__name__}"
328
+ )
329
+
330
+ print(
331
+ f"ERROR: {error}"
332
+ )
333
+
334
+ failed += 1
335
+
336
+ print(
337
+ "===================================="
338
+ )
339
+
340
+ print(
341
+ f"PASSED: {passed}"
342
+ )
343
+
344
+ print(
345
+ f"FAILED: {failed}"
346
+ )
347
+
348
+ print(
349
+ "===================================="
350
+ )
351
+
352
+ if failed > 0:
353
+
354
+ raise RuntimeError(
355
+ "Compute Adapter Test FAILED"
356
+ )
357
+
358
+ print(
359
+ "COMPUTE ADAPTER TEST: PASSED"
360
+ )
361
+
362
+
363
+ # =====================================================
364
+ # Entry Point
365
+ # =====================================================
366
+
367
+ if __name__ == "__main__":
368
+
369
+ main()