mcilspy/tests/conftest.py
Ryan Malloy 70c4a4a39a test: comprehensive test suite for mcilspy MCP server
Add complete test coverage for the mcilspy package:

- T7: Create TestAssembly.dll fixture with known types/members
- T1: Integration tests using real assembly (metadata reader + ILSpy wrapper)
- T2: MCP tool tests with mocked wrapper for each @mcp.tool()
- T3: Error path tests for regex, file not found, invalid assemblies
- T4: Concurrency tests with asyncio.gather() for parallel operations
- T5: Docstring coverage tests using AST introspection
- T6: Timeout behavior tests for 5-minute subprocess timeout

Test summary:
- 147 tests passing
- 14 skipped (ilspycmd-dependent integration tests)
- 73% code coverage
- All ruff linting checks pass
2026-02-08 11:40:57 -07:00

86 lines
2.4 KiB
Python

"""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)