# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Run all tests

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  test:
    name: Test on ${{ matrix.os }} with Python ${{ matrix.python-version }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: true
      matrix:
        python-version: ["3.8", "3.9"]
        os: ["ubuntu-latest", "windows-latest"]
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install Linux system dependencies
      if: startsWith(matrix.os, 'ubuntu')
      run: |
        sudo apt-get install libltdl-dev libgsl0-dev python3-all-dev openmpi-bin libopenmpi-dev
    - name: Install basic Python dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install coverage coveralls nose-testconfig
        python -m pip install mpi4py
        python -m pip install -r requirements.txt
    - name: Install Brian 2
      run: |
        python -m pip install brian2
    - name: Install NEURON
      if: startsWith(matrix.os, 'ubuntu')
      run: |
        python -m pip install neuron==8.1.0
        python -m pip install nrnutils
    - name: Install NEST
      if: startsWith(matrix.os, 'ubuntu')
      run: |
        python -m pip install cython
        wget https://github.com/nest/nest-simulator/archive/refs/tags/v3.3.tar.gz -O nest-simulator-3.3.tar.gz
        tar xzf nest-simulator-3.3.tar.gz
        cmake -DCMAKE_INSTALL_PREFIX=$HOME/.local -Dwith-mpi=ON ./nest-simulator-3.3
        make
        make install
    - name: Install PyNN itself
      run: |
        python setup.py install
    - name: Run unit tests
      run: |
        nosetests --nologcapture --where=test/unittests --verbosity=2 test_assembly.py test_brian.py test_connectors_parallel.py test_connectors_serial.py test_core.py test_descriptions.py test_files.py test_idmixin.py test_lowlevelapi.py test_nest.py test_neuron.py test_parameters.py test_population.py test_populationview.py test_projection.py test_random.py test_recording.py test_simulation_control.py test_space.py test_standardmodels.py test_utility_functions.py
    - name: Run system tests
      run: |
        nosetests --nologcapture --where=test/system --verbosity=2 test_nest.py test_brian2.py test_neuron.py