summaryrefslogtreecommitdiff
path: root/tools/teamcity-runtests.sh
blob: 076e9a1aef98ebf0e26442239286773a25c917d5 (plain)
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
84
85
86
87
#!/bin/bash
#
# This script assumes that the project 'ptyprocess' is
# available in the parent of the project's folder.
set -e
set -o pipefail

if [ -z $1 ]; then
	echo "$0 (2.6|2.7|3.3|3.4|3.5)"
	exit 1
fi

export PYTHONIOENCODING=UTF8
export LANG=en_US.UTF-8

pyversion=$1
pyversion_flit=3.5
shift
here=$(cd `dirname $0`; pwd)
osrel=$(uname -s)
venv=teamcity-pexpect
venv_flit=flit-builder

function prepare_virtualenvwrapper() {
	venv_wrapper=$(which virtualenvwrapper.sh)
	. ${venv_wrapper}
}

function make_wheel_for_ptyprocess() {
	mkvirtualenv -p`which python${pyversion_flit}` ${venv_flit} || true
	workon ${venv_flit}
	# explicitly use pip3.5 to install/upgrade flit, a dependency for building
	# the ptyprocess wheel package.  Flit is not compatible with python 2.7.
	pip${pyversion_flit} install --upgrade flit

	# create ptyprocess wheel
	cd $here/../../ptyprocess
	rm -f dist/*
	flit wheel
	deactivate
}

function prepare_environment() {
	# create a virtualenv for target python version, install ptyprocess and test dependencies
	rmvirtualenv ${venv} || true
	mkvirtualenv -p `which python${pyversion}` ${venv} || true
	workon ${venv}
	pip uninstall --yes ptyprocess || true
	pip install ../ptyprocess/dist/ptyprocess-*.whl
	pip install --upgrade pytest-cov coverage coveralls pytest-capturelog
}

function do_test() {
	# run tests
	cd $here/..
	ret=0
	py.test \
		--cov pexpect \
		--cov-config .coveragerc \
		--junit-xml=results.${osrel}.py${pyversion}.xml \
		--verbose \
		--verbose \
		"$@" || ret=$?

	if [ $ret -ne 0 ]; then
		# we always exit 0, preferring instead the jUnit XML
		# results to be the dominate cause of a failed build.
		echo "py.test returned exit code ${ret}." >&2
		echo "the build should detect and report these " \
			"failing tests from the jUnit xml report." >&2
	fi
}

function report_coverage() {
	# combine all coverage to single file, report for this build,
	# then move into ./build-output/ as a unique artifact to allow
	# the final "Full build" step to combine and report to coveralls.io
	`dirname $0`/teamcity-coverage-report.sh
	mkdir -p build-output
	mv .coverage build-output/.coverage.${osrel}.py{$pyversion}.$RANDOM.$$
}

prepare_virtualenvwrapper
make_wheel_for_ptyprocess
prepare_environment
do_test
report_coverage