#!/usr/bin/env bash
# Script for running Python package test
# @copyright Highly Confidential and Proprietary Zoox Information. Copyright (c) Zoox.
#
# Date Created: November 25, 2019
# Author: jpetrie
#

# -e Exit script on any error
# -o pipefail Do not propagate errors silently thru pipes
set -eo pipefail

echo "thresher/$0::START pwd="`pwd`

# Set pypi variables
ZOOX_INDEX=https://pypi.zooxlabs.com/simple
PYPI_INDEX=https://pypi.python.org/simple

# Clear any packages that may be present
rm -f dist/* 2> /dev/null

# Generate new Python package in dist/
echo "thresher/$0::CREATE_SDIST"
python3.6 setup.py sdist 2> /dev/null

# Install the requirements
pip3.6 install -r requirements.txt --index-url ${ZOOX_INDEX} --extra-index-url ${PYPI_INDEX}

# Install test requirements (needed for CI)
pip3.6 install -r test_requirements.txt --index-url ${ZOOX_INDEX} --extra-index-url ${PYPI_INDEX}

# Install the package
pip3.6 install --force-reinstall dist/* --index-url ${ZOOX_INDEX} --extra-index-url ${PYPI_INDEX}

# Install latest Zoox dependencies
pip3.6 install repo_info --index-url ${ZOOX_INDEX} --extra-index-url ${PYPI_INDEX}

# Navigate cwd to repo root to satisfy bazel_info runtime requirements
pushd ./../../../../

# Run the tests
echo "thresher/$0::RUNNING tests against Python"
pytest -v firmware/validation/py_packages/thresher/tests/

# Restore cwd
popd

echo "thresher/$0::FINISH"
