#!/usr/bin/env python3 """ Real-world test script for the APT solver implementation This test requires a proper Debian system with APT configured """ import os import sys import tempfile import shutil from pathlib import Path # Add the project root to the Python path sys.path.insert(0, str(Path(__file__).parent.parent)) from osbuild.solver.apt import APT from osbuild.solver import RepoError, NoReposError, DepsolveError def test_apt_solver_real_system(): """Test APT solver on a real Debian system.""" print("๐Ÿงช Testing APT solver on real Debian system...") # Test configuration for real system request = { "arch": "amd64", "releasever": "trixie", "arguments": { "repos": [ { "name": "debian-main", "baseurl": "http://deb.debian.org/debian", "enabled": True, "gpgcheck": False, # Skip GPG for testing "components": ["main"], "architectures": ["amd64"], } ], "root_dir": None, # Use system root } } try: # Initialize APT solver solver = APT(request, "/tmp", "/tmp") print("โœ… APT solver initialized successfully") # Test search functionality (this should work on real system) search_result = solver.search({"query": "apt", "match_type": "name", "limit": 5}) print(f"โœ… Search result: {len(search_result)} packages found") if search_result: print(f" First result: {search_result[0]}") # Test package info try: pkg_info = solver.get_package_info("apt") print(f"โœ… Package info retrieved: {pkg_info.get('package', 'unknown')}") except Exception as e: print(f"โš ๏ธ Package info failed: {e}") # Test dependencies try: deps = solver.get_dependencies("apt") print(f"โœ… Dependencies retrieved: {len(deps.get('depends', []))} direct dependencies") except Exception as e: print(f"โš ๏ธ Dependencies failed: {e}") print("โœ… Real system APT solver test completed successfully") return True except Exception as e: print(f"โŒ Real system APT solver test failed: {e}") return False def test_apt_solver_with_chroot(): """Test APT solver with a chroot environment.""" print("๐Ÿงช Testing APT solver with chroot environment...") # Create a temporary directory for chroot with tempfile.TemporaryDirectory() as temp_dir: chroot_dir = os.path.join(temp_dir, "chroot") os.makedirs(chroot_dir, exist_ok=True) # Create basic APT directory structure apt_dirs = [ "etc/apt/sources.list.d", "var/lib/apt/lists/partial", "var/cache/apt/archives/partial", "var/lib/dpkg", ] for apt_dir in apt_dirs: os.makedirs(os.path.join(chroot_dir, apt_dir), exist_ok=True) # Create a basic sources.list sources_list = os.path.join(chroot_dir, "etc/apt/sources.list") with open(sources_list, "w") as f: f.write("deb http://deb.debian.org/debian trixie main\n") # Test configuration request = { "arch": "amd64", "releasever": "trixie", "arguments": { "repos": [ { "name": "debian-main", "baseurl": "http://deb.debian.org/debian", "enabled": True, "gpgcheck": False, "components": ["main"], "architectures": ["amd64"], } ], "root_dir": chroot_dir, } } try: # Initialize APT solver solver = APT(request, temp_dir, temp_dir) print("โœ… APT solver initialized with chroot") # Test dump functionality dump_result = solver.dump() print(f"โœ… Dump result: {len(dump_result.get('packages', []))} packages found") print("โœ… Chroot APT solver test completed successfully") return True except Exception as e: print(f"โŒ Chroot APT solver test failed: {e}") return False def test_apt_solver_advanced_features(): """Test advanced APT solver features.""" print("๐Ÿงช Testing APT solver advanced features...") # Test with multiple repositories request = { "arch": "amd64", "releasever": "trixie", "arguments": { "repos": [ { "name": "debian-main", "baseurl": "http://deb.debian.org/debian", "enabled": True, "gpgcheck": False, "components": ["main"], "architectures": ["amd64"], "priority": 500, }, { "name": "debian-security", "baseurl": "http://security.debian.org/debian-security", "enabled": True, "gpgcheck": False, "components": ["main"], "architectures": ["amd64"], "priority": 100, } ], "root_dir": None, } } try: solver = APT(request, "/tmp", "/tmp") print("โœ… APT solver initialized with multiple repositories") # Test repository configuration if len(solver.repos) == 2: print("โœ… Multiple repositories configured correctly") else: print(f"โŒ Expected 2 repositories, got {len(solver.repos)}") return False # Test priority configuration priorities = [repo["priority"] for repo in solver.repos] if 100 in priorities and 500 in priorities: print("โœ… Repository priorities configured correctly") else: print(f"โŒ Repository priorities incorrect: {priorities}") return False print("โœ… Advanced features test completed successfully") return True except Exception as e: print(f"โŒ Advanced features test failed: {e}") return False def main(): """Run all APT solver tests.""" print("๐Ÿš€ Starting APT solver real-world tests...") print("=" * 50) tests = [ test_apt_solver_real_system, test_apt_solver_with_chroot, test_apt_solver_advanced_features, ] passed = 0 total = len(tests) for test in tests: try: if test(): passed += 1 except Exception as e: print(f"โŒ Test {test.__name__} failed with exception: {e}") print("-" * 30) print(f"๐Ÿ“Š Test Results: {passed}/{total} tests passed") if passed == total: print("๐ŸŽ‰ All APT solver real-world tests passed!") return 0 else: print("โŒ Some APT solver real-world tests failed!") return 1 if __name__ == "__main__": sys.exit(main())