Skip to content

Commit 0c9a21e

Browse files
committed
Fix lint errors and review feedback in test suite
- Remove unused pytest imports from 6 Python test files - Remove unused Impl/BaseRepository imports from test_repositories.py - Remove unused vi/getCounts/getSelectedValuesForCategory from filters-extended.test.ts - Fix global -> globalThis in SpecTabs.test.tsx for ESLint compatibility - Add configurable: true to window.location mock in SpecTabs.test.tsx - Use clear=True in patch.dict for test isolation in test_config_resolve.py - Use precise <loc> assertions in test_seo_helpers.py to fix CodeQL URL warnings - Fix import sorting via ruff auto-fix - Remove unused datetime import in test_insights_helpers.py https://claude.ai/code/session_01KhAhJKpEoqCzmWzcALSfW6
1 parent b1f5ffb commit 0c9a21e

File tree

10 files changed

+25
-49
lines changed

10 files changed

+25
-49
lines changed

app/src/components/SpecTabs.test.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ vi.mock('../constants', () => ({
1717
beforeEach(() => {
1818
vi.restoreAllMocks();
1919
// Mock fetch globally - return tag counts
20-
global.fetch = vi.fn().mockResolvedValue({
20+
globalThis.fetch = vi.fn().mockResolvedValue({
2121
ok: true,
2222
json: () =>
2323
Promise.resolve({
@@ -362,7 +362,7 @@ describe('SpecTabs', () => {
362362
expect(screen.getByText('scatter')).toBeInTheDocument();
363363

364364
// Fetch is mocked for tag counts (may be called if cache is empty)
365-
expect(global.fetch).toBeDefined();
365+
expect(globalThis.fetch).toBeDefined();
366366
});
367367

368368
// -------------------------------------------------------
@@ -409,15 +409,18 @@ describe('SpecTabs', () => {
409409
it('fires onTrackEvent and navigates on tag click', async () => {
410410
const user = userEvent.setup();
411411
const onTrackEvent = vi.fn();
412-
// Mock window.location.href setter
412+
// Mock window.location.href setter to prevent jsdom navigation errors.
413+
// Use configurable: true so the property can be redefined if needed.
413414
const hrefSetter = vi.fn();
414415
Object.defineProperty(window, 'location', {
415416
value: { href: '' },
416417
writable: true,
418+
configurable: true,
417419
});
418420
Object.defineProperty(window.location, 'href', {
419421
set: hrefSetter,
420422
get: () => '',
423+
configurable: true,
421424
});
422425

423426
render(

app/src/utils/filters-extended.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { describe, it, expect, vi } from 'vitest';
1+
import { describe, it, expect } from 'vitest';
22
import {
3-
getCounts,
4-
getSelectedValuesForCategory,
53
getAvailableValues,
64
getAvailableValuesForGroup,
75
getSearchResults,

tests/unit/api/test_analytics_extended.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
Covers edge cases and additional platform patterns.
55
"""
66

7-
import pytest
8-
9-
from api.analytics import (
10-
PLATFORM_PATTERNS,
11-
_detect_whatsapp_variant,
12-
detect_platform,
13-
)
7+
from api.analytics import PLATFORM_PATTERNS, _detect_whatsapp_variant, detect_platform
148

159

1610
class TestDetectWhatsappVariant:

tests/unit/api/test_insights_helpers.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,9 @@
55
that don't require database or HTTP setup.
66
"""
77

8-
from datetime import datetime, timezone
8+
from datetime import timezone
99

10-
import pytest
11-
12-
from api.routers.insights import (
13-
_collect_impl_tags,
14-
_flatten_tags,
15-
_parse_iso,
16-
_score_bucket,
17-
)
10+
from api.routers.insights import _collect_impl_tags, _flatten_tags, _parse_iso, _score_bucket
1811

1912

2013
class TestScoreBucket:

tests/unit/api/test_plots_helpers.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
from unittest.mock import MagicMock
88

9-
import pytest
10-
119
from api.routers.plots import (
1210
_build_cache_key,
1311
_build_impl_lookup,

tests/unit/api/test_schemas.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
Validates schema creation, defaults, and serialization.
55
"""
66

7-
import pytest
8-
97
from api.schemas import (
108
FilterCountsResponse,
119
FilteredPlotsResponse,

tests/unit/api/test_seo_helpers.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
from datetime import datetime
88
from unittest.mock import MagicMock
99

10-
import pytest
11-
1210
from api.routers.seo import BOT_HTML_TEMPLATE, _build_sitemap_xml, _lastmod
1311

1412

@@ -36,11 +34,11 @@ def test_empty_specs(self) -> None:
3634
result = _build_sitemap_xml([])
3735
assert '<?xml version="1.0"' in result
3836
assert "<urlset" in result
39-
assert "https://pyplots.ai/" in result
40-
assert "https://pyplots.ai/catalog" in result
41-
assert "https://pyplots.ai/mcp" in result
42-
assert "https://pyplots.ai/legal" in result
43-
assert "https://pyplots.ai/stats" in result
37+
assert "<loc>https://pyplots.ai/</loc>" in result
38+
assert "<loc>https://pyplots.ai/catalog</loc>" in result
39+
assert "<loc>https://pyplots.ai/mcp</loc>" in result
40+
assert "<loc>https://pyplots.ai/legal</loc>" in result
41+
assert "<loc>https://pyplots.ai/stats</loc>" in result
4442
assert "</urlset>" in result
4543

4644
def test_spec_with_impls(self) -> None:
@@ -141,8 +139,9 @@ def test_template_has_required_meta_tags(self) -> None:
141139
assert "Test Description" in result
142140

143141
def test_template_has_canonical(self) -> None:
142+
url = "https://pyplots.ai/"
144143
result = BOT_HTML_TEMPLATE.format(
145-
title="t", description="d", image="i", url="https://pyplots.ai/"
144+
title="t", description="d", image="i", url=url
146145
)
147146
assert 'rel="canonical"' in result
148-
assert "https://pyplots.ai/" in result
147+
assert url in result

tests/unit/automation/scripts/test_sync_helpers.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@
44
Focuses on _validate_quality_score, _parse_markdown_section, and _validate_spec_id.
55
"""
66

7-
import pytest
8-
9-
from automation.scripts.sync_to_postgres import (
10-
_parse_markdown_section,
11-
_validate_quality_score,
12-
_validate_spec_id,
13-
)
7+
from automation.scripts.sync_to_postgres import _parse_markdown_section, _validate_quality_score, _validate_spec_id
148

159

1610
class TestValidateQualityScore:

tests/unit/core/database/test_repositories.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
import pytest
88
from sqlalchemy.ext.asyncio import AsyncSession
99

10-
from core.database.models import Impl, Library, Spec
10+
from core.database.models import Library, Spec
1111
from core.database.repositories import (
1212
IMPL_UPDATABLE_FIELDS,
1313
LIBRARY_UPDATABLE_FIELDS,
1414
SPEC_UPDATABLE_FIELDS,
15-
BaseRepository,
1615
ImplRepository,
1716
LibraryRepository,
1817
SpecRepository,

tests/unit/core/test_config_resolve.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TestResolveModel:
1717
@pytest.fixture
1818
def settings(self) -> Settings:
1919
"""Create a Settings instance with default model mappings."""
20-
with patch.dict("os.environ", {}, clear=False):
20+
with patch.dict("os.environ", {}, clear=True):
2121
return Settings(
2222
cli_model_claude_small="claude-haiku",
2323
cli_model_claude_medium="claude-sonnet",
@@ -50,24 +50,24 @@ def test_gemini_medium(self, settings: Settings) -> None:
5050

5151
def test_unknown_cli_returns_tier(self) -> None:
5252
"""Unknown CLI should return the tier unchanged (pass-through)."""
53-
with patch.dict("os.environ", {}, clear=False):
53+
with patch.dict("os.environ", {}, clear=True):
5454
s = Settings()
5555
assert s.resolve_model("unknown-cli", "small") == "small"
5656

5757
def test_unknown_tier_returns_tier(self) -> None:
5858
"""Unknown tier should return the tier unchanged (pass-through)."""
59-
with patch.dict("os.environ", {}, clear=False):
59+
with patch.dict("os.environ", {}, clear=True):
6060
s = Settings()
6161
assert s.resolve_model("claude", "xlarge") == "xlarge"
6262

6363
def test_unknown_cli_and_tier(self) -> None:
64-
with patch.dict("os.environ", {}, clear=False):
64+
with patch.dict("os.environ", {}, clear=True):
6565
s = Settings()
6666
assert s.resolve_model("unknown", "unknown") == "unknown"
6767

6868
def test_exact_model_name_passthrough(self) -> None:
6969
"""When tier is an exact model name, it's returned as-is."""
70-
with patch.dict("os.environ", {}, clear=False):
70+
with patch.dict("os.environ", {}, clear=True):
7171
s = Settings()
7272
result = s.resolve_model("claude", "claude-3-opus-20240229")
7373
assert result == "claude-3-opus-20240229"

0 commit comments

Comments
 (0)