Skip to main content
Glama
test_exceptions.py4.36 kB
"""Tests for custom exceptions.""" import pytest from aseprite_mcp.core.exceptions import ( AsepriteError, AsepriteNotFoundError, CommandExecutionError, LuaScriptError, FileNotFoundError as AsepriteFileNotFoundError, ValidationError, SecurityError ) class TestAsepriteError: """Tests for base AsepriteError.""" def test_basic_error(self): """Test basic error creation.""" error = AsepriteError("Test error") assert str(error) == "Test error" assert error.details == {} def test_error_with_details(self): """Test error with details.""" details = {"key": "value", "number": 42} error = AsepriteError("Test error", details) assert str(error) == "Test error" assert error.details == details class TestAsepriteNotFoundError: """Tests for AsepriteNotFoundError.""" def test_without_path(self): """Test error without specific path.""" error = AsepriteNotFoundError() assert "Aseprite executable not found" in str(error) assert "Please ensure ASEPRITE_PATH is set correctly" in str(error) assert error.details["path"] is None def test_with_path(self): """Test error with specific path.""" error = AsepriteNotFoundError("/path/to/aseprite") assert "Aseprite executable not found at '/path/to/aseprite'" in str(error) assert error.details["path"] == "/path/to/aseprite" class TestCommandExecutionError: """Tests for CommandExecutionError.""" def test_command_error(self): """Test command execution error.""" command = ["aseprite", "--batch", "file.ase"] error = CommandExecutionError(command, 1, "Command failed") assert "Command failed with exit code 1" in str(error) assert error.details["command"] == command assert error.details["return_code"] == 1 assert error.details["stderr"] == "Command failed" class TestLuaScriptError: """Tests for LuaScriptError.""" def test_script_error(self): """Test Lua script error.""" script = "local x = nil\nx:method()" error_msg = "attempt to index a nil value" error = LuaScriptError(script, error_msg) assert f"Lua script execution failed: {error_msg}" in str(error) assert error.details["script"] == script assert error.details["error"] == error_msg def test_long_script_truncation(self): """Test that long scripts are truncated in error message.""" long_script = "x" * 200 error = LuaScriptError(long_script, "error") # Should truncate script in message but keep full script in details assert len(error.details["script"]) == 200 assert "..." in str(error) class TestFileNotFoundError: """Tests for custom FileNotFoundError.""" def test_file_not_found(self): """Test file not found error.""" error = AsepriteFileNotFoundError("/path/to/missing.ase") assert "File not found: '/path/to/missing.ase'" in str(error) assert error.details["file_path"] == "/path/to/missing.ase" class TestValidationError: """Tests for ValidationError.""" def test_validation_error(self): """Test validation error.""" error = ValidationError("width", -10, "Must be positive") assert "Validation failed for 'width': Must be positive" in str(error) assert error.details["field"] == "width" assert error.details["value"] == -10 assert error.details["reason"] == "Must be positive" def test_complex_value(self): """Test validation error with complex value.""" value = {"x": 10, "y": 20} error = ValidationError("coordinates", value, "Invalid format") assert "Validation failed for 'coordinates'" in str(error) assert error.details["value"] == value class TestSecurityError: """Tests for SecurityError.""" def test_security_error(self): """Test security error.""" error = SecurityError("Path traversal attempt", "../../../etc/passwd") assert "Security violation: Path traversal attempt" in str(error) assert error.details["attempted_action"] == "../../../etc/passwd"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ext-sakamoro/AsepriteMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server