- Fix test_ingestion.py: SCSS token names, empty CSS handling, JSON error type - Fix test_dss_mcp_commands.py: Use relative path, update tool count to 48 - Add test_json_store.py: 22 tests covering cache, projects, tokens, components, activity log, teams, sync history, and stats - Add venv/ to .gitignore All 215 tests passing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
"""
|
|
Tests for token ingestion from various sources.
|
|
"""
|
|
|
|
import pytest
|
|
import json
|
|
from tools.ingest.css import CSSTokenSource
|
|
from tools.ingest.scss import SCSSTokenSource
|
|
from tools.ingest.json_tokens import JSONTokenSource
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_css_ingestion(sample_css):
|
|
"""Test CSS custom property extraction."""
|
|
parser = CSSTokenSource()
|
|
result = await parser.extract(sample_css)
|
|
|
|
assert len(result.tokens) >= 5
|
|
assert any(t.name == "color.primary" for t in result.tokens)
|
|
assert any(t.value == "#3B82F6" for t in result.tokens)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_scss_ingestion(sample_scss):
|
|
"""Test SCSS variable extraction."""
|
|
parser = SCSSTokenSource()
|
|
result = await parser.extract(sample_scss)
|
|
|
|
assert len(result.tokens) >= 4
|
|
# SCSS converts $primary-color to primary.color (dashes to dots)
|
|
assert any(t.name == "primary.color" for t in result.tokens)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_json_ingestion(sample_json_tokens):
|
|
"""Test JSON token extraction (W3C format)."""
|
|
parser = JSONTokenSource()
|
|
result = await parser.extract(json.dumps(sample_json_tokens))
|
|
|
|
assert len(result.tokens) >= 6
|
|
# Check color tokens
|
|
primary_tokens = [t for t in result.tokens if "primary" in t.name]
|
|
assert len(primary_tokens) >= 2
|
|
|
|
# Check spacing tokens
|
|
spacing_tokens = [t for t in result.tokens if "spacing" in t.name]
|
|
assert len(spacing_tokens) == 3
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_empty_css():
|
|
"""Test handling of empty CSS."""
|
|
parser = CSSTokenSource()
|
|
# Use CSS syntax marker so parser detects as content, not file path
|
|
result = await parser.extract(":root {}")
|
|
|
|
assert len(result.tokens) == 0
|
|
assert result.name
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_invalid_json():
|
|
"""Test handling of invalid JSON."""
|
|
parser = JSONTokenSource()
|
|
|
|
# Parser wraps JSONDecodeError in ValueError
|
|
with pytest.raises(ValueError, match="Invalid JSON"):
|
|
await parser.extract("invalid json{")
|