mirror of https://github.com/fail2ban/fail2ban
BF+ENH: import signal used in the code, withtmpdir -> with_tmpdir (more readable)
case shows how evil except Exception can be ;)pull/1483/head
parent
6353de8b0f
commit
e57321ab1e
|
@ -28,6 +28,7 @@ import os
|
|||
import re
|
||||
import sys
|
||||
import time
|
||||
import signal
|
||||
import unittest
|
||||
|
||||
from threading import Thread
|
||||
|
@ -38,7 +39,7 @@ from ..client.fail2banserver import Fail2banServer, exec_command_line as _exec_s
|
|||
from .. import protocol
|
||||
from ..server import server
|
||||
from ..server.utils import Utils
|
||||
from .utils import LogCaptureTestCase, logSys, withtmpdir, shutil, logging
|
||||
from .utils import LogCaptureTestCase, logSys, with_tmpdir, shutil, logging
|
||||
|
||||
|
||||
STOCK_CONF_DIR = "config"
|
||||
|
@ -252,7 +253,7 @@ class Fail2banClientTest(Fail2banClientServerBase):
|
|||
(CLIENT, "-vq", "-V",))
|
||||
self.assertLogged("Fail2Ban v" + fail2bancmdline.version)
|
||||
|
||||
@withtmpdir
|
||||
@with_tmpdir
|
||||
def testClientDump(self, tmp):
|
||||
# use here the stock configuration (if possible)
|
||||
startparams = _start_params(tmp, True)
|
||||
|
@ -261,7 +262,7 @@ class Fail2banClientTest(Fail2banClientServerBase):
|
|||
self.assertLogged("Loading files")
|
||||
self.assertLogged("logtarget")
|
||||
|
||||
@withtmpdir
|
||||
@with_tmpdir
|
||||
def testClientStartBackgroundInside(self, tmp):
|
||||
try:
|
||||
# use once the stock configuration (to test starting also)
|
||||
|
@ -300,7 +301,7 @@ class Fail2banClientTest(Fail2banClientServerBase):
|
|||
finally:
|
||||
_kill_srv(tmp)
|
||||
|
||||
@withtmpdir
|
||||
@with_tmpdir
|
||||
def testClientStartBackgroundCall(self, tmp):
|
||||
try:
|
||||
global INTERACT
|
||||
|
@ -382,7 +383,7 @@ class Fail2banClientTest(Fail2banClientServerBase):
|
|||
phase['end'] = True
|
||||
logSys.debug("-- end of test worker")
|
||||
|
||||
@withtmpdir
|
||||
@with_tmpdir
|
||||
def testClientStartForeground(self, tmp):
|
||||
th = None
|
||||
try:
|
||||
|
@ -422,7 +423,7 @@ class Fail2banClientTest(Fail2banClientServerBase):
|
|||
if th:
|
||||
th.join()
|
||||
|
||||
@withtmpdir
|
||||
@with_tmpdir
|
||||
def testClientFailStart(self, tmp):
|
||||
try:
|
||||
# started directly here, so prevent overwrite test cases logger with "INHERITED"
|
||||
|
@ -483,7 +484,7 @@ class Fail2banServerTest(Fail2banClientServerBase):
|
|||
self.assertLogged("Usage: " + SERVER)
|
||||
self.assertLogged("Report bugs to ")
|
||||
|
||||
@withtmpdir
|
||||
@with_tmpdir
|
||||
def testServerStartBackground(self, tmp):
|
||||
try:
|
||||
# to prevent fork of test-cases process, start server in background via command:
|
||||
|
@ -523,7 +524,7 @@ class Fail2banServerTest(Fail2banClientServerBase):
|
|||
phase['end'] = True
|
||||
logSys.debug("-- end of test worker")
|
||||
|
||||
@withtmpdir
|
||||
@with_tmpdir
|
||||
def testServerStartForeground(self, tmp):
|
||||
th = None
|
||||
try:
|
||||
|
@ -563,7 +564,7 @@ class Fail2banServerTest(Fail2banClientServerBase):
|
|||
if th:
|
||||
th.join()
|
||||
|
||||
@withtmpdir
|
||||
@with_tmpdir
|
||||
def testServerFailStart(self, tmp):
|
||||
try:
|
||||
# started directly here, so prevent overwrite test cases logger with "INHERITED"
|
||||
|
|
|
@ -79,7 +79,12 @@ class F2B(optparse.Values):
|
|||
return wtime
|
||||
|
||||
|
||||
def withtmpdir(f):
|
||||
def with_tmpdir(f):
|
||||
"""Helper decorator to create a temporary directory
|
||||
|
||||
Directory gets removed after function returns, regardless
|
||||
if exception was thrown of not
|
||||
"""
|
||||
@wraps(f)
|
||||
def wrapper(self, *args, **kwargs):
|
||||
tmp = tempfile.mkdtemp(prefix="f2b-temp")
|
||||
|
@ -90,6 +95,7 @@ def withtmpdir(f):
|
|||
shutil.rmtree(tmp)
|
||||
return wrapper
|
||||
|
||||
|
||||
def initTests(opts):
|
||||
unittest.F2B = F2B(opts)
|
||||
# --fast :
|
||||
|
|
Loading…
Reference in New Issue