TST+RF: Add ability to execute test from setup.py with setuptools

Note that the fail2ban version can no longer be imported from
"fail2ban.version", as this breaks 2to3 conversion for tests
pull/181/head
Steven Hiscocks 2013-04-20 20:17:36 +01:00
parent 9e684abad7
commit 55810a3c30
2 changed files with 36 additions and 7 deletions

View File

@ -13,10 +13,8 @@ install:
- pip install pyinotify - pip install pyinotify
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then sudo apt-get install -qq python-gamin; fi - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then sudo apt-get install -qq python-gamin; fi
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then pip install -q coveralls; fi - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then pip install -q coveralls; fi
before_script:
- if [[ $TRAVIS_PYTHON_VERSION == 3* ]]; then ./fail2ban-2to3; fi
script: script:
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then export PYTHONPATH="$PYTHONPATH:/usr/share/pyshared:/usr/lib/pyshared/python2.7"; fi - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then export PYTHONPATH="$PYTHONPATH:/usr/share/pyshared:/usr/lib/pyshared/python2.7"; fi
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then coverage run --rcfile=.travis_coveragerc bin/fail2ban-testcases; else python bin/fail2ban-testcases; fi - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then coverage run --rcfile=.travis_coveragerc setup.py test; else python setup.py test; fi
after_success: after_success:
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then coveralls; fi - if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then coveralls; fi

View File

@ -22,7 +22,13 @@ __author__ = "Cyril Jaquier"
__copyright__ = "Copyright (c) 2004 Cyril Jaquier" __copyright__ = "Copyright (c) 2004 Cyril Jaquier"
__license__ = "GPL" __license__ = "GPL"
from distutils.core import setup try:
import setuptools
from setuptools import setup
except ImportError:
setuptools = None
from distutils.core import setup
try: try:
# python 3.x # python 3.x
from distutils.command.build_py import build_py_2to3 as build_py from distutils.command.build_py import build_py_2to3 as build_py
@ -36,7 +42,23 @@ from os.path import isfile, join, isdir
import sys import sys
from glob import glob from glob import glob
from fail2ban.version import version if setuptools and "test" in sys.argv:
import logging
logSys = logging.getLogger("fail2ban")
hdlr = logging.StreamHandler(sys.stdout)
fmt = logging.Formatter("%(asctime)-15s %(message)s")
hdlr.setFormatter(fmt)
logSys.addHandler(hdlr)
if set(["-q", "--quiet"]) & set(sys.argv):
logSys.setLevel(logging.FATAL)
logging.captureWarnings(True)
elif set(["-v", "--verbose"]) & set(sys.argv):
logSys.setLevel(logging.DEBUG)
else:
logSys.setLevel(logging.INFO)
elif "test" in sys.argv:
print("python distribute required to execute fail2ban tests")
print("")
longdesc = ''' longdesc = '''
Fail2Ban scans log files like /var/log/pwdfail or Fail2Ban scans log files like /var/log/pwdfail or
@ -45,9 +67,17 @@ too many password failures. It updates firewall rules
to reject the IP address or executes user defined to reject the IP address or executes user defined
commands.''' commands.'''
if setuptools:
setup_extra = {
'test_suite': "fail2ban.tests.utils.gatherTests",
'use_2to3': True,
}
else:
setup_extra = {}
setup( setup(
name = "fail2ban", name = "fail2ban",
version = version, version = "0.9.0a",
description = "Ban IPs that make too many password failures", description = "Ban IPs that make too many password failures",
long_description = longdesc, long_description = longdesc,
author = "Cyril Jaquier", author = "Cyril Jaquier",
@ -88,7 +118,8 @@ setup(
('/usr/share/doc/fail2ban', ('/usr/share/doc/fail2ban',
['README', 'DEVELOP', 'doc/run-rootless.txt'] ['README', 'DEVELOP', 'doc/run-rootless.txt']
) )
] ],
**setup_extra
) )
# Do some checks after installation # Do some checks after installation