| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- #!/usr/bin/env python3
- """
- Test script to verify extraction consistency between autusm and USM acquire script.
- This script tests that both autusm's initial extraction and the acquire script
- produce the same directory structure (flattened to the output directory).
- """
- import os
- import sys
- import tempfile
- import shutil
- from pathlib import Path
- # Add src to path to import autusm modules
- sys.path.insert(0, str(Path(__file__).parent / "src"))
- from autusm.extractor import ArchiveExtractor
- from autusm.generator import ScriptGenerator
- from autusm.models import PackageInfo, BuildSystem, BuildSystemType
- def test_extraction_consistency():
- """Test that extraction behavior is consistent between autusm and acquire script."""
-
- # Test URL for hello-2.12.tar.gz
- test_url = "https://mirror.freedif.org/GNU/hello/hello-2.12.tar.gz"
- package_name = "hello"
-
- print("Testing extraction consistency...")
- print(f"Test URL: {test_url}")
- print(f"Package: {package_name}")
- print()
-
- # Create test directories
- with tempfile.TemporaryDirectory() as temp_dir:
- temp_path = Path(temp_dir)
-
- # Create output directories for both tests
- autusm_output = temp_path / "autusm_output"
- usm_output = temp_path / "usm_output"
- autusm_output.mkdir()
- usm_output.mkdir()
-
- # Download the test archive
- print("Downloading test archive...")
- from autusm.download import DownloadManager
- download_manager = DownloadManager()
- archive_path = download_manager.download(test_url, temp_path)
- print(f"Downloaded to: {archive_path}")
- print()
-
- # Test 1: autusm extraction
- print("Test 1: autusm extraction")
- extractor = ArchiveExtractor()
- autusm_source_dir = extractor.extract(archive_path, autusm_output)
- print(f"autusm extracted to: {autusm_source_dir}")
-
- # List the structure
- print("autusm directory structure:")
- for item in autusm_output.rglob("*"):
- if item.is_file():
- rel_path = item.relative_to(autusm_output)
- print(f" {rel_path}")
- print()
-
- # Test 2: Simulate USM acquire script extraction
- print("Test 2: Simulating USM acquire script extraction")
-
- # Create a test package info
- package_info = PackageInfo(
- name=package_name,
- version="2.12",
- summary="Test package",
- url=test_url
- )
-
- # Create a test build system
- build_system = BuildSystem(
- type=BuildSystemType.AUTOTOOLS,
- config_files=[],
- build_files=[],
- detected_commands=[],
- custom_args={}
- )
-
- # Generate the acquire script
- script_generator = ScriptGenerator()
- acquire_script = script_generator._common_acquire_template(package_info, build_system)
-
- # Write the acquire script to a file
- acquire_script_path = usm_output / "acquire"
- with open(acquire_script_path, "w") as f:
- f.write(acquire_script)
- os.chmod(acquire_script_path, 0o755)
-
- # Run the acquire script
- import subprocess
- result = subprocess.run(
- ["./acquire"],
- cwd=usm_output,
- capture_output=True,
- text=True
- )
-
- if result.returncode != 0:
- print(f"Error running acquire script: {result.stderr}")
- return False
-
- print("USM acquire script executed successfully")
-
- # List the structure
- print("USM directory structure:")
- for item in usm_output.rglob("*"):
- if item.is_file() and item.name != "acquire":
- rel_path = item.relative_to(usm_output)
- print(f" {rel_path}")
- print()
-
- # Compare the directory structures
- print("Comparing directory structures...")
-
- # Get file lists (excluding the acquire script)
- autusm_files = set()
- for item in autusm_output.rglob("*"):
- if item.is_file():
- rel_path = item.relative_to(autusm_output)
- autusm_files.add(str(rel_path))
-
- usm_files = set()
- for item in usm_output.rglob("*"):
- if item.is_file() and item.name != "acquire":
- rel_path = item.relative_to(usm_output)
- usm_files.add(str(rel_path))
-
- # Check if they match
- if autusm_files == usm_files:
- print("✓ SUCCESS: Directory structures match!")
- print(f"Both contain {len(autusm_files)} files")
- return True
- else:
- print("✗ FAILURE: Directory structures differ!")
-
- print("Files only in autusm:")
- for f in sorted(autusm_files - usm_files):
- print(f" {f}")
-
- print("Files only in USM:")
- for f in sorted(usm_files - autusm_files):
- print(f" {f}")
-
- return False
- if __name__ == "__main__":
- success = test_extraction_consistency()
- sys.exit(0 if success else 1)
|