diff --git a/fail2ban/tests/actiontestcase.py b/fail2ban/tests/actiontestcase.py index a4b453a3..1cba0bcc 100644 --- a/fail2ban/tests/actiontestcase.py +++ b/fail2ban/tests/actiontestcase.py @@ -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): diff --git a/fail2ban/tests/utils.py b/fail2ban/tests/utils.py index 9d50646a..35fa59fd 100644 --- a/fail2ban/tests/utils.py +++ b/fail2ban/tests/utils.py @@ -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):