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

Method test_encoding_errors_writing

Lib/test/test_io.py:3039–3061  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3037 self.assertEqual(t.read(), "abc\n\ufffd\n")
3038
3039 def test_encoding_errors_writing(self):
3040 # (1) default
3041 b = self.BytesIO()
3042 t = self.TextIOWrapper(b, encoding="ascii")
3043 self.assertRaises(UnicodeError, t.write, "\xff")
3044 # (2) explicit strict
3045 b = self.BytesIO()
3046 t = self.TextIOWrapper(b, encoding="ascii", errors="strict")
3047 self.assertRaises(UnicodeError, t.write, "\xff")
3048 # (3) ignore
3049 b = self.BytesIO()
3050 t = self.TextIOWrapper(b, encoding="ascii", errors="ignore",
3051 newline="\n")
3052 t.write("abc\xffdef\n")
3053 t.flush()
3054 self.assertEqual(b.getvalue(), b"abcdef\n")
3055 # (4) replace
3056 b = self.BytesIO()
3057 t = self.TextIOWrapper(b, encoding="ascii", errors="replace",
3058 newline="\n")
3059 t.write("abc\xffdef\n")
3060 t.flush()
3061 self.assertEqual(b.getvalue(), b"abc?def\n")
3062
3063 def test_newlines(self):
3064 input_lines = [ "unix\n", "windows\r\n", "os9\r", "last\n", "nonl" ]

Callers

nothing calls this directly

Calls 5

writeMethod · 0.95
flushMethod · 0.95
getvalueMethod · 0.95
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected