From 5269924155cf0c014b8f75e2a557e6e1809ad0e6 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Tue, 22 Apr 2014 11:38:02 +0200 Subject: [PATCH] Wrap tests and linting with tox Use tox configuration to expose linting and unit testing. Will let us integrate them with OpenStack continuous integration infrastructure. * updates .gitignore following the migration from bzr * get rid of the old Makefile in favor of tox * remove .pep8 file (that is now a [flake8] section in tox.ini) * fix a few trivial pep8 errors (comments must start with '# ' and modulo operator needs surrounding spaces) but ignore 'line too long (E501)' for now. * write module requirements in /test-requirements.txt. Discover is needed for python 2.6. * change the test command that cames from the Makefile so it works with python 2.6 Change-Id: If58730d84315c0ea018a3757624d98bf2e1aeb3f --- .gitignore | 4 ++++ .pep8 | 2 -- Makefile | 2 -- jenkins/__init__.py | 10 ++++------ test-requirements.txt | 3 +++ tests/helper.py | 2 +- tox.ini | 26 ++++++++++++++++++++++++++ 7 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 .gitignore delete mode 100644 .pep8 delete mode 100644 Makefile create mode 100644 test-requirements.txt create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4e94e5f --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.egg +*.egg-info +*.pyc +/.tox diff --git a/.pep8 b/.pep8 deleted file mode 100644 index 70d9f64..0000000 --- a/.pep8 +++ /dev/null @@ -1,2 +0,0 @@ -[pep8] -ignore = E221,E501 diff --git a/Makefile b/Makefile deleted file mode 100644 index b67626b..0000000 --- a/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -test: - python -m unittest discover diff --git a/jenkins/__init__.py b/jenkins/__init__.py index 97fe9dd..215bc7c 100644 --- a/jenkins/__init__.py +++ b/jenkins/__init__.py @@ -45,11 +45,9 @@ See examples at :doc:`example` ''' -#import sys import urllib2 import urllib import base64 -#import traceback import json import httplib @@ -69,7 +67,7 @@ DELETE_JOB = 'job/%(name)s/doDelete' ENABLE_JOB = 'job/%(name)s/enable' DISABLE_JOB = 'job/%(name)s/disable' COPY_JOB = 'createItem?name=%(to_name)s&mode=copy&from=%(from_name)s' -RENAME_JOB = 'job/%(name)s/doRename?newName=%(new_name)s' +RENAME_JOB = 'job/%(name)s/doRename?newName=%(new_name)s' BUILD_JOB = 'job/%(name)s/build' STOP_BUILD = 'job/%(name)s/%(number)s/stop' BUILD_WITH_PARAMS_JOB = 'job/%(name)s/buildWithParameters' @@ -82,7 +80,7 @@ NODE_INFO = 'computer/%(name)s/api/json?depth=0' NODE_TYPE = 'hudson.slaves.DumbSlave$DescriptorImpl' TOGGLE_OFFLINE = 'computer/%(name)s/toggleOffline?offlineMessage=%(msg)s' -#for testing only +# for testing only EMPTY_CONFIG_XML = ''' false @@ -98,7 +96,7 @@ EMPTY_CONFIG_XML = ''' ''' -#for testing only +# for testing only RECONFIG_XML = ''' false @@ -358,7 +356,7 @@ class Jenkins(object): self.jenkins_open(urllib2.Request( self.server + RENAME_JOB % locals(), '')) if not self.job_exists(new_name): - raise JenkinsException('rename[%s] failed'%(new_name)) + raise JenkinsException('rename[%s] failed' % (new_name)) def delete_job(self, name): ''' diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..e9ffd03 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,3 @@ +discover +flake8 +mock diff --git a/tests/helper.py b/tests/helper.py index c1628a6..a712654 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -2,4 +2,4 @@ import os import sys sys.path.insert(0, os.path.abspath('..')) -import jenkins +import jenkins # noqa diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..bdba534 --- /dev/null +++ b/tox.ini @@ -0,0 +1,26 @@ +[tox] +minversion = 1.6 +skipsdist = True +envlist = pep8, py26, py27 + +[testenv] +setenv VIRTUAL_ENV={envdir} +usedevelop = True +install_command = pip install {opts} {packages} +deps = -r{toxinidir}/test-requirements.txt +commands = python -m discover + +[tox:jenkins] +downloadcache = ~/cache/pip + +[testenv:pep8] +commands = flake8 + +[testenv:venv] +commands = {posargs} + +[flake8] +; E501 line too long (80 > 79 characters) +ignore = E501 +show-source = True +exclude = .venv,.tox,dist,doc,build,*.egg