fix: resolve all lint issues and fix failing tests

- Fix blank line whitespace issues (W293) using ruff --unsafe-fixes
- Reformat code using ruff format for consistent styling
- Fix analyze_package_quality function to return list[Message] instead of string
- Add missing 'assessment' keyword to package analysis template
- Update tests to use real prompt functions instead of mocks for structure validation
- Fix import ordering in test files
- All 64 tests now pass with 47% code coverage

Signed-off-by: longhao <hal.long@outlook.com>
This commit is contained in:
longhao 2025-05-29 18:38:10 +08:00 committed by Hal
parent d63ef02ef3
commit a28d999958
18 changed files with 554 additions and 390 deletions

View file

@ -36,14 +36,11 @@ class TestDependencyResolver:
"name": "test-package",
"version": "1.0.0",
"requires_python": ">=3.8",
"requires_dist": [
"requests>=2.25.0",
"click>=8.0.0"
]
"requires_dist": ["requests>=2.25.0", "click>=8.0.0"],
}
}
with patch('pypi_query_mcp.core.PyPIClient') as mock_client_class:
with patch("pypi_query_mcp.core.PyPIClient") as mock_client_class:
mock_client = AsyncMock()
mock_client_class.return_value.__aenter__.return_value = mock_client
mock_client.get_package_info.return_value = mock_package_data
@ -64,19 +61,18 @@ class TestDependencyResolver:
"requires_python": ">=3.8",
"requires_dist": [
"requests>=2.25.0",
"typing-extensions>=4.0.0; python_version<'3.10'"
]
"typing-extensions>=4.0.0; python_version<'3.10'",
],
}
}
with patch('pypi_query_mcp.core.PyPIClient') as mock_client_class:
with patch("pypi_query_mcp.core.PyPIClient") as mock_client_class:
mock_client = AsyncMock()
mock_client_class.return_value.__aenter__.return_value = mock_client
mock_client.get_package_info.return_value = mock_package_data
result = await resolver.resolve_dependencies(
"test-package",
python_version="3.11"
"test-package", python_version="3.11"
)
assert result["python_version"] == "3.11"
@ -90,21 +86,17 @@ class TestDependencyResolver:
"name": "test-package",
"version": "1.0.0",
"requires_python": ">=3.8",
"requires_dist": [
"requests>=2.25.0",
"pytest>=6.0.0; extra=='test'"
]
"requires_dist": ["requests>=2.25.0", "pytest>=6.0.0; extra=='test'"],
}
}
with patch('pypi_query_mcp.core.PyPIClient') as mock_client_class:
with patch("pypi_query_mcp.core.PyPIClient") as mock_client_class:
mock_client = AsyncMock()
mock_client_class.return_value.__aenter__.return_value = mock_client
mock_client.get_package_info.return_value = mock_package_data
result = await resolver.resolve_dependencies(
"test-package",
include_extras=["test"]
"test-package", include_extras=["test"]
)
assert result["include_extras"] == ["test"]
@ -118,19 +110,16 @@ class TestDependencyResolver:
"name": "test-package",
"version": "1.0.0",
"requires_python": ">=3.8",
"requires_dist": ["requests>=2.25.0"]
"requires_dist": ["requests>=2.25.0"],
}
}
with patch('pypi_query_mcp.core.PyPIClient') as mock_client_class:
with patch("pypi_query_mcp.core.PyPIClient") as mock_client_class:
mock_client = AsyncMock()
mock_client_class.return_value.__aenter__.return_value = mock_client
mock_client.get_package_info.return_value = mock_package_data
result = await resolver.resolve_dependencies(
"test-package",
max_depth=1
)
result = await resolver.resolve_dependencies("test-package", max_depth=1)
assert result["summary"]["max_depth"] <= 1
@ -142,11 +131,11 @@ class TestDependencyResolver:
"name": "test-package",
"version": "1.0.0",
"requires_python": ">=3.8",
"requires_dist": ["requests>=2.25.0"]
"requires_dist": ["requests>=2.25.0"],
}
}
with patch('pypi_query_mcp.core.PyPIClient') as mock_client_class:
with patch("pypi_query_mcp.core.PyPIClient") as mock_client_class:
mock_client = AsyncMock()
mock_client_class.return_value.__aenter__.return_value = mock_client
mock_client.get_package_info.return_value = mock_package_data
@ -167,11 +156,11 @@ class TestDependencyResolver:
"name": "test-package",
"version": "1.0.0",
"requires_python": ">=3.8",
"requires_dist": ["test-package>=1.0.0"] # Self-dependency
"requires_dist": ["test-package>=1.0.0"], # Self-dependency
}
}
with patch('pypi_query_mcp.core.PyPIClient') as mock_client_class:
with patch("pypi_query_mcp.core.PyPIClient") as mock_client_class:
mock_client = AsyncMock()
mock_client_class.return_value.__aenter__.return_value = mock_client
mock_client.get_package_info.return_value = mock_package_data
@ -183,10 +172,12 @@ class TestDependencyResolver:
@pytest.mark.asyncio
async def test_package_not_found_handling(self, resolver):
"""Test handling of packages that are not found."""
with patch('pypi_query_mcp.core.PyPIClient') as mock_client_class:
with patch("pypi_query_mcp.core.PyPIClient") as mock_client_class:
mock_client = AsyncMock()
mock_client_class.return_value.__aenter__.return_value = mock_client
mock_client.get_package_info.side_effect = PackageNotFoundError("Package not found")
mock_client.get_package_info.side_effect = PackageNotFoundError(
"Package not found"
)
with pytest.raises(PackageNotFoundError):
await resolver.resolve_dependencies("nonexistent-package")