forked from hyperopt/hyperopt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.sh
executable file
·83 lines (69 loc) · 1.84 KB
/
run_tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
use_spark=true
while :; do
case $1 in
--no-spark)
use_spark=false
;;
*) break
esac
shift
done
# Return on any failure
set -e
# if (got > 1 argument OR ( got 1 argument AND that argument does not exist)) then
# print usage and exit.
if [[ $# -gt 1 || ($# = 1 && ! -e $1) ]]; then
echo "run_tests.sh [--no-spark] [target]"
echo ""
echo "Run python tests for this package."
echo " --no-spark : flag to tell this script to skip Apache Spark-related tests"
echo " target : either a test file or directory [default: tests]"
if [[ ($# = 1 && ! -e $1) ]]; then
echo
echo "ERROR: Could not find $1"
fi
exit 1
fi
if [[ ("$use_spark" = false) && ($1 == *test_spark.py) ]] ; then
echo
echo "ERROR: Cannot run $1 with --no-spark flag"
exit 1
fi
if [[ "$use_spark" = true ]]; then
# assumes run from the package base directory
if [ -z "$SPARK_HOME" ]; then
echo 'You need to set $SPARK_HOME to run these tests.' >&2
exit 1
fi
# Honor the choice of python driver
if [ -z "$PYSPARK_PYTHON" ]; then
PYSPARK_PYTHON=`which python`
fi
# Override the python driver version as well to make sure we are in sync in the tests.
export PYSPARK_DRIVER_PYTHON=$PYSPARK_PYTHON
echo $PYSPARK_PYTHON
LIBS=""
for lib in "$SPARK_HOME/python/lib"/*zip ; do
LIBS=$LIBS:$lib
done
export PYTHONPATH=$PYTHONPATH:$SPARK_HOME/python:$LIBS:hyperopt
# This will be used when starting pyspark.
export PYSPARK_SUBMIT_ARGS="--driver-memory 4g --executor-memory 4g pyspark-shell"
fi
# The current directory of the script.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Run test suites
if [ -f "$1" ] || [ -d "$1" ]; then
target="$1"
else
target=$DIR/hyperopt/tests
fi
echo "============= Running the tests in: $target ============="
if [[ "$use_spark" = true ]]; then
$PYSPARK_DRIVER_PYTHON \
-m "pytest" -v $target
else
python \
-m "pytest" -v --ignore-glob "*test_spark.py" $target
fi