Make infra ready for unit/pep8/doc testing

Enable unit test frame work first.

Change-Id: I537b769c5c7467206b6ba0d384434d3442462ff0
This commit is contained in:
Eli Qiao 2016-05-26 15:19:09 +08:00
parent c88892d196
commit 8348cc5ad1
11 changed files with 74 additions and 11 deletions

7
.testr.conf Normal file
View File

@ -0,0 +1,7 @@
[DEFAULT]
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-45} \
${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./higgins/tests/unit} $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@ -1,10 +1,10 @@
Higgins Style Commandments
===============================================
==========================
Read the OpenStack Style Commandments http://docs.openstack.org/developer/hacking/
Higgins Specific Commandments
----------------------------
-----------------------------
- [M302] Change assertEqual(A is not None) by optimal assert like
assertIsNotNone(A).

View File

View File

@ -18,6 +18,9 @@
from oslotest import base
class TestCase(base.BaseTestCase):
class BaseTestCase(base.BaseTestCase):
"""Test case base class for all unit tests."""
def setUp(self):
super(BaseTestCase, self).setUp()

View File

@ -18,10 +18,10 @@ import mock
import pep8
from higgins.hacking import checks
from higgins.tests import base
from higgins.tests.unit import base
class HackingTestCase(base.TestCase):
class HackingTestCase(base.BaseTestCase):
"""Hacking test class.
This class tests the hacking checks higgins .hacking.checks by passing

View File

@ -22,7 +22,7 @@ Tests for `higgins` module.
from higgins.tests.unit import base
class TestHiggins(base.TestCase):
class TestHiggins(base.BaseTestCase):
def test_something(self):
pass

View File

@ -4,12 +4,15 @@
hacking<0.11,>=0.10.2 # Apache-2.0
bandit>=1.0.1 # Apache-2.0
doc8 # Apache-2.0
coverage>=3.6 # Apache-2.0
mock>=1.2 # BSD
python-subunit>=0.0.18 # Apache-2.0/BSD
sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 # BSD
oslosphinx!=3.4.0,>=2.5.0 # Apache-2.0
oslotest>=1.10.0 # Apache-2.0
os-testr>=0.4.1 # Apache-2.0
testrepository>=0.0.18 # Apache-2.0/BSD
testscenarios>=0.4 # Apache-2.0/BSD
testtools>=1.4.0 # MIT

20
tools/flake8wrap.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/sh
#
# A simple wrapper around flake8 which makes it possible
# to ask it to only verify files changed in the current
# git HEAD patch.
#
# Intended to be invoked via tox:
#
# tox -epep8 -- -HEAD
#
if test "x$1" = "x-HEAD" ; then
shift
files=$(git diff --name-only HEAD~1 | tr '\n' ' ')
echo "Running flake8 on ${files}"
diff -u --from-file /dev/null ${files} | flake8 --max-complexity 10 --diff "$@"
else
echo "Running flake8 on all files"
exec flake8 --max-complexity 10 "$@"
fi

16
tools/pretty_tox.sh Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -o pipefail
TESTRARGS=$1
# --until-failure is not compatible with --subunit see:
#
# https://bugs.launchpad.net/testrepository/+bug/1411804
#
# this work around exists until that is addressed
if [[ "$TESTARGS" =~ "until-failure" ]]; then
python setup.py testr --slowest --testr-args="$TESTRARGS"
else
python setup.py testr --slowest --testr-args="--subunit $TESTRARGS" | subunit-trace -f
fi

22
tox.ini
View File

@ -8,16 +8,28 @@ usedevelop = True
install_command =
constraints: {[testenv:common-constraints]install_command}
pip install -U {opts} {packages}
whitelist_externals = bash
find
rm
setenv =
VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/test-requirements.txt
commands = python setup.py test
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands =
find . -type f -name "*.pyc" -delete
bash tools/pretty_tox.sh '{posargs}'
[testenv:common-constraints]
install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages}
[testenv:pep8]
commands = flake8 {posargs}
commands =
doc8 -e .rst doc/source/ CONTRIBUTING.rst HACKING.rst README.rst
bash tools/flake8wrap.sh {posargs}
bandit -r higgins -x tests -n5 -ll
[testenv:pep8-constraints]
install_command = {[testenv:common-constraints]install_command}
@ -38,7 +50,9 @@ install_command = {[testenv:common-constraints]install_command}
commands = python setup.py test --coverage --testr-args='{posargs}'
[testenv:docs]
commands = python setup.py build_sphinx
commands =
doc8 -e .rst doc/source/ CONTRIBUTING.rst HACKING.rst README.rst
python setup.py build_sphinx
[testenv:docs-constraints]
install_command = {[testenv:common-constraints]install_command}