Skip to content

Commit 6e4f3a4

Browse files
Enhance download_test_videos fixture
Refactor video downloading logic and improve error handling. Signed-off-by: Muhammad Rizwan Munawar <muhammadrizwanmunawar123@gmail.com>
1 parent 560f56b commit 6e4f3a4

1 file changed

Lines changed: 29 additions & 30 deletions

File tree

tests/core.py

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,47 @@
1414

1515
@pytest.fixture
1616
def download_test_videos():
17-
"""Download real test videos from GitHub releases."""
17+
"""Download real test videos from GitHub releases. Fail if not available."""
1818
temp_dir = tempfile.mkdtemp(prefix="streamgrid_test_")
19-
video_paths = []
20-
21-
for i, url in enumerate(video_urls):
22-
try:
23-
print(f"Downloading Video{i + 1}.mp4...")
24-
response = requests.get(url, timeout=120)
25-
if response.status_code == 200:
26-
video_path = os.path.join(temp_dir, f"Video{i + 1}.mp4")
27-
with open(video_path, "wb") as f:
28-
f.write(response.content)
29-
video_paths.append(video_path)
30-
print(f"✓ Downloaded Video{i + 1}.mp4")
31-
else:
32-
print(
33-
f"✗ Failed to download Video{i + 1}.mp4 (Status: {response.status_code})"
34-
)
35-
except requests.RequestException as e:
36-
print(f"✗ Error downloading Video{i + 1}.mp4: {e}")
37-
38-
# Change to temp directory so relative paths work
3919
original_dir = os.getcwd()
4020
os.chdir(temp_dir)
4121

22+
video_paths = []
23+
for i, url in enumerate(video_urls, start=1):
24+
print(f"Downloading Video{i}.mp4...")
25+
try:
26+
r = requests.get(url, timeout=60)
27+
r.raise_for_status()
28+
except Exception as e:
29+
# Fail instead of skip or dummy
30+
pytest.fail(f"Failed to download Video{i}.mp4: {e}")
31+
32+
video_path = os.path.join(temp_dir, f"Video{i}.mp4")
33+
with open(video_path, "wb") as f:
34+
f.write(r.content)
35+
video_paths.append(video_path)
36+
print(f"✓ Downloaded Video{i}.mp4")
37+
4238
yield video_paths
4339

44-
# Cleanup
4540
os.chdir(original_dir)
4641
shutil.rmtree(temp_dir, ignore_errors=True)
4742

4843

4944
def test_usage_code(download_test_videos):
50-
"""Test the usage of Streamgrid."""
51-
# Video paths
45+
"""Test the usage of StreamGrid with real videos."""
5246
paths = ["Video1.mp4", "Video2.mp4"]
5347
model = YOLO("yolo11n.pt")
5448

55-
# Test initialization
5649
sg = StreamGrid(paths, model)
57-
assert sg is not None
58-
59-
print("✓ StreamGrid initialization successful")
60-
print("✓ All videos loaded correctly")
61-
print("✓ YOLO model loaded successfully")
50+
try:
51+
assert sg is not None
52+
print("✓ StreamGrid initialization successful")
53+
print("✓ All videos loaded correctly")
54+
print("✓ YOLO model loaded successfully")
55+
finally:
56+
# Ensure background threads are cleaned up to avoid abort
57+
if hasattr(sg, "stop"):
58+
sg.stop()
59+
if hasattr(sg, "close"):
60+
sg.close()

0 commit comments

Comments
 (0)