Show More
@@ -327,6 +327,8 b' else:' | |||||
327 | s = py3compat.cast_unicode(s, encoding=DEFAULT_ENCODING) |
|
327 | s = py3compat.cast_unicode(s, encoding=DEFAULT_ENCODING) | |
328 | super(MyStringIO, self).write(s) |
|
328 | super(MyStringIO, self).write(s) | |
329 |
|
329 | |||
|
330 | _re_type = type(re.compile(r'')) | |||
|
331 | ||||
330 | notprinted_msg = """Did not find {0!r} in printed output (on {1}): |
|
332 | notprinted_msg = """Did not find {0!r} in printed output (on {1}): | |
331 | ------- |
|
333 | ------- | |
332 | {2!s} |
|
334 | {2!s} | |
@@ -347,7 +349,7 b' class AssertPrints(object):' | |||||
347 | """ |
|
349 | """ | |
348 | def __init__(self, s, channel='stdout', suppress=True): |
|
350 | def __init__(self, s, channel='stdout', suppress=True): | |
349 | self.s = s |
|
351 | self.s = s | |
350 | if isinstance(self.s, py3compat.string_types): |
|
352 | if isinstance(self.s, (py3compat.string_types, _re_type)): | |
351 | self.s = [self.s] |
|
353 | self.s = [self.s] | |
352 | self.channel = channel |
|
354 | self.channel = channel | |
353 | self.suppress = suppress |
|
355 | self.suppress = suppress | |
@@ -366,7 +368,10 b' class AssertPrints(object):' | |||||
366 | setattr(sys, self.channel, self.orig_stream) |
|
368 | setattr(sys, self.channel, self.orig_stream) | |
367 | printed = self.buffer.getvalue() |
|
369 | printed = self.buffer.getvalue() | |
368 | for s in self.s: |
|
370 | for s in self.s: | |
369 | assert s in printed, notprinted_msg.format(s, self.channel, printed) |
|
371 | if isinstance(s, _re_type): | |
|
372 | assert s.search(printed), notprinted_msg.format(s.pattern, self.channel, printed) | |||
|
373 | else: | |||
|
374 | assert s in printed, notprinted_msg.format(s, self.channel, printed) | |||
370 | return False |
|
375 | return False | |
371 |
|
376 | |||
372 | printed_msg = """Found {0!r} in printed output (on {1}): |
|
377 | printed_msg = """Found {0!r} in printed output (on {1}): | |
@@ -387,7 +392,10 b' class AssertNotPrints(AssertPrints):' | |||||
387 | setattr(sys, self.channel, self.orig_stream) |
|
392 | setattr(sys, self.channel, self.orig_stream) | |
388 | printed = self.buffer.getvalue() |
|
393 | printed = self.buffer.getvalue() | |
389 | for s in self.s: |
|
394 | for s in self.s: | |
390 | assert s not in printed, printed_msg.format(s, self.channel, printed) |
|
395 | if isinstance(s, _re_type): | |
|
396 | assert not s.search(printed), printed_msg.format(s.pattern, self.channel, printed) | |||
|
397 | else: | |||
|
398 | assert s not in printed, printed_msg.format(s, self.channel, printed) | |||
391 | return False |
|
399 | return False | |
392 |
|
400 | |||
393 | @contextmanager |
|
401 | @contextmanager |
General Comments 0
You need to be logged in to leave comments.
Login now