MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_str

Method test_str

Lib/test/test_android.py:115–262  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

113 return stack
114
115 def test_str(self):
116 for stream_name, level, fileno in STREAM_INFO:
117 with self.stream_context(stream_name, level):
118 stream = getattr(sys, stream_name)
119 tag = f"python.{stream_name}"
120 self.assertEqual(f"<TextLogStream '{tag}'>", repr(stream))
121
122 self.assertIs(stream.writable(), True)
123 self.assertIs(stream.readable(), False)
124 self.assertEqual(stream.fileno(), fileno)
125 self.assertEqual("UTF-8", stream.encoding)
126 self.assertEqual("backslashreplace", stream.errors)
127 self.assertIs(stream.line_buffering, True)
128 self.assertIs(stream.write_through, False)
129
130 def write(s, lines=None, *, write_len=None):
131 if write_len is None:
132 write_len = len(s)
133 self.assertEqual(write_len, stream.write(s))
134 if lines is None:
135 lines = [s]
136 self.assert_logs(level, tag, lines)
137
138 # Single-line messages,
139 with self.unbuffered(stream):
140 write("", [])
141
142 write("a")
143 write("Hello")
144 write("Hello world")
145 write(" ")
146 write(" ")
147
148 # Non-ASCII text
149 write("ol\u00e9") # Spanish
150 write("\u4e2d\u6587") # Chinese
151
152 # Non-BMP emoji
153 write("\U0001f600")
154
155 # Non-encodable surrogates
156 write("\ud800\udc00", [r"\ud800\udc00"])
157
158 # Code used by surrogateescape (which isn't enabled here)
159 write("\udc80", [r"\udc80"])
160
161 # Null characters are logged using "modified UTF-8".
162 write("\u0000", [r"\xc0\x80"])
163 write("a\u0000", [r"a\xc0\x80"])
164 write("\u0000b", [r"\xc0\x80b"])
165 write("a\u0000b", [r"a\xc0\x80b"])
166
167 # Multi-line messages. Avoid identical consecutive lines, as
168 # they may activate "chatty" filtering and break the tests.
169 write("\nx", [""])
170 write("\na\n", ["x", "a"])
171 write("\n", [""])
172 write("b\n", ["b"])

Callers

nothing calls this directly

Calls 15

stream_contextMethod · 0.95
unbufferedMethod · 0.95
assert_logMethod · 0.95
getattrFunction · 0.85
reprFunction · 0.85
subTestMethod · 0.80
assertRaisesRegexMethod · 0.80
CustomStrClass · 0.70
writeFunction · 0.50
assertEqualMethod · 0.45
assertIsMethod · 0.45
writableMethod · 0.45

Tested by

no test coverage detected