"""Tests for error handling paths. These tests verify that the server handles various error conditions gracefully: - Invalid regex patterns - ilspycmd not found scenarios - Invalid language versions - File not found errors - Invalid assembly files """ from unittest.mock import AsyncMock, MagicMock, patch import pytest from mcilspy import server from mcilspy.ilspy_wrapper import ILSpyWrapper from mcilspy.metadata_reader import MetadataReader from mcilspy.models import EntityType # Fixture to bypass path validation for tests using mock paths @pytest.fixture def bypass_path_validation(): """Bypass _validate_assembly_path for tests using mock wrapper.""" def passthrough(path): return path with patch.object(server, "_validate_assembly_path", side_effect=passthrough): yield class TestInvalidRegexPatterns: """Tests for invalid regex pattern handling.""" @pytest.mark.asyncio async def test_search_types_invalid_regex(self, test_assembly_path): """Test search_types with invalid regex pattern.""" # Use an invalid regex pattern result = await server.search_types( test_assembly_path, pattern="[invalid(regex", use_regex=True, ) assert "Invalid regex pattern" in result @pytest.mark.asyncio async def test_search_methods_invalid_regex(self, test_assembly_path): """Test search_methods with invalid regex pattern.""" result = await server.search_methods( test_assembly_path, pattern="[unclosed", use_regex=True, ) assert "Invalid regex pattern" in result @pytest.mark.asyncio async def test_search_fields_invalid_regex(self, test_assembly_path): """Test search_fields with invalid regex pattern.""" result = await server.search_fields( test_assembly_path, pattern="*invalid*", use_regex=True, ) assert "Invalid regex pattern" in result @pytest.mark.asyncio async def test_search_properties_invalid_regex(self, test_assembly_path): """Test search_properties with invalid regex pattern.""" result = await server.search_properties( test_assembly_path, pattern="(?P