|
14 | 14 |
|
15 | 15 | @pytest.fixture |
16 | 16 | def download_test_videos(): |
17 | | - """Download real test videos from GitHub releases.""" |
| 17 | + """Download real test videos from GitHub releases. Fail if not available.""" |
18 | 18 | 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 |
39 | 19 | original_dir = os.getcwd() |
40 | 20 | os.chdir(temp_dir) |
41 | 21 |
|
| 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 | + |
42 | 38 | yield video_paths |
43 | 39 |
|
44 | | - # Cleanup |
45 | 40 | os.chdir(original_dir) |
46 | 41 | shutil.rmtree(temp_dir, ignore_errors=True) |
47 | 42 |
|
48 | 43 |
|
49 | 44 | 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.""" |
52 | 46 | paths = ["Video1.mp4", "Video2.mp4"] |
53 | 47 | model = YOLO("yolo11n.pt") |
54 | 48 |
|
55 | | - # Test initialization |
56 | 49 | 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