From 461e9bab56027e257a836132e753a044bfa93cc2 Mon Sep 17 00:00:00 2001 From: sebres Date: Fri, 12 Aug 2016 11:07:31 +0200 Subject: [PATCH] better handling of setup in test-cases (prevent execution of 2to3 twice, full logging in heavydebug, etc.) --- bin/fail2ban-testcases | 3 ++- fail2ban/tests/misctestcase.py | 11 ++++++---- setup.py | 39 +++++++++++++++++++++++++++------- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/bin/fail2ban-testcases b/bin/fail2ban-testcases index 7e5f7aca..76a8e6ec 100755 --- a/bin/fail2ban-testcases +++ b/bin/fail2ban-testcases @@ -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', ''))) diff --git a/fail2ban/tests/misctestcase.py b/fail2ban/tests/misctestcase.py index 7028eeb1..7558851a 100644 --- a/fail2ban/tests/misctestcase.py +++ b/fail2ban/tests/misctestcase.py @@ -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): diff --git a/setup.py b/setup.py index f9f57976..fbffbaf8 100755 --- a/setup.py +++ b/setup.py @@ -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',