Skip to content

Commit 909151d

Browse files
abncrobinso
authored andcommitted
Add contrib scripts and docs for testing python3
1 parent 13cc398 commit 909151d

5 files changed

Lines changed: 125 additions & 8 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ MANIFEST
44
dist
55
build
66
.coverage
7+
8+
#python-bugzilla venvs
9+
dev-env*

HACKING

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,56 @@
1-
If submitting any patch, please verify that no new pylint or pep8 violations
2-
are introduced:
1+
Hackers Guide
2+
=============
33

4-
python setup.py pylint
4+
1. Setting up the environment
5+
-----------------------------
6+
To start development, you can set-up/activate a virtual environment by using the
7+
following command:
8+
source contrib/activate-dev-env [python2|python3]
59

6-
And ensure that the basic unit test suite does not regress
10+
Note: Providing no arguments will attempt to use python2.
711

8-
python setup.py test
12+
# Manually activating an environment
13+
source dev-env-${NAME}/bin/activate
914

15+
2. Running tests
16+
----------------
17+
Once you have already activated an environment, you can use the following.
18+
19+
# Basic unit test suite
20+
python setup.py test
21+
22+
# Functional tests
1023
There are more comprehensive tests that are disabled by default. Readonly
1124
functional tests that run against several public bugzilla instances. No
1225
login account is required:
1326

14-
python setup.py test --ro-functional
27+
python setup.py test --ro-functional
1528

1629
And read/write functional tests. These currently run against the test
1730
bugzilla instance at partner-bugzilla.redhat.com, and requires a valid
1831
login there:
1932

20-
python setup.py test --rw-functional
33+
python setup.py test --rw-functional
34+
35+
Note: Before running rw-functional tests, make sure you have logged using:
36+
python bugzilla-cli \
37+
--bugzilla="https://partner-bugzilla.redhat.com/xmlrpc.cgi" \
38+
--user=$USER login
39+
40+
3. pylint and pep8
41+
------------------
42+
To test for pylint or pep8 violations, you can run:
43+
python setup.py pylint
44+
45+
Note: This expects that you already have pylint and pep8 (installed when setting
46+
up virtualenv) isntalled.
47+
48+
4. Patch Submission
49+
-------------------
50+
If you are submitting a patch, ensure the following:
51+
[REQ] verify that no new pylint or pep8 violations
52+
[REQ] run basic unit test suite across all python versions:
53+
bash contrib/run-tests
2154

2255
Running any of the functional tests is not a requirement for patch submission,
2356
but please give them a go if you are interested.

contrib/activate-dev-env

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Helper script to create (if required) and activate a virtual environment for
2+
# a specified PYTHON_BINARY (python|python2|python3) and install dependencies
3+
# required for testing and development.
4+
#
5+
# Usage: source $0 [PYTHON_BINARY]
6+
7+
# use env python by default
8+
PYTHON_BIN=python2
9+
VIRTIALENV_CMD=virtualenv
10+
SETUP_PY="setup.py"
11+
DEV_MODULE_DIR="bugzilla"
12+
DIR_PREFIX="dev-env"
13+
14+
if [ $# -ne 0 ]; then
15+
PYTHON_BIN=$1
16+
fi
17+
18+
function activate()
19+
{
20+
DIR_NAME=$1
21+
echo "INFO: Activating virtualenv at ${DIR_NAME}"
22+
source ${DIR_NAME}/bin/activate
23+
}
24+
25+
function virtualize()
26+
{
27+
PROMPT=$(basename ${PYTHON_BIN})
28+
DIR_NAME="${DIR_PREFIX}-${PROMPT}"
29+
30+
if [ ! -d ${DIR_NAME} ]; then
31+
echo "INFO: Creating virtualenv ${DIR_NAME}"
32+
${VIRTIALENV_CMD} -p $(which ${PYTHON_BIN}) --prompt "${PROMPT}" ${DIR_NAME}
33+
fi
34+
35+
if [ -d ${DIR_NAME} ]; then
36+
activate $DIR_NAME
37+
38+
for REQ in $(find ./ -maxdepth 1 -type f -name "*requirements.txt"); do
39+
pip install -qr "${REQ}"
40+
done
41+
else
42+
echo >&2 "ERROR: Failed to activate virtualenv."
43+
fi
44+
}
45+
46+
47+
if ! command -v ${VIRTIALENV_CMD} >/dev/null 2>&1; then
48+
# We require virtuaenv to be available
49+
echo >&2 "ERROR: virtualenv command not found"
50+
elif ! command -v $PYTHON_BIN >/dev/null 2>&1; then
51+
# Ensure PYTHON_BIN is valid
52+
echo >&2 "ERROR: ${PYTHON_BIN} command not found"
53+
elif ! ${PYTHON_BIN} --version 2>&1 | grep -q '^Python'; then
54+
# Ensure PYTHON_BIN is python
55+
echo >&2 "ERROR: '${PYTHON_BIN} --version' returned an invalid response. Is ${PYTHON_BIN} really python?"
56+
elif [ ! -f ${SETUP_PY} ]; then
57+
echo >&2 "ERROR: ${SETUP_PY} not found"
58+
else
59+
virtualize
60+
fi

contrib/run-tests

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# Helper script to run test for each supported python versions
4+
# Defaults to running basic tests. The script activates the correct environment
5+
# as required.
6+
7+
# Usage: $0 [options]
8+
# Example: $0 --ro-functional
9+
10+
ARGS="$@"
11+
12+
for BIN in python2 python3; do
13+
if command -v ${BIN} >/dev/null 2>&1; then
14+
echo "INFO: Running tests for ${BIN}"
15+
. ./contrib/activate-dev-env ${BIN}
16+
python setup.py test ${ARGS}
17+
echo "INFO: Tests completed for ${BIN}"
18+
else
19+
echo "INFO: ${BIN} not found, skipping tests."
20+
fi
21+
done

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def run(self):
4949
usecov = False
5050

5151
if usecov:
52-
cov = coverage.coverage(omit=["/*/tests/*", "/usr/*"])
52+
cov = coverage.coverage(omit=["/*/tests/*", "/usr/*", "*dev-env*"])
5353
cov.erase()
5454
cov.start()
5555

0 commit comments

Comments
 (0)