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
This commit is contained in:
Antoine Musso 2014-04-22 11:38:02 +02:00
parent dc73252fa0
commit 5269924155
7 changed files with 38 additions and 11 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.egg
*.egg-info
*.pyc
/.tox

2
.pep8
View File

@ -1,2 +0,0 @@
[pep8]
ignore = E221,E501

View File

@ -1,2 +0,0 @@
test:
python -m unittest discover

View File

@ -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 = '''<?xml version='1.0' encoding='UTF-8'?>
<project>
<keepDependencies>false</keepDependencies>
@ -98,7 +96,7 @@ EMPTY_CONFIG_XML = '''<?xml version='1.0' encoding='UTF-8'?>
<buildWrappers/>
</project>'''
#for testing only
# for testing only
RECONFIG_XML = '''<?xml version='1.0' encoding='UTF-8'?>
<project>
<keepDependencies>false</keepDependencies>
@ -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):
'''

3
test-requirements.txt Normal file
View File

@ -0,0 +1,3 @@
discover
flake8
mock

View File

@ -2,4 +2,4 @@ import os
import sys
sys.path.insert(0, os.path.abspath('..'))
import jenkins
import jenkins # noqa

26
tox.ini Normal file
View File

@ -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