#!/usr/bin/env bash
# This script allows the user to run the Python package tests from a local terminal. It will setup
# the test environment in a virtual environment and install any package dependencies

# Check if virtualenv is installed
if ! command -v virtualenv &> /dev/null
then
    echo "Please install virtualenv before running"
    exit
fi

ENV_NAME="package_test_env"

# Create the python virtual environment
echo "Creating env $ENV_NAME"
virtualenv -p python3.6 $ENV_NAME

# Source the newly created environment
source $ENV_NAME/bin/activate

# Install the package using the setup.py file created
python setup.py install

# Install all requirements for the package and tests
pip install -r requirements.txt --index-url https://pypi.zooxlabs.com/simple
pip install -r test_requirements.txt --index-url https://pypi.zooxlabs.com/simple

# Run the package tests
pytest -v tests/

# Deactivate the environment and clean up the directory
deactivate
rm -R dist/
rm -R $ENV_NAME
