Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update
  • Loading branch information
RizwanMunawar committed Jul 7, 2025
commit 6e571f58e397a3028120064c6b718b31cfbe4e97
37 changes: 37 additions & 0 deletions .github/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Run Tests

on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
schedule:
- cron: '0 0 * * *' # Run daily at midnight UTC
workflow_dispatch: # Allow manual trigger

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libgl1-mesa-glx libglib2.0-0

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install pytest requests ultralytics opencv-python
pip install -e . # Install streamgrid package

- name: Run tests
run: |
pytest test_streamgrid.py
64 changes: 64 additions & 0 deletions tests/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import pytest
import os
import tempfile
import requests
import shutil
from ultralytics import YOLO
from streamgrid import StreamGrid

video_urls = [
"https://github.com/RizwanMunawar/streamgrid/releases/download/v1.0.0/1.mp4",
"https://github.com/RizwanMunawar/streamgrid/releases/download/v1.0.0/d3.mp4",
]

@pytest.fixture
def download_test_videos():
"""Download real test videos from GitHub releases"""
temp_dir = tempfile.mkdtemp(prefix="streamgrid_test_")
video_paths = []

for i, url in enumerate(video_urls):
try:
print(f"Downloading Video{i + 1}.mp4...")
response = requests.get(url, timeout=120)
if response.status_code == 200:
video_path = os.path.join(temp_dir, f"Video{i + 1}.mp4")
with open(video_path, 'wb') as f:
f.write(response.content)
video_paths.append(video_path)
print(f"✓ Downloaded Video{i + 1}.mp4")
else:
print(f"✗ Failed to download Video{i + 1}.mp4 (Status: {response.status_code})")
except requests.RequestException as e:
print(f"✗ Error downloading Video{i + 1}.mp4: {e}")

# Change to temp directory so relative paths work
original_dir = os.getcwd()
os.chdir(temp_dir)

yield video_paths

# Cleanup
os.chdir(original_dir)
shutil.rmtree(temp_dir, ignore_errors=True)

def test_usage_code(download_test_videos):
"""Test the exact code from documentation"""
if len(download_test_videos) != 2:
pytest.skip("All 2 videos must be downloaded")

# This is the exact code from your documentation
from ultralytics import YOLO
from streamgrid import StreamGrid

# Video paths
paths = ["Video1.mp4", "Video2.mp4"]
model = YOLO("yolo11n.pt")

# Test initialization
sg = StreamGrid(paths, model)
assert sg is not None

print("✓ StreamGrid initialization successful")
print("✓ All videos loaded correctly")
print("✓ YOLO model loaded successfully")