"""Shared pytest fixtures for mcilspy tests.""" import os import shutil from pathlib import Path import pytest # Path to test fixtures directory FIXTURES_DIR = Path(__file__).parent / "fixtures" @pytest.fixture def test_assembly_path() -> str: """Return path to the custom test assembly. This is the primary fixture for tests - uses our custom-built TestAssembly.dll with known types and members. """ test_dll = FIXTURES_DIR / "TestAssembly.dll" if not test_dll.exists(): pytest.skip("TestAssembly.dll not found - run build_test_assembly.sh first") return str(test_dll) @pytest.fixture def sample_assembly_path() -> str: """Return path to a .NET assembly for testing. Falls back to SDK assemblies if test assembly not available. Prefer using test_assembly_path for new tests. """ # First try our test assembly test_dll = FIXTURES_DIR / "TestAssembly.dll" if test_dll.exists(): return str(test_dll) # Fallback: Try to find a .NET SDK assembly dotnet_base = Path("/usr/share/dotnet/sdk") if dotnet_base.exists(): for sdk_dir in dotnet_base.iterdir(): for net_version in ["net10.0", "net9.0", "net8.0", "net7.0", "net6.0"]: test_dll = ( sdk_dir / "Sdks" / "Microsoft.NET.Sdk" / "tools" / net_version / "Microsoft.NET.Build.Tasks.dll" ) if test_dll.exists(): return str(test_dll) # Last resort: any .dll in dotnet directory for root, _dirs, files in os.walk("/usr/share/dotnet"): for f in files: if f.endswith(".dll"): return os.path.join(root, f) pytest.skip("No .NET assembly found for testing") @pytest.fixture def nonexistent_path() -> str: """Return a path that doesn't exist.""" return "/nonexistent/path/to/assembly.dll" @pytest.fixture def ilspycmd_installed() -> bool: """Check if ilspycmd is available for integration tests.""" return shutil.which("ilspycmd") is not None @pytest.fixture def skip_without_ilspycmd(ilspycmd_installed): """Skip test if ilspycmd is not installed.""" if not ilspycmd_installed: pytest.skip("ilspycmd not installed") @pytest.fixture def temp_output_dir(tmp_path): """Provide a temporary directory for test outputs.""" return str(tmp_path)