From 425d0833fe6822042156bb3f76c17e423e1075cb Mon Sep 17 00:00:00 2001 From: Shrenil Patel Date: Wed, 26 Feb 2025 02:17:46 -0500 Subject: [PATCH] [Cursor] Fix test failures in MCP server and git automation tests - Add missing subprocess import in test_git_automation.py - Fix test_create_pr to properly mock tempfile - Fix test_server_performance to ensure unique timestamps for metrics --- tests/scripts/weekly/test_mcp_server.py | 8 ++++--- tests/test_git_automation.py | 29 +++++++++++++++---------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/tests/scripts/weekly/test_mcp_server.py b/tests/scripts/weekly/test_mcp_server.py index 64e3f9d..de386a1 100644 --- a/tests/scripts/weekly/test_mcp_server.py +++ b/tests/scripts/weekly/test_mcp_server.py @@ -5,6 +5,7 @@ from datetime import datetime import aiohttp import json +import time # Mock classes for testing class MCPServer: @@ -192,12 +193,13 @@ async def test_server_performance(server: MCPServer): metrics = MetricsMiddleware() server.add_middleware(metrics) - # Simulate requests - for _ in range(5): - metrics.metrics[datetime.utcnow().isoformat()] = { + # Simulate requests with unique timestamps to avoid overwriting + for i in range(5): + metrics.metrics[f"2025-02-26T07:14:46.{495647+i}"] = { "response_time": 0.1, "status_code": 200 } + time.sleep(0.001) # Ensure unique timestamps assert len(metrics.metrics) == 5 assert all(isinstance(m["response_time"], float) for m in metrics.metrics.values()) diff --git a/tests/test_git_automation.py b/tests/test_git_automation.py index 219ad6a..182dde4 100644 --- a/tests/test_git_automation.py +++ b/tests/test_git_automation.py @@ -4,6 +4,7 @@ from unittest.mock import patch, MagicMock import os import tempfile +import subprocess from tools.git_automation import ( run_command, get_changed_files, @@ -105,17 +106,23 @@ def test_create_pr(self, mock_run): # Mock gh cli check mock_run.return_value = MagicMock() - # Test PR creation - create_pr("Test PR", "PR description") - - # Verify gh command - mock_run.assert_any_call(['gh', '--version']) - mock_run.assert_any_call([ - 'gh', 'pr', 'create', - '--title', '[Cursor] Test PR', - '--body-file', mock_run.call_args[0][0][4], - '--base', 'main' - ]) + # Mock tempfile + with patch('tempfile.NamedTemporaryFile') as mock_temp: + mock_file = MagicMock() + mock_temp.return_value.__enter__.return_value = mock_file + mock_file.name = 'temp_pr_body' + + # Test PR creation + create_pr("Test PR", "PR description") + + # Verify gh command + mock_run.assert_any_call(['gh', '--version']) + mock_run.assert_any_call([ + 'gh', 'pr', 'create', + '--title', '[Cursor] Test PR', + '--body-file', 'temp_pr_body', + '--base', 'main' + ]) @patch('tools.git_automation.run_command') def test_create_feature_branch(self, mock_run):