#!/bin/bash
ANY=
NONOSE=

if which python3 >> /dev/null ; then
	 PYTHON=python3
else
	 PYTHON=python
fi

for i in "$@" ; do
	if [[ $i != -* ]] ; then
		ANY=1
	fi
	if [[ $i == -N ]] ; then
		NONOSE=1
	fi
done

for arg do
  shift
  [ "$arg" = "-N" ] && continue
  set -- "$@" "$arg"
done


if [[ $NONOSE == '' ]] &&  echo 'import nose' | $PYTHON >> /dev/null 2> /dev/null ; then
	MODULE="nose -s"
else
	MODULE=unittest
fi



ADD=
if [[ ! "$ANY" ]] ; then
	cd $(dirname "$0")
	ADD=*/test/test_*.py
fi
$PYTHON -m $MODULE $@ $ADD
