name: Python Tests

on:
  push:
    branches: [ main, 'prep-*' ]
  pull_request:
    branches: [ main, 'prep-*' ]

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ['3.10', '3.11', '3.12', '3.13']
      fail-fast: false

    steps:
    - uses: actions/checkout@v4

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}
        cache: 'pip'

    - name: Install uv
      run: |
        python -m pip install --upgrade pip
        pip install uv

    - name: Cache uv dependencies
      uses: actions/cache@v4
      with:
        path: ~/.cache/uv
        key: ${{ runner.os }}-uv-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml') }}
        restore-keys: |
          ${{ runner.os }}-uv-${{ matrix.python-version }}-

    - name: Install dependencies
      run: |
        uv venv
        source .venv/bin/activate
        uv pip install -e ".[dev]"

    - name: Run linting
      run: |
        source .venv/bin/activate
        uv run pre-commit run --all-files

    - name: Setup configuration file
      run: |
        cp config.example.yaml config.yaml

    - name: Download NLTK data
      run: |
        source .venv/bin/activate
        python -c "import nltk; nltk.download('punkt_tab')"

    - name: Run tests
      run: |
        source .venv/bin/activate
        pytest tests/ -p no:warnings 