terrylica

ckvd-testing

Run tests for crypto-kline-vision-data with proper markers and coverage. TRIGGERS - write tests, run tests, pytest, test coverage, unit tests, integration tests, mocking patterns.

terrylica 0 Updated 3mo ago

Resources

3
GitHub

Install

npx skillscat add terrylica/crypto-kline-vision-data/ckvd-testing

Install via the SkillsCat registry.

SKILL.md

Testing Crypto Kline Vision Data

Run tests for: $ARGUMENTS

Test Workflow Checklist

Copy this checklist and track progress:

Test Progress:
- [ ] Step 1: Run lint check (ruff check)
- [ ] Step 2: Run unit tests (fast, no network)
- [ ] Step 3: Verify import works
- [ ] Step 4: Run integration tests (if changing APIs)
- [ ] Step 5: Check coverage (if adding new code)

Step 1: uv run -p 3.13 ruff check --fix .
Step 2: uv run -p 3.13 pytest tests/unit/ -v
Step 3: uv run -p 3.13 python -c "from ckvd import CryptoKlineVisionData; print('OK')"
Step 4: uv run -p 3.13 pytest tests/integration/ -v (if needed)
Step 5: uv run -p 3.13 pytest tests/unit/ --cov=src/ckvd

Test Organization

tests/
├── unit/                    # Fast, no network (~0.5s)
├── integration/             # External services
├── okx/                     # OKX API integration
└── fcp_pm/                  # FCP protocol tests

Running Tests

Unit Tests (Fast)

# Quick validation
uv run -p 3.13 pytest tests/unit/ -v

# With coverage
uv run -p 3.13 pytest tests/unit/ --cov=src/ckvd --cov-report=term-missing

Integration Tests

# Requires network access
uv run -p 3.13 pytest tests/integration/ -v

# OKX-specific tests
uv run -p 3.13 pytest tests/okx/ -m okx -v

All Tests

uv run -p 3.13 pytest tests/ -v

Test Markers

Marker Purpose
@pytest.mark.integration Tests that call external APIs
@pytest.mark.okx OKX-specific tests
@pytest.mark.serial Must run sequentially

Writing New Tests

import pytest
from ckvd import CryptoKlineVisionData, DataProvider, MarketType

class TestMyFeature:
    """Tests for MyFeature."""

    def test_basic_functionality(self):
        """Verify basic operation."""
        # Arrange
        manager = CryptoKlineVisionData.create(DataProvider.BINANCE, MarketType.SPOT)

        # Act
        result = manager.some_method()

        # Assert
        assert result is not None
        manager.close()

    @pytest.mark.integration
    def test_with_network(self):
        """Test requiring network access."""
        # Mark with @pytest.mark.integration for external calls
        pass

Mocking HTTP Calls

from unittest.mock import patch, MagicMock

@patch("ckvd.core.sync.crypto_kline_vision_data.FSSpecVisionHandler")
@patch("ckvd.core.sync.crypto_kline_vision_data.UnifiedCacheManager")
def test_with_mocks(self, mock_cache, mock_handler):
    mock_handler.return_value = MagicMock()
    mock_cache.return_value = MagicMock()
    # Test logic...

Examples

Practical test examples:

  • @examples/unit-test-patterns.md - Basic tests, fixtures, mocking
  • @examples/integration-test-patterns.md - API tests, markers, FCP testing

Helper Scripts

Quick test runner:

# Run all quick checks (lint + unit tests + import)
./docs/skills/ckvd-testing/scripts/run_quick_tests.sh

# Run with test pattern filter
./docs/skills/ckvd-testing/scripts/run_quick_tests.sh test_timestamp

TodoWrite Task Templates

Template A: Run Quick Test

1. Run ruff lint check (uv run -p 3.13 ruff check --fix .)
2. Run unit tests (uv run -p 3.13 pytest tests/unit/ -v)
3. Verify package import works
4. Report pass/fail summary

Template B: Add Unit Test for Feature

1. Identify module and function under test
2. Read existing test patterns in tests/unit/ for the module
3. Write test class following Arrange/Act/Assert pattern
4. Mock external services (FSSpecVisionHandler, UnifiedCacheManager)
5. Add appropriate markers (@pytest.mark.integration if needed)
6. Run new tests and verify they pass
7. Check coverage for new code

Template C: Check Coverage

1. Run unit tests with coverage (uv run -p 3.13 pytest tests/unit/ --cov=src/ckvd --cov-report=term-missing)
2. Identify modules below target coverage
3. Write tests for uncovered paths
4. Re-run coverage to verify improvement

Post-Change Checklist

After modifying this skill:

  • Test commands use uv run -p 3.13 and correct paths
  • Test organization diagram matches actual directory structure
  • Mocking examples match actual import paths
  • @-links to references/ and examples/ resolve
  • Append changes to evolution-log.md

Detailed References

For deeper information, see:

  • @references/fixtures.md - Pytest fixtures and auto-cleanup patterns
  • @references/coverage.md - Coverage configuration and thresholds
  • @references/mocking-patterns.md - CKVD-specific mocking patterns
  • @references/markers.md - Pytest markers and test categorization
  • @references/evolution-log.md - Skill change history