MCPcopy Index your code
hub / github.com/python/cpython / test_detach

Method test_detach

Lib/test/test_io/test_textio.py:242–260  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

240 self.TextIOWrapper(b, encoding="hex")
241
242 def test_detach(self):
243 r = self.BytesIO()
244 b = self.BufferedWriter(r)
245 t = self.TextIOWrapper(b, encoding="ascii")
246 self.assertIs(t.detach(), b)
247
248 t = self.TextIOWrapper(b, encoding="ascii")
249 t.write("howdy")
250 self.assertFalse(r.getvalue())
251 t.detach()
252 self.assertEqual(r.getvalue(), b"howdy")
253 self.assertRaises(ValueError, t.detach)
254
255 # Operations independent of the detached stream should still work
256 repr(t)
257 self.assertEqual(t.encoding, "ascii")
258 self.assertEqual(t.errors, "strict")
259 self.assertFalse(t.line_buffering)
260 self.assertFalse(t.write_through)
261
262 def test_repr(self):
263 raw = self.BytesIO("hello".encode("utf-8"))

Callers

nothing calls this directly

Calls 7

detachMethod · 0.95
writeMethod · 0.95
getvalueMethod · 0.95
assertFalseMethod · 0.80
assertIsMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected