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

@ -87,12 +87,15 @@ class PyPIStatsClient:
def _get_cache_key(self, endpoint: str, package_name: str = "", **params) -> str:
"""Generate cache key for API data."""
param_str = "&".join(f"{k}={v}" for k, v in sorted(params.items()) if v is not None)
param_str = "&".join(
f"{k}={v}" for k, v in sorted(params.items()) if v is not None
)
return f"{endpoint}:{package_name}:{param_str}"
def _is_cache_valid(self, cache_entry: dict[str, Any]) -> bool:
"""Check if cache entry is still valid."""
import time
return time.time() - cache_entry.get("timestamp", 0) < self._cache_ttl
async def _make_request(self, url: str) -> dict[str, Any]:
@ -187,13 +190,16 @@ class PyPIStatsClient:
if period and period != "all":
url += f"?period={period}"
logger.info(f"Fetching recent downloads for: {normalized_name} (period: {period})")
logger.info(
f"Fetching recent downloads for: {normalized_name} (period: {period})"
)
try:
data = await self._make_request(url)
# Cache the result
import time
self._cache[cache_key] = {"data": data, "timestamp": time.time()}
return data
@ -235,19 +241,24 @@ class PyPIStatsClient:
if mirrors is not None:
url += f"?mirrors={'true' if mirrors else 'false'}"
logger.info(f"Fetching overall downloads for: {normalized_name} (mirrors: {mirrors})")
logger.info(
f"Fetching overall downloads for: {normalized_name} (mirrors: {mirrors})"
)
try:
data = await self._make_request(url)
# Cache the result
import time
self._cache[cache_key] = {"data": data, "timestamp": time.time()}
return data
except Exception as e:
logger.error(f"Failed to fetch overall downloads for {normalized_name}: {e}")
logger.error(
f"Failed to fetch overall downloads for {normalized_name}: {e}"
)
raise
def clear_cache(self):