(self)
| 123 | return stack |
| 124 | |
| 125 | def test_str(self): |
| 126 | for stream_name, level, fileno in STREAM_INFO: |
| 127 | with self.stream_context(stream_name, level): |
| 128 | stream = getattr(sys, stream_name) |
| 129 | tag = f"python.{stream_name}" |
| 130 | self.assertEqual(f"<TextLogStream '{tag}'>", repr(stream)) |
| 131 | |
| 132 | self.assertIs(stream.writable(), True) |
| 133 | self.assertIs(stream.readable(), False) |
| 134 | self.assertEqual(stream.fileno(), fileno) |
| 135 | self.assertEqual("UTF-8", stream.encoding) |
| 136 | self.assertEqual("backslashreplace", stream.errors) |
| 137 | self.assertIs(stream.line_buffering, True) |
| 138 | self.assertIs(stream.write_through, False) |
| 139 | |
| 140 | def write(s, lines=None, *, write_len=None): |
| 141 | if write_len is None: |
| 142 | write_len = len(s) |
| 143 | self.assertEqual(write_len, stream.write(s)) |
| 144 | if lines is None: |
| 145 | lines = [s] |
| 146 | self.assert_logs(level, tag, lines) |
| 147 | |
| 148 | # Single-line messages, |
| 149 | with self.reconfigure(stream, write_through=True): |
| 150 | write("", []) |
| 151 | |
| 152 | write("a") |
| 153 | write("Hello") |
| 154 | write("Hello world") |
| 155 | write(" ") |
| 156 | write(" ") |
| 157 | |
| 158 | # Non-ASCII text |
| 159 | write("ol\u00e9") # Spanish |
| 160 | write("\u4e2d\u6587") # Chinese |
| 161 | |
| 162 | # Non-BMP emoji |
| 163 | write("\U0001f600") |
| 164 | |
| 165 | # Non-encodable surrogates |
| 166 | write("\ud800\udc00", [r"\ud800\udc00"]) |
| 167 | |
| 168 | # Code used by surrogateescape (which isn't enabled here) |
| 169 | write("\udc80", [r"\udc80"]) |
| 170 | |
| 171 | # Null characters are logged using "modified UTF-8". |
| 172 | write("\u0000", [r"\xc0\x80"]) |
| 173 | write("a\u0000", [r"a\xc0\x80"]) |
| 174 | write("\u0000b", [r"\xc0\x80b"]) |
| 175 | write("a\u0000b", [r"a\xc0\x80b"]) |
| 176 | |
| 177 | # Multi-line messages. Avoid identical consecutive lines, as |
| 178 | # they may activate "chatty" filtering and break the tests. |
| 179 | # |
| 180 | # Additional spaces will appear in the output where necessary to |
| 181 | # protect leading newlines. |
| 182 | write("\nx", [" "]) |
nothing calls this directly
no test coverage detected