##// END OF EJS Templates
BUG: Explicitly close Tee in AssertPrints and AssertNotPrints...
Scott Sanderson -
Show More
@@ -365,6 +365,7 b' 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 try:
368 if value is not None:
369 if value is not None:
369 # If an error was raised, don't check anything else
370 # If an error was raised, don't check anything else
370 return False
371 return False
@@ -377,6 +378,8 b' class AssertPrints(object):'
377 else:
378 else:
378 assert s in printed, notprinted_msg.format(s, self.channel, printed)
379 assert s in printed, notprinted_msg.format(s, self.channel, printed)
379 return False
380 return False
381 finally:
382 self.tee.close()
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 b' 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):
395 try:
392 if value is not None:
396 if value is not None:
393 # If an error was raised, don't check anything else
397 # If an error was raised, don't check anything else
398 self.tee.close()
394 return False
399 return False
395 self.tee.flush()
400 self.tee.flush()
396 setattr(sys, self.channel, self.orig_stream)
401 setattr(sys, self.channel, self.orig_stream)
397 printed = self.buffer.getvalue()
402 printed = self.buffer.getvalue()
398 for s in self.s:
403 for s in self.s:
399 if isinstance(s, _re_type):
404 if isinstance(s, _re_type):
400 assert not s.search(printed), printed_msg.format(s.pattern, self.channel, printed)
405 assert not s.search(printed),printed_msg.format(
406 s.pattern, self.channel, printed)
401 else:
407 else:
402 assert s not in printed, printed_msg.format(s, self.channel, printed)
408 assert s not in printed, printed_msg.format(
409 s, self.channel, printed)
403 return False
410 return False
411 finally:
412 self.tee.close()
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