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