|
1 | 1 | # Automated tests for the `coloredlogs' package.
|
2 | 2 | #
|
3 | 3 | # Author: Peter Odding <[email protected]>
|
4 |
| -# Last Change: December 10, 2020 |
| 4 | +# Last Change: June 11, 2021 |
5 | 5 | # URL: https://coloredlogs.readthedocs.io
|
6 | 6 |
|
7 | 7 | """Automated tests for the `coloredlogs` package."""
|
@@ -396,6 +396,22 @@ def test_plain_text_output_format(self):
|
396 | 396 | assert severity in last_line
|
397 | 397 | assert PLAIN_TEXT_PATTERN.match(last_line)
|
398 | 398 |
|
| 399 | + def test_dynamic_stderr_lookup(self): |
| 400 | + """Make sure coloredlogs.install() uses StandardErrorHandler when possible.""" |
| 401 | + coloredlogs.install() |
| 402 | + # Redirect sys.stderr to a temporary buffer. |
| 403 | + initial_stream = StringIO() |
| 404 | + initial_text = "Which stream will receive this text?" |
| 405 | + with PatchedAttribute(sys, 'stderr', initial_stream): |
| 406 | + logging.info(initial_text) |
| 407 | + assert initial_text in initial_stream.getvalue() |
| 408 | + # Redirect sys.stderr again, to a different destination. |
| 409 | + subsequent_stream = StringIO() |
| 410 | + subsequent_text = "And which stream will receive this other text?" |
| 411 | + with PatchedAttribute(sys, 'stderr', subsequent_stream): |
| 412 | + logging.info(subsequent_text) |
| 413 | + assert subsequent_text in subsequent_stream.getvalue() |
| 414 | + |
399 | 415 | def test_force_enable(self):
|
400 | 416 | """Make sure ANSI escape sequences can be forced (bypassing auto-detection)."""
|
401 | 417 | interpreter = subprocess.Popen([
|
|
0 commit comments