Пример #1
0
 def test_iterlines_limit(self):
     data, limit = 'abc\ndef\r\nghi', 10
     result = [(tob('abc'), tob('\n')),
               (tob('def'), tob('\r\n')),
               (tob('g'), tob(''))]
     i = mp.lineiter(BytesIO(tob(data)), readlimit=limit)
     self.assertEqual(list(i), result)
     data, limit = 'abc\ndef\r\nghi', 8
     result = [(tob('abc'), tob('\n')),
               (tob('def'), tob('\r'))]
     i = mp.lineiter(BytesIO(tob(data)), readlimit=limit)
     self.assertEqual(list(i), result)
Пример #2
0
 def test_iterlines_maxbuf(self):
     data, limit = 'abcdefgh\nijklmnop\r\nq', 9
     result = [(tob('abcdefgh'), tob('\n')),
               (tob('ijklmnop'), tob('\r\n')),
               (tob('q'), tob(''))]
     i = mp.lineiter(BytesIO(tob(data)), limit)
     self.assertEqual(list(i), result)
     data, limit = ('X' * 3 * 1024) + 'x\n', 1024
     result = [(tob('X' * 1024), tob('')),
               (tob('X' * 1024), tob('')),
               (tob('X' * 1024), tob('')),
               (tob('x'), tob('\n'))]
     i = mp.lineiter(BytesIO(tob(data)), limit)
     self.assertEqual(list(i), result)
Пример #3
0
 def test_iterlines(self):
     data = 'abc\ndef\r\nghi'
     result = [(tob('abc'), tob('\n')),
               (tob('def'), tob('\r\n')),
               (tob('ghi'), tob(''))]
     i = mp.lineiter(BytesIO(tob(data)))
     self.assertEqual(list(i), result)
Пример #4
0
 def test_line_parser(self):
     for line in ('foo', ''):
         for ending in ('\n', '\r', '\r\n'):
             iterator = mp.lineiter(BytesIO(tob(line + ending)))
             for item in iterator:
                 self.assertEqual(item, (tob(line), tob(ending)))
                 break  # at first loop, as portable way of spelling .next()