Files
rpi-tulivision/test_venv_setup.py
2025-09-25 15:16:52 +02:00

142 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""
Test script to verify virtual environment setup
This script tests if the virtual environment is properly configured
"""
import sys
import os
import subprocess
from pathlib import Path
def test_virtual_environment():
"""Test if virtual environment is properly set up"""
print("Testing Virtual Environment Setup")
print("=" * 40)
# Check if we're in a virtual environment
if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
print("✅ Running in virtual environment")
print(f" Python executable: {sys.executable}")
print(f" Virtual env path: {sys.prefix}")
else:
print("❌ Not running in virtual environment")
print(f" Python executable: {sys.executable}")
return False
# Test required packages
required_packages = [
'vlc',
'dotenv',
'psutil',
'yaml',
'RPi.GPIO',
'pigpio',
'requests',
'PIL',
'numpy',
'cv2'
]
print("\nTesting Required Packages:")
print("-" * 30)
missing_packages = []
for package in required_packages:
try:
if package == 'yaml':
import yaml
elif package == 'PIL':
from PIL import Image
elif package == 'cv2':
import cv2
else:
__import__(package)
print(f"{package}")
except ImportError:
print(f"{package} - Missing")
missing_packages.append(package)
if missing_packages:
print(f"\n❌ Missing packages: {', '.join(missing_packages)}")
return False
else:
print("\n✅ All required packages are available")
# Test VLC
print("\nTesting VLC:")
print("-" * 15)
try:
import vlc
instance = vlc.Instance()
print("✅ VLC instance created successfully")
except Exception as e:
print(f"❌ VLC test failed: {e}")
return False
# Test GPIO (if on Raspberry Pi)
print("\nTesting GPIO:")
print("-" * 15)
try:
import RPi.GPIO as GPIO
print("✅ RPi.GPIO module available")
except ImportError:
print("⚠️ RPi.GPIO not available (may not be on Raspberry Pi)")
except Exception as e:
print(f"❌ GPIO test failed: {e}")
return False
print("\n✅ Virtual environment setup test passed!")
return True
def test_installation_paths():
"""Test if installation paths are correct"""
print("\nTesting Installation Paths")
print("=" * 30)
install_dir = Path("/opt/video_player")
venv_dir = install_dir / "venv"
config_dir = Path("/etc/video_player")
paths_to_check = [
(install_dir, "Installation directory"),
(venv_dir, "Virtual environment directory"),
(venv_dir / "bin" / "python", "Virtual environment Python"),
(config_dir, "Configuration directory"),
(install_dir / "video_player.py", "Main video player script"),
(install_dir / "ir_remote.py", "IR remote script"),
(install_dir / "config_manager.py", "Config manager script")
]
all_good = True
for path, description in paths_to_check:
if path.exists():
print(f"{description}: {path}")
else:
print(f"{description}: {path} - Missing")
all_good = False
return all_good
def main():
"""Main test function"""
print("Video Player Virtual Environment Test")
print("=" * 50)
# Test installation paths
paths_ok = test_installation_paths()
# Test virtual environment
venv_ok = test_virtual_environment()
print("\n" + "=" * 50)
if paths_ok and venv_ok:
print("🎉 All tests passed! Virtual environment is properly configured.")
return 0
else:
print("❌ Some tests failed. Please check the installation.")
return 1
if __name__ == "__main__":
sys.exit(main())