#
# Common shell routines for testing python modules
# Copyright (c) 2012-2016 Red Hat.
#

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

python=${PCP_PYTHON_PROG}
[ -n "$python" ] || _notrun "No python interpreter configured in \$PCP_PYTHON_PROG"
eval $python -c exit 2>/dev/null || _notrun "Python interpreter \"$python\" failed"

# verify output from unittest indicates successful testing
_check_unittest()
{
    mode=$1
    file=$2

    $PCP_ECHO_PROG $PCP_ECHO_N "$mode - ""$PCP_ECHO_C"
    if grep OK $file
    then
        return 0
    fi

    # Give some hint as to what went wrong ...
    #
    $PCP_AWK_PROG <$file '
$1 == "FAIL:"			{ want = 1 }
$1 == "File"			{ want = 1 }
want == 1 && $1 == "Ran" 	{ exit }
want == 1			{ print }'
    return 1
}

_check_requests()
{
    $python -c "import requests" >/dev/null 2>&1 || _notrun "$python requests package is not installed"
}

_check_requests_json()
{
    version=`$python --version 2>&1 | sed -e 's/Python //'`
    case "$version"
    in
	2.7.3|2.7.4)
	    _notrun "requests.json() broken in Python $version"
	    ;;
    esac
}
