RF/BF: py26 has no {} sets, so just pass multiple entries as *args

pull/1188/head^2
Yaroslav Halchenko 2015-09-12 21:37:40 -04:00
parent 5ed731d3b3
commit 8a4dcafc8f
2 changed files with 12 additions and 15 deletions

View File

@ -200,10 +200,10 @@ class CommandActionTest(LogCaptureTestCase):
RuntimeError, CommandAction.executeCmd, 'sleep 60', timeout=2) RuntimeError, CommandAction.executeCmd, 'sleep 60', timeout=2)
# give a test still 1 second, because system could be too busy # give a test still 1 second, because system could be too busy
self.assertTrue(time.time() >= stime + 2 and time.time() <= stime + 3) 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 2 seconds',
'sleep 60 -- timed out after 3 seconds' 'sleep 60 -- timed out after 3 seconds'
}) )
self.assertLogged('sleep 60 -- killed with SIGTERM') self.assertLogged('sleep 60 -- killed with SIGTERM')
def testExecuteTimeoutWithNastyChildren(self): def testExecuteTimeoutWithNastyChildren(self):

View File

@ -232,8 +232,8 @@ class LogCaptureTestCase(unittest.TestCase):
def _is_logged(self, s): def _is_logged(self, s):
return s in self._log.getvalue() return s in self._log.getvalue()
def assertLogged(self, s): def assertLogged(self, *s):
"""Assert that a string was logged """Assert that one of the strings was logged
Preferable to assertTrue(self._is_logged(..))) Preferable to assertTrue(self._is_logged(..)))
since provides message with the actual log. 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 Test should succeed if string (or any of the listed) is present in the log
""" """
logged = self._log.getvalue() logged = self._log.getvalue()
for s_ in s:
s_iter = s if isinstance(s, (tuple, list, set)) else [s]
for s_ in s_iter:
if s_ in logged: if s_ in logged:
return 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): def assertNotLogged(self, *s):
"""Assert that a string was not logged """Assert that strings were not logged
Parameters Parameters
---------- ----------
s : string or list/set/tuple of strings 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() logged = self._log.getvalue()
for s_ in s:
s_iter = s if isinstance(s, (tuple, list, set)) else [s]
for s_ in s_iter:
if s_ not in logged: if s_ not in logged:
return 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): def getLog(self):