(self, stream_name, level)
| 97 | stream.reconfigure(**original_settings) |
| 98 | |
| 99 | def stream_context(self, stream_name, level): |
| 100 | stack = ExitStack() |
| 101 | stack.enter_context(self.subTest(stream_name)) |
| 102 | |
| 103 | # In --verbose3 mode, sys.stdout and sys.stderr are captured, so we can't |
| 104 | # test them directly. Detect this mode and use some temporary streams with |
| 105 | # the same properties. |
| 106 | stream = getattr(sys, stream_name) |
| 107 | native_stream = getattr(sys, f"__{stream_name}__") |
| 108 | if isinstance(stream, io.StringIO): |
| 109 | # https://developer.android.com/ndk/reference/group/logging |
| 110 | prio = {"I": 4, "W": 5}[level] |
| 111 | stack.enter_context( |
| 112 | patch( |
| 113 | f"sys.{stream_name}", |
| 114 | stream := TextLogStream( |
| 115 | prio, f"python.{stream_name}", native_stream, |
| 116 | ), |
| 117 | ) |
| 118 | ) |
| 119 | |
| 120 | # The tests assume the stream is initially buffered. |
| 121 | stack.enter_context(self.reconfigure(stream, write_through=False)) |
| 122 | |
| 123 | return stack |
| 124 | |
| 125 | def test_str(self): |
| 126 | for stream_name, level, fileno in STREAM_INFO: |
no test coverage detected