diff --git a/.testr.conf b/.testr.conf new file mode 100644 index 000000000..414b5d510 --- /dev/null +++ b/.testr.conf @@ -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 diff --git a/HACKING.rst b/HACKING.rst index 774acd996..85e510650 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -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). diff --git a/doc/source/dev/quickstart.rst b/doc/source/dev/quickstart.rst index 0d2bd100e..42615cd7c 100644 --- a/doc/source/dev/quickstart.rst +++ b/doc/source/dev/quickstart.rst @@ -60,4 +60,4 @@ You may pass options to the test programs using positional arguments:: To run only the pep8/flake8 syntax and style checks:: - tox -epep8 \ No newline at end of file + tox -epep8 diff --git a/higgins/tests/__init__.py b/higgins/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/higgins/tests/unit/base.py b/higgins/tests/unit/base.py index 1c30cdb56..02059bce3 100644 --- a/higgins/tests/unit/base.py +++ b/higgins/tests/unit/base.py @@ -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() diff --git a/higgins/tests/unit/test_hacking.py b/higgins/tests/unit/test_hacking.py index 91e9eea83..7d9146c5b 100644 --- a/higgins/tests/unit/test_hacking.py +++ b/higgins/tests/unit/test_hacking.py @@ -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 diff --git a/higgins/tests/unit/test_higgins.py b/higgins/tests/unit/test_higgins.py index b97182905..9e6db4fe5 100644 --- a/higgins/tests/unit/test_higgins.py +++ b/higgins/tests/unit/test_higgins.py @@ -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 diff --git a/test-requirements.txt b/test-requirements.txt index cfb840496..45e555667 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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 diff --git a/tools/flake8wrap.sh b/tools/flake8wrap.sh new file mode 100755 index 000000000..919ea6729 --- /dev/null +++ b/tools/flake8wrap.sh @@ -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 diff --git a/tools/pretty_tox.sh b/tools/pretty_tox.sh new file mode 100755 index 000000000..799ac1848 --- /dev/null +++ b/tools/pretty_tox.sh @@ -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 diff --git a/tox.ini b/tox.ini index 19ac94472..31eef0da5 100644 --- a/tox.ini +++ b/tox.ini @@ -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}