unittest.sh 1.1 KB
Newer Older
R
root 已提交
1 2 3 4 5
#!/bin/bash

abort(){
    echo "Run unittest failed" 1>&2
    echo "Please check your code" 1>&2
6 7
    echo "  1. you can run unit tests by 'bash .travis/unittest.sh' locally" 1>&2
    echo "  2. you can add python requirements in .travis/requirements.txt if you use new requirements in unit tests" 1>&2
R
root 已提交
8 9 10 11 12 13 14
    exit 1
}

unittest(){
    if [ $? != 0 ]; then
        exit 1
    fi
K
Kaipeng Deng 已提交
15
    find "./ppdet" -name 'tests' -type d -print0 | \
R
root 已提交
16 17 18 19 20 21 22
        xargs -0 -I{} -n1 bash -c \
        'python -m unittest discover -v -s {}'
}

trap 'abort' 0
set -e

K
Kaipeng Deng 已提交
23
# install travis python dependencies exclude pycocotools
24 25
if [ -f ".travis/requirements.txt" ]; then
    pip install -r .travis/requirements.txt
R
root 已提交
26
fi
27

K
Kaipeng Deng 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
# install pycocotools
if [ `pip list | grep pycocotools | wc -l` -eq 0 ]; then
  # install git if needed
  if [ -n  `which git` ]; then
    apt-get update
    apt-get install -y git
  fi;
  git clone https://github.com/cocodataset/cocoapi.git
  cd cocoapi/PythonAPI
  make install
  python setup.py install --user
  cd ../..
  rm -rf cocoapi
fi

R
root 已提交
43 44 45 46 47
export PYTHONPATH=`pwd`:$PYTHONPATH

unittest .

trap : 0