##// END OF EJS Templates
BUG: Explicitly close Tee in AssertPrints and AssertNotPrints...
Scott Sanderson -
r17801:8a65f6a7
parent child
Show More
@@ -365,18 +365,21 class AssertPrints(object):
365 setattr(sys, self.channel, self.buffer if self.suppress else self.tee)
365 setattr(sys, self.channel, self.buffer if self.suppress else self.tee)
366
366
367 def __exit__(self, etype, value, traceback):
367 def __exit__(self, etype, value, traceback):
368 if value is not None:
368 try:
369 # If an error was raised, don't check anything else
369 if value is not None:
370 # If an error was raised, don't check anything else
371 return False
372 self.tee.flush()
373 setattr(sys, self.channel, self.orig_stream)
374 printed = self.buffer.getvalue()
375 for s in self.s:
376 if isinstance(s, _re_type):
377 assert s.search(printed), notprinted_msg.format(s.pattern, self.channel, printed)
378 else:
379 assert s in printed, notprinted_msg.format(s, self.channel, printed)
370 return False
380 return False
371 self.tee.flush()
381 finally:
372 setattr(sys, self.channel, self.orig_stream)
382 self.tee.close()
373 printed = self.buffer.getvalue()
374 for s in self.s:
375 if isinstance(s, _re_type):
376 assert s.search(printed), notprinted_msg.format(s.pattern, self.channel, printed)
377 else:
378 assert s in printed, notprinted_msg.format(s, self.channel, printed)
379 return False
380
383
381 printed_msg = """Found {0!r} in printed output (on {1}):
384 printed_msg = """Found {0!r} in printed output (on {1}):
382 -------
385 -------
@@ -389,18 +392,24 class AssertNotPrints(AssertPrints):
389
392
390 Counterpart of AssertPrints"""
393 Counterpart of AssertPrints"""
391 def __exit__(self, etype, value, traceback):
394 def __exit__(self, etype, value, traceback):
392 if value is not None:
395 try:
393 # If an error was raised, don't check anything else
396 if value is not None:
397 # If an error was raised, don't check anything else
398 self.tee.close()
399 return False
400 self.tee.flush()
401 setattr(sys, self.channel, self.orig_stream)
402 printed = self.buffer.getvalue()
403 for s in self.s:
404 if isinstance(s, _re_type):
405 assert not s.search(printed),printed_msg.format(
406 s.pattern, self.channel, printed)
407 else:
408 assert s not in printed, printed_msg.format(
409 s, self.channel, printed)
394 return False
410 return False
395 self.tee.flush()
411 finally:
396 setattr(sys, self.channel, self.orig_stream)
412 self.tee.close()
397 printed = self.buffer.getvalue()
398 for s in self.s:
399 if isinstance(s, _re_type):
400 assert not s.search(printed), printed_msg.format(s.pattern, self.channel, printed)
401 else:
402 assert s not in printed, printed_msg.format(s, self.channel, printed)
403 return False
404
413
405 @contextmanager
414 @contextmanager
406 def mute_warn():
415 def mute_warn():
General Comments 0
You need to be logged in to leave comments. Login now