mirror of https://github.com/fail2ban/fail2ban
RF/BF: py26 has no {} sets, so just pass multiple entries as *args
parent
5ed731d3b3
commit
8a4dcafc8f
|
@ -200,10 +200,10 @@ class CommandActionTest(LogCaptureTestCase):
|
|||
RuntimeError, CommandAction.executeCmd, 'sleep 60', timeout=2)
|
||||
# give a test still 1 second, because system could be too busy
|
||||
self.assertTrue(time.time() >= stime + 2 and time.time() <= stime + 3)
|
||||
self.assertLogged({
|
||||
self.assertLogged(
|
||||
'sleep 60 -- timed out after 2 seconds',
|
||||
'sleep 60 -- timed out after 3 seconds'
|
||||
})
|
||||
)
|
||||
self.assertLogged('sleep 60 -- killed with SIGTERM')
|
||||
|
||||
def testExecuteTimeoutWithNastyChildren(self):
|
||||
|
|
|
@ -232,8 +232,8 @@ class LogCaptureTestCase(unittest.TestCase):
|
|||
def _is_logged(self, s):
|
||||
return s in self._log.getvalue()
|
||||
|
||||
def assertLogged(self, s):
|
||||
"""Assert that a string was logged
|
||||
def assertLogged(self, *s):
|
||||
"""Assert that one of the strings was logged
|
||||
|
||||
Preferable to assertTrue(self._is_logged(..)))
|
||||
since provides message with the actual log.
|
||||
|
@ -244,28 +244,25 @@ class LogCaptureTestCase(unittest.TestCase):
|
|||
Test should succeed if string (or any of the listed) is present in the log
|
||||
"""
|
||||
logged = self._log.getvalue()
|
||||
|
||||
s_iter = s if isinstance(s, (tuple, list, set)) else [s]
|
||||
for s_ in s_iter:
|
||||
for s_ in s:
|
||||
if s_ in logged:
|
||||
return
|
||||
raise AssertionError("%r was not found in the log: %r" % (s, logged))
|
||||
raise AssertionError("None among %r was found in the log: %r" % (s, logged))
|
||||
|
||||
def assertNotLogged(self, s):
|
||||
"""Assert that a string was not logged
|
||||
def assertNotLogged(self, *s):
|
||||
"""Assert that strings were not logged
|
||||
|
||||
Parameters
|
||||
----------
|
||||
s : string or list/set/tuple of strings
|
||||
Test should succeed if the string (or at least one of the listed) is not present in the log
|
||||
Test should succeed if the string (or at least one of the listed) is not
|
||||
present in the log
|
||||
"""
|
||||
logged = self._log.getvalue()
|
||||
|
||||
s_iter = s if isinstance(s, (tuple, list, set)) else [s]
|
||||
for s_ in s_iter:
|
||||
for s_ in s:
|
||||
if s_ not in logged:
|
||||
return
|
||||
raise AssertionError("%r was found present in the log: %r" % (s, logged))
|
||||
raise AssertionError("All of the %r were found present in the log: %r" % (s, logged))
|
||||
|
||||
|
||||
def getLog(self):
|
||||
|
|
Loading…
Reference in New Issue