name: Python tests

on: [pull_request]

jobs:
  build-ubuntu:
    runs-on: ubuntu-latest
    env:
      UV_HTTP_TIMEOUT: 600 # max 10min to install deps

    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.10", "3.12"]

    steps:
      - uses: actions/checkout@v2
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}

      # Setup venv
      - name: Setup venv + uv
        run: |
          pip install --upgrade uv
          uv venv

      # Install dependencies
      - name: Install dependencies
        run: |
          uv pip install "smolagents[test] @ ."

      # Run all tests separately for individual feedback
      # Use 'if success() || failure()' so that all tests are run even if one failed
      # See https://stackoverflow.com/a/62112985
      - name: Import tests
        run: |
          uv run pytest ./tests/test_import.py
        if: ${{ success() || failure() }}

      - name: Agent tests
        run: |
          uv run pytest ./tests/test_agents.py
        if: ${{ success() || failure() }}

      - name: Default tools tests
        run: |
          uv run pytest ./tests/test_default_tools.py
        if: ${{ success() || failure() }}

      # - name: Docs tests # Disabled for now (slow test + requires API keys)
      #   run: |
      #     uv run pytest ./tests/test_all_docs.py

      - name: Final answer tests
        run: |
          uv run pytest ./tests/test_final_answer.py
        if: ${{ success() || failure() }}

      - name: Models tests
        run: |
          uv run pytest ./tests/test_models.py
        if: ${{ success() || failure() }}

      - name: Memory tests
        run: |
          uv run pytest ./tests/test_memory.py
        if: ${{ success() || failure() }}

      - name: Monitoring tests
        run: |
          uv run pytest ./tests/test_monitoring.py
        if: ${{ success() || failure() }}

      - name: Python interpreter tests
        run: |
          uv run pytest ./tests/test_python_interpreter.py
        if: ${{ success() || failure() }}

      - name: Search tests
        run: |
          uv run pytest ./tests/test_search.py
        if: ${{ success() || failure() }}

      - name: Tools tests
        run: |
          uv run pytest ./tests/test_tools.py
        if: ${{ success() || failure() }}

      - name: Types tests
        run: |
          uv run pytest ./tests/test_types.py
        if: ${{ success() || failure() }}

      - name: Utils tests
        run: |
          uv run pytest ./tests/test_utils.py
        if: ${{ success() || failure() }}

      - name: Function type hints utils tests
        run: |
          uv run pytest ./tests/test_function_type_hints_utils.py
        if: ${{ success() || failure() }}
