Skip to content

Commit

Permalink
implemented assertNotLogged in LoggingMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilioPeJu committed Jun 23, 2017
1 parent cce5f7e commit b248cb2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions master/buildbot/test/util/logging.py
Expand Up @@ -28,16 +28,24 @@ def setUpLogging(self):
log.addObserver(self._logEvents.append)
self.addCleanup(log.removeObserver, self._logEvents.append)

def assertLogged(self, regexp):
def logContainsMessage(self, regexp):
r = re.compile(regexp)
for event in self._logEvents:
msg = log.textFromEventDict(event)
if msg is not None:
assert not msg.startswith("Unable to format event"), msg
if msg is not None and r.search(msg):
return
self.fail(
"%r not matched in log output.\n%s " % (
return True
return False

def assertLogged(self, regexp):
if not self.logContainsMessage(regexp):
self.fail("%r not matched in log output.\n%s " % (
regexp, [log.textFromEventDict(e) for e in self._logEvents]))

def assertNotLogged(self, regexp):
if self.logContainsMessage(regexp):
self.fail("%r matched in log output.\n%s " % (
regexp, [log.textFromEventDict(e) for e in self._logEvents]))

def assertWasQuiet(self):
Expand Down

0 comments on commit b248cb2

Please sign in to comment.