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

Method test_newlines

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

Source from the content-addressed store, hash-verified

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" ]
3065
3066 tests = [
3067 [ None, [ 'unix\n', 'windows\n', 'os9\n', 'last\n', 'nonl' ] ],
3068 [ '', input_lines ],
3069 [ '\n', [ "unix\n", "windows\r\n", "os9\rlast\n", "nonl" ] ],
3070 [ '\r\n', [ "unix\nwindows\r\n", "os9\rlast\nnonl" ] ],
3071 [ '\r', [ "unix\nwindows\r", "\nos9\r", "last\nnonl" ] ],
3072 ]
3073 encodings = (
3074 'utf-8', 'latin-1',
3075 'utf-16', 'utf-16-le', 'utf-16-be',
3076 'utf-32', 'utf-32-le', 'utf-32-be',
3077 )
3078
3079 # Try a range of buffer sizes to test the case where \r is the last
3080 # character in TextIOWrapper._pending_line.
3081 for encoding in encodings:
3082 # XXX: str.encode() should return bytes
3083 data = bytes(''.join(input_lines).encode(encoding))
3084 for do_reads in (False, True):
3085 for bufsize in range(1, 10):
3086 for newline, exp_lines in tests:
3087 bufio = self.BufferedReader(self.BytesIO(data), bufsize)
3088 textio = self.TextIOWrapper(bufio, newline=newline,
3089 encoding=encoding)
3090 if do_reads:
3091 got_lines = []
3092 while True:
3093 c2 = textio.read(2)
3094 if c2 == '':
3095 break
3096 self.assertEqual(len(c2), 2)
3097 got_lines.append(c2 + textio.readline())
3098 else:
3099 got_lines = list(textio)
3100
3101 for got_line, exp_line in zip(got_lines, exp_lines):
3102 self.assertEqual(got_line, exp_line)
3103 self.assertEqual(len(got_lines), len(exp_lines))
3104
3105 def test_newlines_input(self):
3106 testdata = b"AAA\nBB\x00B\nCCC\rDDD\rEEE\r\nFFF\r\nGGG"

Callers

nothing calls this directly

Calls 8

readMethod · 0.95
readlineMethod · 0.95
lenFunction · 0.85
listClass · 0.85
encodeMethod · 0.45
joinMethod · 0.45
assertEqualMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected