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

Method test_reconfigure_errors

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

Source from the content-addressed store, hash-verified

3940 self.assertEqual(txt.detach().getvalue(), b'LF\nCRLF\r\n')
3941
3942 def test_reconfigure_errors(self):
3943 txt = self.TextIOWrapper(self.BytesIO(), 'ascii', 'replace', '\r')
3944 with self.assertRaises(TypeError): # there was a crash
3945 txt.reconfigure(encoding=42)
3946 if self.is_C:
3947 with self.assertRaises(UnicodeEncodeError):
3948 txt.reconfigure(encoding='\udcfe')
3949 with self.assertRaises(LookupError):
3950 txt.reconfigure(encoding='locale\0')
3951 # TODO: txt.reconfigure(encoding='utf-8\0')
3952 # TODO: txt.reconfigure(encoding='nonexisting')
3953 with self.assertRaises(TypeError):
3954 txt.reconfigure(errors=42)
3955 if self.is_C:
3956 with self.assertRaises(UnicodeEncodeError):
3957 txt.reconfigure(errors='\udcfe')
3958 # TODO: txt.reconfigure(errors='ignore\0')
3959 # TODO: txt.reconfigure(errors='nonexisting')
3960 with self.assertRaises(TypeError):
3961 txt.reconfigure(newline=42)
3962 with self.assertRaises(ValueError):
3963 txt.reconfigure(newline='\udcfe')
3964 with self.assertRaises(ValueError):
3965 txt.reconfigure(newline='xyz')
3966 if not self.is_C:
3967 # TODO: Should fail in C too.
3968 with self.assertRaises(ValueError):
3969 txt.reconfigure(newline='\n\0')
3970 if self.is_C:
3971 # TODO: Use __bool__(), not __index__().
3972 with self.assertRaises(ZeroDivisionError):
3973 txt.reconfigure(line_buffering=BadIndex())
3974 with self.assertRaises(OverflowError):
3975 txt.reconfigure(line_buffering=2**1000)
3976 with self.assertRaises(ZeroDivisionError):
3977 txt.reconfigure(write_through=BadIndex())
3978 with self.assertRaises(OverflowError):
3979 txt.reconfigure(write_through=2**1000)
3980 with self.assertRaises(ZeroDivisionError): # there was a crash
3981 txt.reconfigure(line_buffering=BadIndex(),
3982 write_through=BadIndex())
3983 self.assertEqual(txt.encoding, 'ascii')
3984 self.assertEqual(txt.errors, 'replace')
3985 self.assertIs(txt.line_buffering, False)
3986 self.assertIs(txt.write_through, False)
3987
3988 txt.reconfigure(encoding='latin1', errors='ignore', newline='\r\n',
3989 line_buffering=True, write_through=True)
3990 self.assertEqual(txt.encoding, 'latin1')
3991 self.assertEqual(txt.errors, 'ignore')
3992 self.assertIs(txt.line_buffering, True)
3993 self.assertIs(txt.write_through, True)
3994
3995 def test_reconfigure_newline(self):
3996 raw = self.BytesIO(b'CR\rEOF')

Callers

nothing calls this directly

Calls 5

reconfigureMethod · 0.95
BadIndexClass · 0.70
assertRaisesMethod · 0.45
assertEqualMethod · 0.45
assertIsMethod · 0.45

Tested by

no test coverage detected