1#!/bin/bash
2set -eux
3# By default, run tests with pytest-forked plugin,
4# disable in terminal for debugging, you may add --forked
5flag_forked="--forked"
6if [[ -z "${CONTINUOUS_INTEGRATION-}" ]] && [[ -t 1 ]] ; then
7	flag_forked=""
8fi
9test_flags=(
10	$@
11	$flag_forked
12	tests/
13)
14
15main() {
16	cd "$( dirname "${BASH_SOURCE[0]}" )/.."
17	if [[ -n "${CONTINUOUS_INTEGRATION-}" ]] ; then
18		case "${test_group-}" in
19		pep8)
20			if [[ "${TRAVIS_PYTHON_VERSION}" = "2.7" ]] ; then
21				flake8 python2/
22			else
23				flake8 python3/ tests/
24			fi
25			;;
26		package)
27			# TODO: sdist bdist_wheel
28			# but wheels don't roll well with our 2/3 split code base
29			python setup.py sdist
30			install_check_version "pip"
31			;;
32		*)
33			pip install -e .
34			httplib2_test_still_run_skipped=1 pytest --fulltrace -k test_303 $@ tests/ || true
35			httplib2_test_still_run_skipped=1 pytest --fulltrace -k test_head_301 $@ tests/ || true
36			pytest --fulltrace ${test_flags[@]}
37			;;
38		esac
39	else
40		if [[ ! -d ./venv-27 ]] ; then
41			virtualenv --python=python2.7 ./venv-27
42		fi
43		if [[ ! -d ./venv-36 ]] ; then
44			virtualenv --python=python3.6 ./venv-36
45		fi
46
47		./venv-27/bin/pip install -e . -r requirements-test.txt
48		./venv-27/bin/pytest ${test_flags[@]}
49		./venv-36/bin/pip install -e . -r requirements-test.txt
50		./venv-36/bin/pytest ${test_flags[@]}
51
52		# FIXME: too many errors
53		# ./venv-27/bin/flake8 python2/
54		# ./venv-36/bin/flake8 python3/ tests/
55
56		# TODO: sdist bdist_wheel
57		# but wheels don't roll well with our 2/3 split code base
58		./venv-36/bin/python setup.py sdist
59		install_check_version "./venv-27/bin/pip"
60		install_check_version "./venv-36/bin/pip"
61	fi
62	rm -rf ./_httplib2_test_cache
63}
64
65install_check_version() {
66	local pip="$1"
67	$pip install dist/httplib2*
68	version_source=$(cd python3 ; python3 -Es -c 'import httplib2;print(httplib2.__version__)')
69	version_installed=$($pip show httplib2 |fgrep Version |cut -d' ' -f2)
70	if [[ "$version_source" != "$version_installed" ]] ; then
71		echo "error: installed package version=$version_installed does not match source=$version_source" >&2
72		exit 1
73	fi
74}
75
76main "$@"
77