Fix test cases and improve MATLAB parity #77
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tests | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| env: | |
| # Set MATLAB batch licensing token for private repos or when using MATLAB Engine | |
| MLM_LICENSE_TOKEN: ${{ secrets.MATLAB_BATCH_TOKEN }} | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| test: | |
| name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-22.04, macos-latest, windows-latest] | |
| python-version: ["3.10", "3.11", "3.12", "3.13"] | |
| include: | |
| # Test on macOS and Windows for Python 3.12 only | |
| - os: macos-latest | |
| python-version: "3.12" | |
| - os: windows-latest | |
| python-version: "3.12" | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| submodules: 'recursive' | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v4 | |
| with: | |
| enable-cache: true | |
| cache-dependency-glob: "pyproject.toml" | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Determine MATLAB availability | |
| id: matlab-availability | |
| shell: bash | |
| run: | | |
| # Enable MATLAB if batch license token is available | |
| if [[ -n "$MLM_LICENSE_TOKEN" ]]; then | |
| available=true | |
| else | |
| available=false | |
| fi | |
| echo "available=${available}" >> "$GITHUB_OUTPUT" | |
| echo "EEGPREP_SKIP_MATLAB=1" >> "$GITHUB_ENV" | |
| - name: Set up MATLAB | |
| if: steps.matlab-availability.outputs.available == 'true' | |
| uses: matlab-actions/setup-matlab@v2 | |
| with: | |
| release: R2024b | |
| products: MATLAB | |
| - name: Locate MATLAB root | |
| if: steps.matlab-availability.outputs.available == 'true' | |
| shell: bash | |
| run: | | |
| MATLAB_ROOT=$(python - <<'PY' | |
| import os | |
| from pathlib import Path | |
| tool_cache = Path(os.environ.get("RUNNER_TOOL_CACHE", "")) / "MATLAB" | |
| candidates = sorted(tool_cache.glob("*/x64")) | |
| if not candidates: | |
| raise SystemExit(f"No MATLAB installation found under {tool_cache}") | |
| print(candidates[-1]) | |
| PY | |
| ) | |
| echo "MATLAB_ROOT=$MATLAB_ROOT" >> $GITHUB_ENV | |
| echo "$MATLAB_ROOT/bin" >> $GITHUB_PATH | |
| - name: Install Python MATLAB Engine | |
| if: steps.matlab-availability.outputs.available == 'true' | |
| shell: bash | |
| run: | | |
| python -m pip install "${MATLAB_ROOT}/extern/engines/python" | |
| - name: Check MATLAB Engine availability | |
| if: steps.matlab-availability.outputs.available == 'true' | |
| shell: bash | |
| run: | | |
| if python - <<'PY' | |
| import matlab.engine | |
| eng = matlab.engine.start_matlab() | |
| eng.quit() | |
| PY | |
| then | |
| echo "EEGPREP_SKIP_MATLAB=0" >> "$GITHUB_ENV" | |
| else | |
| echo "EEGPREP_SKIP_MATLAB=1" >> "$GITHUB_ENV" | |
| fi | |
| - name: Install dependencies | |
| run: | | |
| uv pip install --system -e .[all] | |
| - name: Run MATLAB tests | |
| if: steps.matlab-availability.outputs.available == 'true' | |
| uses: matlab-actions/run-command@v2 | |
| with: | |
| command: "ver" | |
| - name: Run Python tests via MATLAB batch | |
| if: steps.matlab-availability.outputs.available == 'true' | |
| uses: matlab-actions/run-command@v2 | |
| with: | |
| command: | | |
| [status, cmdout] = system('python -m unittest discover -s tests'); | |
| disp(cmdout); | |
| if status ~= 0 | |
| error('Python tests failed'); | |
| end | |
| - name: Run Python tests | |
| if: steps.matlab-availability.outputs.available != 'true' | |
| run: | | |
| python -m unittest discover -s tests | |
| - name: Display installed packages | |
| if: always() | |
| run: | | |
| uv pip list --system |