name: Test with PyPI

on: [pull_request, workflow_dispatch]

env:
  PYTHONUNBUFFERED: 1

jobs:

  # Test against PyPI packages, using pytest
  test-with-pypi:
    strategy:
      matrix:
        os: ['ubuntu-latest']
        python-version: ['3.8', '3.10', '3.11']

    runs-on: ${{ matrix.os }}
    steps:
      - name: Clone the Envisage source
        uses: actions/checkout@v4
      - name: Install packages for Qt support
        uses: ./.github/actions/install-qt-support
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install packages needed for testing
        run: python -m pip install pytest
      - name: Install toolkit
        # See https://github.com/enthought/envisage/issues/528 for restrictions
        run: python -m pip install 'pyside6<6.4'
        if: matrix.python-version != '3.11'
      - name: Install package under test
        run: python -m pip install .
      - name: List installed packages
        run: python -m pip list
      - name: Run tests (Ubuntu)
        if: matrix.os == 'ubuntu-latest'
        run: xvfb-run -a python -m pytest
      - name: Run tests (not Ubuntu)
        if: matrix.os != 'ubuntu-latest'
        run: python -m pytest
