jobs:
- job: 'basic_test_pr_ubuntu'
  pool:
    vmImage: 'Ubuntu 16.04'
  strategy:
    matrix:
      Python36:
        PYTHON_VERSION: '3.6'

  steps:
  - script: |
      python3 -m pip install --upgrade pip setuptools --user
      python3 -m pip install pylint==2.3.1 astroid==2.2.5 --user
      python3 -m pip install coverage --user
      echo "##vso[task.setvariable variable=PATH]${HOME}/.local/bin:${PATH}"
    displayName: 'Install python tools'
  - script: |
      source install.sh
    displayName: 'Install nni toolkit via source code'
  - script: |
      python3 -m pip install torch==0.4.1 --user
      python3 -m pip install torchvision==0.2.1 --user
      python3 -m pip install tensorflow==1.13.1 --user
      python3 -m pip install keras==2.1.6 --user
      python3 -m pip install gym onnx --user
      sudo apt-get install swig -y
      nnictl package install --name=SMAC
      nnictl package install --name=BOHB
    displayName: 'Install dependencies'
  - script: |
      set -e
      python3 -m pylint --rcfile pylintrc nni_annotation
      python3 -m pylint --rcfile pylintrc nni_cmd
      python3 -m pylint --rcfile pylintrc nni_gpu_tool
      python3 -m pylint --rcfile pylintrc nni_trial_tool
      python3 -m pylint --rcfile pylintrc nni
      python3 -m pylint --rcfile pylintrc nnicli
    displayName: 'Run pylint'
  - script: |
      python3 -m pip install flake8 --user
      EXCLUDES=./src/nni_manager/,./tools/nni_annotation/testcase/,./examples/trials/mnist-nas/*/mnist*.py,./examples/trials/nas_cifar10/src/cifar10/general_child.py
      python3 -m flake8 . --count --exclude=$EXCLUDES --select=E9,F63,F72,F82 --show-source --statistics
    displayName: 'Run flake8 tests to find Python syntax errors and undefined names'
  - script: |
      cd test
      source unittest.sh
    displayName: 'Unit test'
  - script: |
      cd test
      python3 naive_test.py
    displayName: 'Naive test'
  - script: |
      cd test
      python3 tuner_test.py
    displayName: 'Built-in tuners / assessors tests'
  - script: |
      cd test
      python3 metrics_test.py
    displayName: 'Trial job metrics test'
  - script: |
      cd test
      python3 cli_test.py
    displayName: 'nnicli test'

- job: 'basic_test_pr_macOS'
  pool:
    vmImage: 'macOS 10.13'
  strategy:
    matrix:
      Python36:
        PYTHON_VERSION: '3.6'

  steps:
  - script: python3 -m pip install --upgrade pip setuptools
    displayName: 'Install python tools'
  - script: |
      source install.sh
      echo "##vso[task.setvariable variable=PATH]${HOME}/Library/Python/3.7/bin:${PATH}"
    displayName: 'Install nni toolkit via source code'
  - script: |
      python3 -m pip install torch==0.4.1 --user
      python3 -m pip install torchvision==0.2.1 --user
      python3 -m pip install tensorflow==1.13.1 --user
      ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
      brew install swig@3
      ln -s /usr/local/opt/swig\@3/bin/swig /usr/local/bin/swig
      nnictl package install --name=SMAC
    displayName: 'Install dependencies'
  - script: |
      cd test
      source unittest.sh
    displayName: 'Unit test'
  - script: |
      cd test
      python3 naive_test.py
    displayName: 'Naive test'
  - script: |
      cd test
      python3 tuner_test.py
    displayName: 'Built-in tuners / assessors tests'
  - script: |
      cd test
      python3 cli_test.py
    displayName: 'nnicli test'

- job: 'basic_test_pr_Windows'
  pool:
    vmImage: 'vs2017-win2016'
  strategy:
    matrix:
      Python36:
        PYTHON_VERSION: '3.6'

  steps:
  - script: |
      powershell.exe -file install.ps1
    displayName: 'Install nni toolkit via source code'
  - script: |
      python -m pip install scikit-learn==0.20.0 --user
      python -m pip install keras==2.1.6 --user
      python -m pip install https://download.pytorch.org/whl/cu90/torch-0.4.1-cp36-cp36m-win_amd64.whl --user
      python -m pip install torchvision --user
      python -m pip install tensorflow==1.13.1 --user
    displayName: 'Install dependencies'
  - script: |
      cd test
      powershell.exe -file unittest.ps1
    displayName: 'unit test'
  - script: |
      cd test
      python tuner_test.py
    displayName: 'Built-in tuners / assessors tests'
  - script: |
      cd test
      PATH=$HOME/.local/bin:$PATH python3 cli_test.py
    displayName: 'nnicli test'
