Skip to content

Agent Mesh

fyx python testing

Antonio Ojea48ff1c4359eb
diff --git a/.gitignore b/.gitignore
index 4dec4c12..165aa1ef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,4 +35,5 @@ go.work.sum
bin/
tests/e2e/logs/
tests/integration/scratch/
-__pycache__/
\ No newline at end of file
+__pycache__/
+.venv/
diff --git a/Makefile b/Makefile
index 58dea290..6d66ff9b 100644
--- a/Makefile
+++ b/Makefile
@@ -20,6 +20,15 @@ clean:
test:
CGO_ENABLED=1 go test -v -race -count 1 ./...
+.PHONY: test-python test-python-container
+test-python:
+ python3 -m venv sam-mcp-python/.venv
+ ./sam-mcp-python/.venv/bin/pip install -e ./sam-mcp-python[test]
+ ./sam-mcp-python/.venv/bin/pytest sam-mcp-python/tests/unit
+
+test-python-container:
+ docker run --rm -v $(REPO_ROOT)/sam-mcp-python:/app -w /app python:3.12 bash -c "pip install -e .[test] && pytest tests/unit"
+
e2e-test:
bats --verbose-run tests/e2e/
diff --git a/sam-mcp-python/tests/unit/test_unit.py b/sam-mcp-python/tests/unit/test_unit.py
index 965c7c8e..feb08c17 100644
--- a/sam-mcp-python/tests/unit/test_unit.py
+++ b/sam-mcp-python/tests/unit/test_unit.py
@@ -1,69 +1,9 @@
import asyncio
-import json
import pytest
from unittest.mock import AsyncMock, MagicMock, patch
-from sam_mcp.protocol import Protocol, JsonRpcError
-from sam_mcp.transport import SamTransport
from sam_mcp.client import SamClient
from sam_mcp.adapters.langchain import get_langchain_tools
-# Protocol Tests
-def test_protocol_create_request():
- req = Protocol.create_request("test_method", {"param": "value"}, 1)
- assert req == {
- "jsonrpc": "2.0",
- "method": "test_method",
- "params": {"param": "value"},
- "id": 1
- }
-
-def test_protocol_create_response():
- resp = Protocol.create_response(1, {"result": "ok"})
- assert resp == {
- "jsonrpc": "2.0",
- "id": 1,
- "result": {"result": "ok"}
- }
-
-def test_protocol_parse_message():
- msg = '{"jsonrpc": "2.0", "method": "test", "id": 1}'
- parsed = Protocol.parse_message(msg)
- assert parsed["method"] == "test"
-
-def test_protocol_parse_invalid_json():
- with pytest.raises(JsonRpcError) as excinfo:
- Protocol.parse_message("{invalid}")
- assert excinfo.value.code == -32700
-
-# Transport Tests
-async def test_transport_send_message():
- transport = SamTransport("/tmp/test.sock")
-
- mock_reader = AsyncMock()
- # Simulate HTTP response
- mock_reader.readline.side_effect = [
- b"HTTP/1.1 200 OK\r\n",
- b"Content-Length: 15\r\n",
- b"\r\n"
- ]
- mock_reader.readexactly.return_value = b'{"result":"ok"}'
-
- mock_writer = MagicMock()
- mock_writer.drain = AsyncMock()
-
- transport.reader = mock_reader
- transport.writer = mock_writer
-
- resp = await transport.send_message('{"method":"test"}')
- assert resp == '{"result":"ok"}'
-
- # Verify HTTP request was sent
- args, _ = mock_writer.write.call_args
- request_bytes = args[0]
- assert b"POST /mcp HTTP/1.1" in request_bytes
- assert b"Content-Length: 17" in request_bytes
-
# Client Tests
@pytest.mark.asyncio
async def test_client_get_tools():