forked from darachubarova/deflicker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_download_feature.py
More file actions
146 lines (114 loc) · 4.02 KB
/
Copy pathtest_download_feature.py
File metadata and controls
146 lines (114 loc) · 4.02 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
#!/usr/bin/env python
"""Test script for the new download-video functionality."""
import sys
import json
from pathlib import Path
# Add src to path
sys.path.insert(0, str(Path(__file__).parent))
from src.utils import create_triple_comparison_video_sliced
import numpy as np
import cv2
def test_create_triple_comparison_video_sliced():
"""Test the create_triple_comparison_video_sliced function."""
print("Testing create_triple_comparison_video_sliced...")
# Create test data
frame_height, frame_width = 480, 640
num_frames = 10
fps = 30.0
# Generate synthetic frames
frames = [
np.random.randint(0, 255, (frame_height, frame_width, 3), dtype=np.uint8)
for _ in range(num_frames)
]
# Generate synthetic masks (0-1 float)
masks_before = [
np.random.rand(frame_height, frame_width).astype(np.float32)
for _ in range(num_frames)
]
masks_after = [
np.random.rand(frame_height, frame_width).astype(np.float32)
for _ in range(num_frames)
]
# Create output directory
output_dir = Path("results/test_output")
output_dir.mkdir(parents=True, exist_ok=True)
output_path = str(output_dir / "test_comparison.mp4")
try:
# Call the function
result = create_triple_comparison_video_sliced(
frames=frames,
masks_before=masks_before,
masks_after=masks_after,
output_path=output_path,
fps=fps
)
# Verify output
output_file = Path(result)
if output_file.exists() and output_file.stat().st_size > 0:
print(f"✅ Video created successfully: {output_path}")
print(f" File size: {output_file.stat().st_size} bytes")
print(f" Expected dimensions: {frame_width} x {frame_height * 3}")
print(f" Expected FPS: {fps}")
return True
else:
print(f"❌ Video file not created or empty")
return False
except Exception as e:
print(f"❌ Error: {e}")
import traceback
traceback.print_exc()
return False
def test_api_models():
"""Test that the Pydantic models are correctly defined."""
print("\nTesting API models...")
try:
from src.main import DownloadVideoRequest
# Test with all parameters
request1 = DownloadVideoRequest(
job_id="test-job-id",
frame_range_start=0,
frame_range_end=100
)
print(f"✅ DownloadVideoRequest with all params: {request1.dict()}")
# Test with only job_id
request2 = DownloadVideoRequest(job_id="test-job-id-2")
print(f"✅ DownloadVideoRequest with only job_id: {request2.dict()}")
# Test optional parameters
request3 = DownloadVideoRequest(
job_id="test-job-id-3",
frame_range_start=50
)
print(f"✅ DownloadVideoRequest with partial params: {request3.dict()}")
return True
except Exception as e:
print(f"❌ Error: {e}")
import traceback
traceback.print_exc()
return False
def main():
"""Run all tests."""
print("=" * 60)
print("Testing new download-video functionality")
print("=" * 60)
results = []
# Test 1: API models
results.append(("API Models", test_api_models()))
# Test 2: Video creation
results.append(("Video Creation", test_create_triple_comparison_video_sliced()))
# Summary
print("\n" + "=" * 60)
print("Test Summary")
print("=" * 60)
for test_name, result in results:
status = "✅ PASS" if result else "❌ FAIL"
print(f"{test_name}: {status}")
all_passed = all(result for _, result in results)
print("=" * 60)
if all_passed:
print("✅ All tests passed!")
return 0
else:
print("❌ Some tests failed!")
return 1
if __name__ == "__main__":
sys.exit(main())