youtube-cli/test_tui.py
Jarian Cottingham 06877fb2fc feat: add TUI (Textual User Interface) with download queue system
- New TUI using Textual framework with responsive interface
- Search, results, download, and queue screens for YouTube video management
- Download queue system with sequential background downloads
- Status bar with queue count and download progress indicators
- Comprehensive test suite (97 tests) with 100% pass rate
- Modern Python packaging with pyproject.toml and uv support
- Added requirements-tui.txt for TUI-specific dependencies
- Updated setup.py and install.sh for TUI integration
- Enhanced README.md with TUI usage documentation
2026-02-25 15:59:15 -06:00

167 lines
3.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
Main test runner for YouTube TUI tests
This script runs all TUI tests with detailed output and coverage reporting.
"""
import os
import subprocess
import sys
def print_header(text):
"""Print a formatted header"""
print("\n" + "=" * 70)
print(f" {text}")
print("=" * 70)
def print_success(text):
"""Print success message"""
print(f"\033[92m✓ {text}\033[0m")
def print_error(text):
"""Print error message"""
print(f"\033[91m✗ {text}\033[0m")
def print_info(text):
"""Print info message"""
print(f"\033[94m {text}\033[0m")
def run_pytest():
"""Run pytest with coverage"""
print_header("Running TUI Tests")
# Build pytest command
pytest_cmd = [
sys.executable,
"-m",
"pytest",
"tests/",
"-v", # Verbose output
"--tb=short", # Short traceback
"--strict-markers", # Require markers
]
# Add coverage if available
try:
import importlib.util
if importlib.util.find_spec("pytest_cov") is not None:
pytest_cmd.extend(
[
"--cov=youtube_tui",
"--cov-report=term-missing",
"--cov-report=html:htmlcov",
"--cov-config=.coveragerc",
]
)
print_info("Coverage reporting enabled")
else:
print_info("Coverage not available, skipping coverage reporting")
except ImportError:
print_info("Coverage not available, skipping coverage reporting")
print_info(f"Running: {' '.join(pytest_cmd)}")
# Run pytest
result = subprocess.run(
pytest_cmd, cwd=os.path.dirname(os.path.abspath(__file__))
)
return result.returncode
def run_tui_tests_directly():
"""Run TUI tests directly without pytest"""
print_header("Running TUI Tests (Direct Mode)")
# Import test modules
import unittest
# Discover tests
loader = unittest.TestLoader()
start_dir = "tests"
suite = loader.discover(start_dir, pattern="test_*.py")
# Run tests
runner = unittest.TextTestRunner(verbosity=2)
result = runner.run(suite)
return 0 if result.wasSuccessful() else 1
def check_dependencies():
"""Check if required dependencies are installed"""
print_header("Checking Dependencies")
required_packages = [
("textual", "Textual TUI framework"),
("pytest", "pytest testing framework"),
]
missing = []
for package, name in required_packages:
try:
__import__(package)
print_success(f"{name} ({package})")
except ImportError:
print_error(f"{name} ({package}) - NOT INSTALLED")
missing.append(package)
if missing:
print_info("\nInstall missing packages with:")
print(f" pip install {' '.join(missing)}")
return False
return True
def main():
"""Main entry point"""
print_header("YouTube TUI Test Suite")
# Check dependencies
if not check_dependencies():
print_error("Missing dependencies. Please install required packages.")
sys.exit(1)
# Check if pytest is available
try:
import importlib.util
if importlib.util.find_spec("pytest") is not None:
print_success("pytest is installed")
use_pytest = True
else:
print_info("pytest not found, using unittest")
use_pytest = False
except ImportError:
print_info("pytest not found, using unittest")
use_pytest = False
# Run tests
if use_pytest:
exit_code = run_pytest()
else:
exit_code = run_tui_tests_directly()
# Print summary
print_header("Test Summary")
if exit_code == 0:
print_success("All tests passed!")
else:
print_error("Some tests failed. Please review the output above.")
return exit_code
if __name__ == "__main__":
sys.exit(main())