debian-forge/test/debian/test-debian-package-resolver.py

202 lines
6 KiB
Python

#!/usr/bin/env python3
"""
Test Debian Package Resolver for Debian Forge
This script tests the Debian package dependency resolution system for
composer builds.
"""
import json
import os
import sys
import tempfile
from pathlib import Path
# Add current directory to Python path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def test_package_resolver_import():
"""Test importing the package resolver"""
print("Testing package resolver import...")
try:
from debian_package_resolver import DebianPackageResolver, PackageInfo, DependencyResolution
print(" ✅ Package resolver imported successfully")
return True
except ImportError as e:
print(f" ❌ Failed to import package resolver: {e}")
return False
def test_package_info_dataclass():
"""Test PackageInfo dataclass"""
print("\nTesting PackageInfo dataclass...")
try:
from debian_package_resolver import PackageInfo
pkg = PackageInfo(
name="test-package",
version="1.0.0",
architecture="amd64",
depends=["libc6"],
recommends=["test-recommend"],
suggests=["test-suggest"],
conflicts=["test-conflict"],
breaks=[],
replaces=[],
provides=[],
essential=False,
priority="optional"
)
if pkg.name != "test-package":
print(" ❌ Package name not set correctly")
return False
if pkg.version != "1.0.0":
print(" ❌ Package version not set correctly")
return False
if len(pkg.depends) != 1:
print(" ❌ Package dependencies not set correctly")
return False
print(" ✅ PackageInfo dataclass works correctly")
return True
except Exception as e:
print(f" ❌ PackageInfo test failed: {e}")
return False
def test_dependency_resolution():
"""Test basic dependency resolution"""
print("\nTesting dependency resolution...")
try:
from debian_package_resolver import DebianPackageResolver
resolver = DebianPackageResolver()
# Test simple package resolution
packages = ["systemd", "ostree"]
resolution = resolver.resolve_package_dependencies(packages)
if not resolution.packages:
print(" ❌ No packages resolved")
return False
if not resolution.install_order:
print(" ❌ No install order generated")
return False
# Check if systemd and ostree are in resolved packages
if "systemd" not in resolution.packages:
print(" ❌ systemd not in resolved packages")
return False
if "ostree" not in resolution.packages:
print(" ❌ ostree not in resolved packages")
return False
print(" ✅ Dependency resolution works correctly")
return True
except Exception as e:
print(f" ❌ Dependency resolution test failed: {e}")
return False
def test_conflict_detection():
"""Test package conflict detection"""
print("\nTesting conflict detection...")
try:
from debian_package_resolver import DebianPackageResolver
resolver = DebianPackageResolver()
# Test conflicting packages
conflicting_packages = ["systemd", "sysvinit-core"]
resolution = resolver.resolve_package_dependencies(conflicting_packages)
if not resolution.conflicts:
print(" ❌ Conflicts not detected")
return False
print(" ✅ Conflict detection works correctly")
return True
except Exception as e:
print(f" ❌ Conflict detection test failed: {e}")
return False
def test_package_validation():
"""Test package list validation"""
print("\nTesting package validation...")
try:
from debian_package_resolver import DebianPackageResolver
resolver = DebianPackageResolver()
# Test valid package list
valid_packages = ["systemd", "ostree", "dbus"]
validation = resolver.validate_package_list(valid_packages)
if not validation['valid']:
print(f" ❌ Valid package list marked as invalid: {validation['errors']}")
return False
print(" ✅ Package validation works correctly")
return True
except Exception as e:
print(f" ❌ Package validation test failed: {e}")
return False
def main():
"""Main test function"""
print("Debian Package Resolver Test for Debian Forge")
print("=" * 60)
tests = [
("Package Resolver Import", test_package_resolver_import),
("PackageInfo Dataclass", test_package_info_dataclass),
("Dependency Resolution", test_dependency_resolution),
("Conflict Detection", test_conflict_detection),
("Package Validation", test_package_validation)
]
results = []
for test_name, test_func in tests:
try:
result = test_func()
results.append((test_name, result))
except Exception as e:
print(f"{test_name} test failed with exception: {e}")
results.append((test_name, False))
# Summary
print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
passed = 0
total = len(results)
for test_name, result in results:
status = "✅ PASS" if result else "❌ FAIL"
print(f"{test_name}: {status}")
if result:
passed += 1
print(f"\nOverall: {passed}/{total} tests passed")
if passed == total:
print("🎉 All tests passed! Debian package resolver is ready.")
return 0
else:
print("⚠️ Some tests failed. Please review the issues above.")
return 1
if __name__ == '__main__':
sys.exit(main())