better handling of setup in test-cases (prevent execution of 2to3 twice, full logging in heavydebug, etc.)

pull/1510/head
sebres 8 years ago
parent d71a525a85
commit 461e9bab56

@ -113,6 +113,7 @@ else: # pragma: no cover
# ticking, unless like with '-l critical' which would be silent
# unless error occurs
logSys.setLevel(getattr(logging, 'CRITICAL'))
opts.log_level = logSys.level
# Add the default logging handler
stdout = logging.StreamHandler(sys.stdout)
@ -140,7 +141,7 @@ logSys.addHandler(stdout)
#
# Let know the version
#
if not opts.log_level or opts.log_level != 'critical': # pragma: no cover
if opts.log_level != logging.CRITICAL: # pragma: no cover
print("Fail2ban %s test suite. Python %s. Please wait..." \
% (version, str(sys.version).replace('\n', '')))

@ -87,6 +87,7 @@ else:
def _getSysPythonVersion():
return _sh_call("fail2ban-python -c 'import sys; print(tuple(sys.version_info))'")
class SetupTest(unittest.TestCase):
def setUp(self):
@ -108,9 +109,11 @@ class SetupTest(unittest.TestCase):
if not self.setup:
return # if verbose skip didn't work out
tmp = tempfile.mkdtemp()
# suppress stdout (and stderr) if not heavydebug
supdbgout = ' >/dev/null' if unittest.F2B.log_level >= logging.DEBUG else '' # HEAVYDEBUG
try:
os.system("%s %s install --root=%s >/dev/null"
% (sys.executable, self.setup, tmp))
os.system("%s %s install --disable-2to3 --dry-run --root=%s%s"
% (sys.executable, self.setup, tmp, supdbgout))
def strippath(l):
return [x[len(tmp)+1:] for x in l]
@ -161,8 +164,8 @@ class SetupTest(unittest.TestCase):
# clean up
shutil.rmtree(tmp)
# remove build directory
os.system("%s %s clean --all >/dev/null 2>&1"
% (sys.executable, self.setup))
os.system("%s %s clean --all%s"
% (sys.executable, self.setup, (supdbgout + ' 2>&1') if supdbgout else ''))
class TestsUtilsTest(LogCaptureTestCase):

@ -31,17 +31,19 @@ except ImportError:
setuptools = None
from distutils.core import setup
# all versions
from distutils.command.build_py import build_py
from distutils.command.build_scripts import build_scripts
from distutils.command.install_scripts import install_scripts
from distutils.command.install import install
try:
# python 3.x
from distutils.command.build_py import build_py_2to3 as build_py
from distutils.command.build_scripts \
import build_scripts_2to3 as build_scripts
from distutils.command.build_py import build_py_2to3
from distutils.command.build_scripts import build_scripts_2to3
_2to3 = True
except ImportError:
# python 2.x
from distutils.command.build_py import build_py
from distutils.command.build_scripts import build_scripts
# all versions
from distutils.command.install_scripts import install_scripts
_2to3 = False
import os
from os.path import isfile, join, isdir, realpath
@ -66,6 +68,27 @@ class install_scripts_f2b(install_scripts):
updatePyExec(bindir)
return outputs
# Wrapper to specify fail2ban own options:
class install_command_f2b(install):
user_options = install.user_options + [
('disable-2to3', None, 'Specify to deactivate 2to3, e.g. if the install runs from fail2ban test-cases.'),
]
def initialize_options(self):
self.disable_2to3 = None
install.initialize_options(self)
def finalize_options(self):
global _2to3
## in the test cases 2to3 should be already done (fail2ban-2to3):
if self.disable_2to3:
_2to3 = False
if _2to3:
cmdclass = self.distribution.cmdclass
cmdclass['build_py'] = build_py_2to3
cmdclass['build_scripts'] = build_scripts_2to3
install.finalize_options(self)
def run(self):
install.run(self)
# Update fail2ban-python env to current python version (where f2b-modules located/installed)
rootdir = os.path.realpath(os.path.dirname(
@ -143,7 +166,7 @@ setup(
platforms = "Posix",
cmdclass = {
'build_py': build_py, 'build_scripts': build_scripts,
'install_scripts': install_scripts_f2b
'install_scripts': install_scripts_f2b, 'install': install_command_f2b
},
scripts = [
'bin/fail2ban-client',

Loading…
Cancel
Save